Skip to content

Commit

Permalink
enh(cpn): identify drag n drop and new from template as changed
Browse files Browse the repository at this point in the history
  • Loading branch information
elecpower committed Jul 22, 2023
1 parent 3338fce commit 9398ca4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
26 changes: 20 additions & 6 deletions companion/src/mdichild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,6 @@ void MdiChild::updateTitle()

void MdiChild::setModified()
{
radioData.models[getCurrentModel()].modelUpdated = true;
refresh();
setWindowModified(true);
emit modified();
Expand Down Expand Up @@ -741,7 +740,6 @@ void MdiChild::checkAndInitModel(int row)
{
if (row < (int)radioData.models.size() && radioData.models[row].isEmpty()) {
radioData.models[row].setDefaultValues(row, radioData.generalSettings);
setModified();
}
}

Expand Down Expand Up @@ -829,9 +827,8 @@ int MdiChild::newModel(int modelIndex)
if (countUsedModels() == 1) {
radioData.setCurrentModel(modelIndex);
}

setModelModified(modelIndex);
setSelectedModel(modelIndex);
setModified();

if (isNewModel) {
if (g.newModelAction() == AppData::MODEL_ACT_WIZARD)
Expand Down Expand Up @@ -990,6 +987,7 @@ void MdiChild::pasteModelData(const QMimeData * mimeData, const QModelIndex row,
strcpy(radioData.models[modelIdx].filename, radioData.getNextModelFilename().toStdString().c_str());
lastSelectedModel = modelIdx; // after refresh the last pasted model will be selected
modified = true;
setModelModified(modelIdx, false); // avoid unnecessary refreshes
if (doMove) {
deletesList.append(origMdlIdx);
removeModelFromCutList(origMdlIdx);
Expand Down Expand Up @@ -1178,7 +1176,7 @@ void MdiChild::openModelWizard(int row)
int res = wizard->exec();
if (res == QDialog::Accepted && wizard->mix.complete /*TODO rather test the exec() result?*/) {
radioData.models[row] = wizard->mix;
setModified();
setModelModified(row);
setSelectedModel(row);
}
}
Expand All @@ -1203,7 +1201,7 @@ void MdiChild::openModelEditWindow(int row)
ModelEdit * t = new ModelEdit(this, radioData, (row), firmware);
gStopwatch.report("ModelEdit created");
t->setWindowTitle(tr("Editing model %1: ").arg(row+1) + QString(model.name) + QString(" (%1)").arg(userFriendlyCurrentFile()));
connect(t, &ModelEdit::modified, this, &MdiChild::setModified);
connect(t, &ModelEdit::modified, this, &MdiChild::setCurrentModelModified);
gStopwatch.report("STARTING MODEL EDIT");
t->show();
QApplication::restoreOverrideCursor();
Expand Down Expand Up @@ -1673,6 +1671,8 @@ void MdiChild::openModelTemplate(int row)
for (int i = 0; i < CPN_MAX_MODULES; i++) {
radioData.models[row].moduleData[i].modelId = row + 1;
}

setModelModified(row);
}

void MdiChild::openModelPrompt(int row)
Expand Down Expand Up @@ -1827,3 +1827,17 @@ void MdiChild::exportSelectedModels()
{
exportModels(getSelectedModels());
}

void MdiChild::setCurrentModelModified()
{
setModelModified(getCurrentModel());
}

void MdiChild::setModelModified(const int modelIndex, bool cascade)
{
if (modelIndex >= 0 && modelIndex < (int)radioData.models.size()) {
radioData.models[modelIndex].modelUpdated = true;
if (cascade)
setModified();
}
}
2 changes: 2 additions & 0 deletions companion/src/mdichild.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class MdiChild : public QWidget
void updateNavigation();
void updateTitle();
void setModified();
void setCurrentModelModified();
void retranslateUi();
void showModelsListContextMenu(const QPoint & pos);
void showLabelsContextMenu(const QPoint & pos);
Expand Down Expand Up @@ -228,6 +229,7 @@ class MdiChild : public QWidget
const quint16 stateDataVersion;
AbstractStaticItemModel* modelSortOrderItemModel;
QComboBox* cboModelSortOrder;
void setModelModified(const int modelIndex, bool cascade = true);
};

// This will draw the drop indicator across all columns of a model View (vs. in just one column), and lets us make the indicator more obvious.
Expand Down

0 comments on commit 9398ca4

Please sign in to comment.