@@ -53,6 +53,8 @@ MainWindow::MainWindow(QWidget* parent)
5353 this , &MainWindow::onStreamedElementsReady);
5454 connect (loader_, &SceneLoader::loadedFromStream,
5555 this , &MainWindow::onLoadedFromStream);
56+ connect (loader_, &SceneLoader::loadCancelled,
57+ this , &MainWindow::onLoadCancelled);
5658 connect (loader_, &SceneLoader::loadError,
5759 this , &MainWindow::onLoadError);
5860 connect (loader_, &SceneLoader::allLoadsFinished,
@@ -297,6 +299,42 @@ void MainWindow::writeSidecarForModel(uint32_t mid) {
297299 qDebug (" Sidecar write: %lld ms (%s)" , t.elapsed (), ok ? " ok" : " FAILED" );
298300}
299301
302+ void MainWindow::removeModelUi (uint32_t mid) {
303+ auto root_it = tree_roots_.find (mid);
304+ if (root_it != tree_roots_.end ()) {
305+ delete root_it->second ;
306+ tree_roots_.erase (root_it);
307+ }
308+
309+ for (auto it = tree_items_.begin (); it != tree_items_.end ();) {
310+ auto info_it = element_map_.find (it->first );
311+ if (info_it != element_map_.end () && info_it->second .model_id == mid) {
312+ it = tree_items_.erase (it);
313+ } else {
314+ ++it;
315+ }
316+ }
317+
318+ for (auto it = element_map_.begin (); it != element_map_.end ();) {
319+ if (it->second .model_id == mid) {
320+ it = element_map_.erase (it);
321+ } else {
322+ ++it;
323+ }
324+ }
325+
326+ for (auto it = scoped_ifc_id_to_object_id_.begin (); it != scoped_ifc_id_to_object_id_.end ();) {
327+ if (static_cast <uint32_t >(it->first >> 32 ) == mid) {
328+ it = scoped_ifc_id_to_object_id_.erase (it);
329+ } else {
330+ ++it;
331+ }
332+ }
333+
334+ viewport_->setSelectedObjectId (0 );
335+ property_table_->setRowCount (0 );
336+ }
337+
300338void MainWindow::onLoadedFromStream (uint32_t mid, qint64 elapsed_ms) {
301339 progress_bar_->setVisible (false );
302340 status_label_->setText (QString (" %1 elements across %2 model(s) — last loaded in %3" )
@@ -307,7 +345,16 @@ void MainWindow::onLoadedFromStream(uint32_t mid, qint64 elapsed_ms) {
307345 writeSidecarForModel (mid);
308346}
309347
310- void MainWindow::onLoadError (uint32_t /* mid*/ , QString message) {
348+ void MainWindow::onLoadCancelled (uint32_t mid) {
349+ progress_bar_->setVisible (false );
350+ removeModelUi (mid);
351+ status_label_->setText (QString (" %1 load cancelled" ).arg (loader_->displayName (mid)));
352+ }
353+
354+ void MainWindow::onLoadError (uint32_t mid, QString message) {
355+ progress_bar_->setVisible (false );
356+ removeModelUi (mid);
357+ status_label_->setText (" Error: " + message);
311358 QMessageBox::warning (this , " Error" , message);
312359}
313360
0 commit comments