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
+4 -3
View File
@@ -813,10 +813,11 @@ StringTagMappingTable Boards::getTrimSourcesLookupTable(Board::Type board)
QList<int> Boards::getSupportedInternalModules(Board::Type board)
{
QList<int> modules;
modules = {(int)MODULE_TYPE_NONE};
if (IS_TARANIS_X9DP_2019(board) || IS_TARANIS_X7_ACCESS(board)) {
modules = {(int)MODULE_TYPE_ISRM_PXX2};
modules.append({(int)MODULE_TYPE_ISRM_PXX2});
} else if (IS_FLYSKY_NV14(board)) {
modules = {(int)MODULE_TYPE_FLYSKY};
modules.append({(int)MODULE_TYPE_FLYSKY});
} else if (IS_FAMILY_HORUS_OR_T16(board) || IS_FAMILY_T12(board)
|| (IS_TARANIS_SMALL(board) && IS_ACCESS_RADIO(board))) {
modules.append({
@@ -826,7 +827,7 @@ QList<int> Boards::getSupportedInternalModules(Board::Type board)
(int)MODULE_TYPE_MULTIMODULE,
});
} else if (IS_TARANIS(board)) {
modules = {(int)MODULE_TYPE_XJT_PXX1};
modules.append({(int)MODULE_TYPE_XJT_PXX1});
}
return modules;
+1 -2
View File
@@ -212,7 +212,6 @@ class Boards
static QString potTypeToString(int value);
static QString sliderTypeToString(int value);
static QString switchTypeToString(int value);
static QString intModuleTypeToString(int value);
static AbstractStaticItemModel * potTypeItemModel();
static AbstractStaticItemModel * sliderTypeItemModel();
static AbstractStaticItemModel * switchTypeItemModel();
@@ -221,7 +220,7 @@ class Boards
static StringTagMappingTable getTrimSourcesLookupTable(Board::Type board);
static QList<int> getSupportedInternalModules(Board::Type board);
static int getDefaultInternalModules(Board::Type board);
protected:
Board::Type m_boardType;
+1 -1
View File
@@ -381,7 +381,7 @@ bool ModuleData::isProtocolAvailable(int moduleidx, unsigned int protocol, Gener
Firmware *fw = getCurrentFirmware();
Board::Type board = fw->getBoard();
if (moduleidx == 0 && Boards::getCapability(board, Board::HasInternalModuleSupport))
if (moduleidx == 0)
return (int)settings.internalModule == getTypeFromProtocol(protocol);
QString id = fw->getId();
+6 -1
View File
@@ -66,9 +66,12 @@ GeneralEdit::GeneralEdit(QWidget * parent, RadioData & radioData, Firmware * fir
addTab(new GeneralSetupPanel(this, generalSettings, firmware), tr("Setup"));
addTab(new CustomFunctionsPanel(this, nullptr, generalSettings, firmware, editorItemModels), tr("Global Functions"));
addTab(new TrainerPanel(this, generalSettings, firmware, editorItemModels), tr("Trainer"));
addTab(new HardwarePanel(this, generalSettings, firmware, editorItemModels), tr("Hardware"));
auto hwpnl = new HardwarePanel(this, generalSettings, firmware, editorItemModels);
addTab(hwpnl, tr("Hardware"));
addTab(new CalibrationPanel(this, generalSettings, firmware), tr("Calibration"));
connect(hwpnl, &HardwarePanel::internalModuleChanged, this, [&] { intModChanged = true; });
ui->tabWidget->setCurrentIndex( g.generalEditTab() );
}
@@ -81,6 +84,8 @@ GeneralEdit::~GeneralEdit()
void GeneralEdit::closeEvent(QCloseEvent *event)
{
g.generalEditTab(ui->tabWidget->currentIndex());
if (intModChanged)
emit internalModuleChanged(); // for MidiChild to trap
}
void GeneralEdit::addTab(GenericPanel *panel, QString text)
+5 -1
View File
@@ -47,6 +47,9 @@ class GeneralEdit : public QDialog
GeneralEdit(QWidget * parent, RadioData & radioData, Firmware * firmware);
~GeneralEdit();
protected:
virtual void closeEvent(QCloseEvent *event) override;
private:
Ui::GeneralEdit *ui;
GeneralSettings & generalSettings;
@@ -60,6 +63,7 @@ class GeneralEdit : public QDialog
signals:
void modified();
void internalModuleChanged();
private slots:
void onTabModified();
@@ -71,6 +75,6 @@ class GeneralEdit : public QDialog
Firmware * firmware;
QVector<GenericPanel *> panels;
void addTab(GenericPanel *panel, QString text);
void closeEvent(QCloseEvent *event);
CompoundItemModelFactory *editorItemModels;
bool intModChanged = false;
};
+18 -5
View File
@@ -132,15 +132,13 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings
}
if (Boards::getCapability(board, Board::HasInternalModuleSupport)) {
m_internalModule = generalSettings.internalModule; // to permit undo
addLabel(tr("Internal module"), row, 0);
AutoComboBox *internalModule = new AutoComboBox(this);
internalModule = new AutoComboBox(this);
internalModule->setModel(tabFilteredModels->getItemModel(FIM_INTERNALMODULES));
internalModule->setField(generalSettings.internalModule, this);
addParams(row, internalModule);
connect(internalModule, &AutoComboBox::currentDataChanged, this, [=] () {
QMessageBox::warning(this, CPN_STR_APP_NAME,
tr("ALERT: Check each model's internal module protocol to ensure it is compatible!"));
});
connect(internalModule, &AutoComboBox::currentDataChanged, this, &HardwarePanel::on_internalModuleChanged);
}
if (firmware->getCapability(HasTelemetryBaudrate)) {
@@ -206,6 +204,21 @@ HardwarePanel::~HardwarePanel()
delete tabFilteredModels;
}
void HardwarePanel::on_internalModuleChanged()
{
if (QMessageBox::warning(this, CPN_STR_APP_NAME,
tr("Warning: Changing the Internal module may invalidate the internal module protocol of the models!"),
QMessageBox::Cancel | QMessageBox::Ok, QMessageBox::Cancel) != QMessageBox::Ok) {
generalSettings.internalModule = m_internalModule;
internalModule->updateValue();
}
else {
m_internalModule = generalSettings.internalModule;
emit internalModuleChanged();
}
}
void HardwarePanel::addStick(int index, int & row)
{
int col = 0;
+9
View File
@@ -25,6 +25,7 @@
class CompoundItemModelFactory;
class FilteredItemModelFactory;
class QGridLayout;
class AutoComboBox;
class HardwarePanel : public GeneralPanel
{
@@ -34,11 +35,19 @@ class HardwarePanel : public GeneralPanel
HardwarePanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware, CompoundItemModelFactory * editorItemModels);
virtual ~HardwarePanel();
signals:
void internalModuleChanged();
private slots:
void on_internalModuleChanged();
private:
Board::Type board;
CompoundItemModelFactory *editorItemModels;
FilteredItemModelFactory *tabFilteredModels;
QGridLayout *grid;
AutoComboBox *internalModule;
unsigned int m_internalModule = 0;
void addStick(int index, int & row);
void addPot(int index, int & row);
+1
View File
@@ -50,6 +50,7 @@ class MainWindow : public QMainWindow
void firmwareDownloadCompleted();
void firmwareChanged();
void startSync();
void onInternalModuleChanged();
protected:
QString getCompanionUpdateBaseUrl() const;
+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;
}
+5
View File
@@ -117,6 +117,7 @@ class MdiChild : public QWidget
void onItemSelected(const QModelIndex &);
void onCurrentItemChanged(const QModelIndex &, const QModelIndex &);
void onDataChanged(const QModelIndex & index);
void onInternalModuleChanged();
void generalEdit();
void copyGeneralSettings();
@@ -183,6 +184,10 @@ class MdiChild : public QWidget
bool convertStorage(Board::Type from, Board::Type to, bool newFile = false);
void showWarning(const QString & msg);
int askQuestion(const QString & msg, QMessageBox::StandardButtons buttons = (QMessageBox::Yes | QMessageBox::No), QMessageBox::StandardButton defaultButton = QMessageBox::No);
QDialog * getChildDialog(QRegularExpression & regexp);
QDialog * getModelEditDialog(int row);
QList<QDialog *> * getChildrenDialogsList(QRegularExpression & regexp);
QList<QDialog *> * getModelEditDialogsList();
Ui::MdiChild * ui;
TreeModel * modelsListModel;
+1
View File
@@ -49,6 +49,7 @@ ModelEdit::ModelEdit(QWidget * parent, RadioData & radioData, int modelId, Firmw
ui->setupUi(this);
setWindowIcon(CompanionIcon("edit.png"));
setAttribute(Qt::WA_DeleteOnClose);
restoreGeometry(g.modelEditGeo());
ui->pushButton->setIcon(CompanionIcon("simulate.png"));
+2
View File
@@ -48,6 +48,8 @@ class ModelEdit : public QDialog
ModelEdit(QWidget * parent, RadioData & radioData, int modelId, Firmware * firmware);
~ModelEdit();
int getModelId() { return modelId; }
protected:
void closeEvent(QCloseEvent *event);
+18
View File
@@ -28,6 +28,7 @@
#include "multiprotocols.h"
#include "checklistdialog.h"
#include "helpers.h"
#include "moduledata.h"
#include <QDir>
@@ -240,6 +241,23 @@ ModulePanel::ModulePanel(QWidget * parent, ModelData & model, ModuleData & modul
if (panelFilteredItemModels && moduleIdx >= 0) {
int id = panelFilteredItemModels->registerItemModel(new FilteredItemModel(ModuleData::protocolItemModel(generalSettings), moduleIdx + 1/*flag cannot be 0*/), QString("Module Protocol %1").arg(moduleIdx));
ui->protocol->setModel(panelFilteredItemModels->getItemModel(id));
if (ui->protocol->findData(module.protocol) < 0) {
QString msg = tr("Warning: The internal module protocol <b>%1</b> is incompatible with the hardware internal module <b>%2</b> and has been set to <b>OFF</b>!");
msg = msg.arg(module.protocolToString(module.protocol)).arg(ModuleData::typeToString(generalSettings.internalModule));
QMessageBox *msgBox = new QMessageBox(this);
msgBox->setIcon( QMessageBox::Warning );
msgBox->setText(msg);
msgBox->addButton( "Ok", QMessageBox::AcceptRole );
msgBox->setWindowFlag(Qt::WindowStaysOnTopHint);
msgBox->setAttribute(Qt::WA_DeleteOnClose); // delete pointer after close
msgBox->setModal(false);
msgBox->show();
module.clear();
}
ui->protocol->setField(module.protocol, this);
}