Companion hardware internal module continued (#1342)

* Add ability to undo hardware internal module change

* Add internal module protocol check on model edit

* Event driven check and update of all models

* Fix model edit dialog searches

* Add OFF to list of internal modules

* Fix internal module protocol list issue #1382
This commit is contained in:
Neil Horne
2022-01-10 11:13:21 +10:00
committed by GitHub
parent b41cb2a75a
commit fcf8fbdfff
13 changed files with 145 additions and 14 deletions
+74 -1
View File
@@ -32,6 +32,7 @@
#include "storage.h"
#include "radiointerface.h"
#include "radiodataconversionstate.h"
#include "filtereditemmodels.h"
#include <algorithm>
#include <ExportableTableView>
@@ -1091,9 +1092,15 @@ void MdiChild::pasteGeneralData(const QMimeData * mimeData)
void MdiChild::generalEdit()
{
if (getModelEditDialogsList()->count() > 0) {
QMessageBox::information(this, CPN_STR_APP_NAME, tr("Unable to Edit Radio Settings whilst models are open for editing."));
return;
}
GeneralEdit * t = new GeneralEdit(this, radioData, firmware);
connect(t, &GeneralEdit::modified, this, &MdiChild::setModified);
t->show();
connect(t, &GeneralEdit::internalModuleChanged, this, &MdiChild::onInternalModuleChanged); // passed up from HardwarePanel >> GeneralEdit
t->exec();
}
void MdiChild::copyGeneralSettings()
@@ -1260,6 +1267,13 @@ void MdiChild::openModelEditWindow(int row)
if (row < 0 && (row = getCurrentModel()) < 0)
return;
QDialog * med = getModelEditDialog(row);
if (med) {
med->activateWindow();
med->raise();
return;
}
QApplication::setOverrideCursor(Qt::WaitCursor);
checkAndInitModel(row);
ModelData & model = radioData.models[row];
@@ -1624,3 +1638,62 @@ bool MdiChild::loadBackup()
return false;
#endif
}
QList<QDialog *> * MdiChild::getModelEditDialogsList()
{
QList<QDialog *> *ret = new QList<QDialog *>();
QList<QDialog *> dlgs = findChildren<QDialog *>();
for (QDialog *dlg : dlgs) {
ModelEdit * med = dynamic_cast<ModelEdit *>(dlg);
if (med)
ret->append(dlg);
}
return ret;
}
QDialog * MdiChild::getModelEditDialog(int row)
{
QList<QDialog *> *dlgs = getModelEditDialogsList();
for (QDialog *dlg : *dlgs) {
ModelEdit * med = dynamic_cast<ModelEdit *>(dlg);
if (med && med->getModelId() == row)
return med;
}
return nullptr;
}
void MdiChild::onInternalModuleChanged()
{
FilteredItemModel * fim = new FilteredItemModel(ModuleData::protocolItemModel(radioData.generalSettings), 0 + 1/*flag cannot be 0*/);
int cnt = 0;
for (unsigned int i = 0; i < radioData.models.size(); i++) {
ModuleData & module = radioData.models[i].moduleData[0];
bool found = false;
for (int j = 0; j < fim->rowCount(); j++) {
if (fim->data(fim->index(j, 0), AbstractItemModel::IMDR_Id).toInt() == (int)module.protocol) {
found = true;
break;
}
}
if (!found) {
module.clear();
cnt++;
}
}
if (cnt > 0) {
QMessageBox::warning(this, CPN_STR_APP_NAME, tr("Internal module protocol changed to <b>OFF</b> for %1 models!").arg(cnt));
setModified();
}
delete fim;
}