@@ -563,6 +563,9 @@ bool MainWindow::fileOpen(const QString& fileName, bool openFromProject, bool re
563563 // When a new DB file has been open while a project is open, set the project modified.
564564 if (!currentProjectFilename.isEmpty ())
565565 isProjectModified = true ;
566+ } else {
567+ // loadProject will init the rest
568+ return true ;
566569 }
567570 if (ui->tabSqlAreas ->count () == 0 )
568571 openSqlTab (true );
@@ -2723,6 +2726,8 @@ MainWindow::LoadAttempResult MainWindow::loadProject(QString filename, bool read
27232726 addToRecentFilesMenu (filename, readOnly);
27242727 currentProjectFilename = filename;
27252728
2729+ int projectRestoreIdx = -1 ;
2730+ QString projectRestoreTabs;
27262731 while (!xml.atEnd () && !xml.hasError ())
27272732 {
27282733 // Read next token
@@ -2775,15 +2780,13 @@ MainWindow::LoadAttempResult MainWindow::loadProject(QString filename, bool read
27752780 while (xml.readNext () != QXmlStreamReader::EndElement && xml.name () != QT_UNICODE_LITERAL (" window" ))
27762781 {
27772782 if (xml.name () == QT_UNICODE_LITERAL (" main_tabs" )) {
2778- // Currently open tabs
2779- restoreOpenTabs (xml.attributes ().value (" open" ).toString ());
2780- // Currently selected open tab
2781- ui->mainTab ->setCurrentIndex (xml.attributes ().value (" current" ).toString ().toInt ());
2783+ projectRestoreTabs = xml.attributes ().value (" open" ).toString ();
2784+ projectRestoreIdx = xml.attributes ().value (" current" ).toString ().toInt ();
27822785 xml.skipCurrentElement ();
27832786 } else if (xml.name () == QT_UNICODE_LITERAL (" current_tab" )) {
27842787 // Currently selected tab (3.11 or older format, first restore default open tabs)
2785- restoreOpenTabs ( defaultOpenTabs) ;
2786- ui-> mainTab -> setCurrentIndex ( xml.attributes ().value (" id" ).toString ().toInt () );
2788+ projectRestoreTabs = defaultOpenTabs;
2789+ projectRestoreIdx = xml.attributes ().value (" id" ).toString ().toInt ();
27872790 xml.skipCurrentElement ();
27882791 }
27892792 }
@@ -2913,7 +2916,6 @@ MainWindow::LoadAttempResult MainWindow::loadProject(QString filename, bool read
29132916 } else {
29142917 xml.skipCurrentElement ();
29152918 }
2916-
29172919 }
29182920 } else if (xml.name () == QT_UNICODE_LITERAL (" tab_sql" )) {
29192921 // Close all open tabs first
@@ -2951,12 +2953,20 @@ MainWindow::LoadAttempResult MainWindow::loadProject(QString filename, bool read
29512953
29522954 file.close ();
29532955
2954- if (ui->mainTab ->currentWidget () == ui->browser ) {
2955- refreshTableBrowsers (); // Refresh view
2956+ if (projectRestoreIdx != -1 && !projectRestoreTabs.isEmpty ()) {
2957+ ui->mainTab ->blockSignals (true );
2958+ restoreOpenTabs (projectRestoreTabs);
2959+ ui->mainTab ->blockSignals (false );
2960+ ui->mainTab ->setCurrentIndex (projectRestoreIdx);
29562961 }
29572962
2958- isProjectModified = false ;
2959-
2963+ // This is done because on consecutive reloads,
2964+ // we have events in queue which will activate
2965+ // &TableBrowser::projectModified,
2966+ // append ourselves after those events
2967+ QMetaObject::invokeMethod (this , [this ] {
2968+ isProjectModified = false ;
2969+ }, Qt::QueuedConnection);
29602970 return !xml.hasError ()? Success : Aborted;
29612971 } else {
29622972 // No project was opened
0 commit comments