@@ -563,6 +563,9 @@ bool MainWindow::fileOpen(const QString& fileName, bool openFromProject, bool re
563
563
// When a new DB file has been open while a project is open, set the project modified.
564
564
if (!currentProjectFilename.isEmpty ())
565
565
isProjectModified = true ;
566
+ } else {
567
+ // loadProject will init the rest
568
+ return true ;
566
569
}
567
570
if (ui->tabSqlAreas ->count () == 0 )
568
571
openSqlTab (true );
@@ -2723,6 +2726,8 @@ MainWindow::LoadAttempResult MainWindow::loadProject(QString filename, bool read
2723
2726
addToRecentFilesMenu (filename, readOnly);
2724
2727
currentProjectFilename = filename;
2725
2728
2729
+ int projectRestoreIdx = -1 ;
2730
+ QString projectRestoreTabs;
2726
2731
while (!xml.atEnd () && !xml.hasError ())
2727
2732
{
2728
2733
// Read next token
@@ -2775,15 +2780,13 @@ MainWindow::LoadAttempResult MainWindow::loadProject(QString filename, bool read
2775
2780
while (xml.readNext () != QXmlStreamReader::EndElement && xml.name () != QT_UNICODE_LITERAL (" window" ))
2776
2781
{
2777
2782
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 ();
2782
2785
xml.skipCurrentElement ();
2783
2786
} else if (xml.name () == QT_UNICODE_LITERAL (" current_tab" )) {
2784
2787
// 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 ();
2787
2790
xml.skipCurrentElement ();
2788
2791
}
2789
2792
}
@@ -2913,7 +2916,6 @@ MainWindow::LoadAttempResult MainWindow::loadProject(QString filename, bool read
2913
2916
} else {
2914
2917
xml.skipCurrentElement ();
2915
2918
}
2916
-
2917
2919
}
2918
2920
} else if (xml.name () == QT_UNICODE_LITERAL (" tab_sql" )) {
2919
2921
// Close all open tabs first
@@ -2951,12 +2953,20 @@ MainWindow::LoadAttempResult MainWindow::loadProject(QString filename, bool read
2951
2953
2952
2954
file.close ();
2953
2955
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);
2956
2961
}
2957
2962
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);
2960
2970
return !xml.hasError ()? Success : Aborted;
2961
2971
} else {
2962
2972
// No project was opened
0 commit comments