Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions src/appproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,12 @@ void AppProject::closeProject()
// Close any remaining windows (for example split auto-clones).
_mdiArea->closeAllSubWindows();

// Force immediate destruction of MDI subwindows (WA_DeleteOnClose uses
// deleteLater, so without this their destructors run after new forms are
// already created, causing deviceIdAdded/unitMapAdded signals to be
// suppressed for the newly opened project).
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);

const auto deleteClosedForms = [this](auto&& shouldDelete) {
const auto snapshot = _closedForms;
for (auto* frm : snapshot) {
Expand All @@ -662,6 +668,8 @@ void AppProject::closeProject()

_closedForms.clear();
_mbServer.clearAddressSpace();
_mbServer.clearDescriptions();
_mbServer.clearTimestamps();
_dataCounter = 0;
_trafficCounter = 0;
_scriptCounter = 0;
Expand Down Expand Up @@ -1721,11 +1729,12 @@ void AppProject::loadProject(const QString& filename)
if(!file.open(QFile::ReadOnly))
return;

_projectFilename = QFileInfo(filename).absoluteFilePath();
emit projectOpened(_projectFilename);

_mbServer.clearDescriptions();
_mbServer.clearTimestamps();
const auto replace = _projectFilename.isEmpty();
if (replace) {
setSavePath(QFileInfo(filename).absoluteDir().absolutePath());
_projectFilename = QFileInfo(filename).absoluteFilePath();
emit projectOpened(_projectFilename);
}

ModbusDefinitions defs;
QList<ConnectionDetails> conns;
Expand All @@ -1738,7 +1747,7 @@ void AppProject::loadProject(const QString& filename)
bool projectGlobalZeroBasedAddress = false;
bool hasProjectGlobalHexView = false;
bool projectGlobalHexView = false;
bool viewPreparedForForms = false;
bool viewPreparedForForms = !replace;
QStringList primaryTabOrder;
QStringList secondaryTabOrder;

Expand Down Expand Up @@ -1807,20 +1816,6 @@ void AppProject::loadProject(const QString& filename)
_mdiArea->setSplitViewEnabled(splitView);
viewPreparedForForms = true;
}

_mdiArea->closeAllSubWindows();
// Force immediate destruction of MDI subwindows (WA_DeleteOnClose uses
// deleteLater, so without this their destructors run after new forms are
// already created, causing deviceIdAdded/unitMapAdded signals to be
// suppressed for the newly opened project).
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
// Clean up forms that were already closed (hidden)
const auto closed = _closedForms;
for (auto&& frm : closed) {
_projectTree->removeForm(frm);
delete frm;
}
_closedForms.clear();
while (xml.readNextStartElement()) {
ProjectFormKind kind;
bool isForm = true;
Expand Down Expand Up @@ -2011,9 +2006,14 @@ void AppProject::loadProject(const QString& filename)

// Prefer global AddressSpace metadata when present; otherwise keep legacy per-form values.
if (hasGlobalDescriptionMap)
_mbServer.setDescriptionMap(globalDescriptionMap, WriteSource::ProjectLoad);
_mbServer.setDescriptionMap(globalDescriptionMap, WriteSource::ProjectLoad, replace);
if (hasGlobalTimestampMap)
_mbServer.setTimestampMap(globalTimestampMap);
_mbServer.setTimestampMap(globalTimestampMap, replace);

if (!replace) {
// Ignore global settings part of merging project
return;
}

_mainWindow->applyConnections(defs, conns);
syncAutoRequestMap(_mbServer.getModbusDefinitions());
Expand Down Expand Up @@ -2136,6 +2136,7 @@ void AppProject::restoreActiveWindows()
///
/// \brief AppProject::saveProject
/// \param filename
/// \return
///
bool AppProject::saveProject(const QString& filename)
{
Expand All @@ -2147,6 +2148,7 @@ bool AppProject::saveProject(const QString& filename)
return false;
}

setSavePath(QFileInfo(filename).absoluteDir().absolutePath());
_projectFilename = absoluteFilename;

QXmlStreamWriter w(&file);
Expand Down
1 change: 1 addition & 0 deletions src/appproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class AppProject : public QObject
void loadProject(const QString& filename);
bool saveProject(const QString& filename);
void restoreActiveWindows();
const QString & filePath() const noexcept { return _projectFilename; }

// Called from MainWindow::~MainWindow() before delete ui.
// Closes MDI windows and deletes forms/scripts without touching the project tree UI
Expand Down
Loading
Loading