Refactor to directly call updates to data models

This commit is contained in:
elecpower
2020-10-02 07:06:00 +10:00
parent 1364a88eb0
commit af4c5524b1
30 changed files with 401 additions and 331 deletions
+44 -3
View File
@@ -43,7 +43,7 @@ RawSourceItemModel::RawSourceItemModel(const GeneralSettings * const generalSett
addItems(SOURCE_TYPE_PPM, RawSource::SourcesGroup, fw->getCapability(TrainerInputs)); addItems(SOURCE_TYPE_PPM, RawSource::SourcesGroup, fw->getCapability(TrainerInputs));
addItems(SOURCE_TYPE_CH, RawSource::SourcesGroup, fw->getCapability(Outputs)); addItems(SOURCE_TYPE_CH, RawSource::SourcesGroup, fw->getCapability(Outputs));
addItems(SOURCE_TYPE_SPECIAL, RawSource::TelemGroup, 5); addItems(SOURCE_TYPE_SPECIAL, RawSource::TelemGroup, 5);
addItems(SOURCE_TYPE_TELEMETRY, RawSource::TelemGroup, CPN_MAX_SENSORS * 3); addItems(SOURCE_TYPE_TELEMETRY, RawSource::TelemGroup, fw->getCapability(Sensors) * 3);
addItems(SOURCE_TYPE_GVAR, RawSource::GVarsGroup, fw->getCapability(Gvars)); addItems(SOURCE_TYPE_GVAR, RawSource::GVarsGroup, fw->getCapability(Gvars));
} }
@@ -90,7 +90,7 @@ RawSwitchItemModel::RawSwitchItemModel(const GeneralSettings * const generalSett
// Descending switch direction: NOT (!) switches // Descending switch direction: NOT (!) switches
addItems(SWITCH_TYPE_ACT, -1); addItems(SWITCH_TYPE_ACT, -1);
addItems(SWITCH_TYPE_SENSOR, -CPN_MAX_SENSORS); addItems(SWITCH_TYPE_SENSOR, -fw->getCapability(Sensors));
addItems(SWITCH_TYPE_TELEMETRY, -1); addItems(SWITCH_TYPE_TELEMETRY, -1);
addItems(SWITCH_TYPE_FLIGHT_MODE, -fw->getCapability(FlightModes)); addItems(SWITCH_TYPE_FLIGHT_MODE, -fw->getCapability(FlightModes));
addItems(SWITCH_TYPE_VIRTUAL, -fw->getCapability(LogicalSwitches)); addItems(SWITCH_TYPE_VIRTUAL, -fw->getCapability(LogicalSwitches));
@@ -109,7 +109,7 @@ RawSwitchItemModel::RawSwitchItemModel(const GeneralSettings * const generalSett
addItems(SWITCH_TYPE_VIRTUAL, fw->getCapability(LogicalSwitches)); addItems(SWITCH_TYPE_VIRTUAL, fw->getCapability(LogicalSwitches));
addItems(SWITCH_TYPE_FLIGHT_MODE, fw->getCapability(FlightModes)); addItems(SWITCH_TYPE_FLIGHT_MODE, fw->getCapability(FlightModes));
addItems(SWITCH_TYPE_TELEMETRY, 1); addItems(SWITCH_TYPE_TELEMETRY, 1);
addItems(SWITCH_TYPE_SENSOR, CPN_MAX_SENSORS); addItems(SWITCH_TYPE_SENSOR, fw->getCapability(Sensors));
addItems(SWITCH_TYPE_ON, 1); addItems(SWITCH_TYPE_ON, 1);
addItems(SWITCH_TYPE_ONE, 1); addItems(SWITCH_TYPE_ONE, 1);
addItems(SWITCH_TYPE_ACT, 1); addItems(SWITCH_TYPE_ACT, 1);
@@ -220,3 +220,44 @@ void CurveItemModel::update()
emit dataUpdateComplete(); emit dataUpdateComplete();
} }
//
// CommonItemModels
//
CommonItemModels::CommonItemModels(const GeneralSettings * const generalSettings, const ModelData * const modelData, QObject * parent)
{
m_rawSourceItemModel = new RawSourceItemModel(generalSettings, modelData, parent);
m_rawSwitchItemModel = new RawSwitchItemModel(generalSettings, modelData, parent);
m_curveItemModel = new CurveItemModel(generalSettings, modelData, parent);
}
CommonItemModels::~CommonItemModels()
{
}
void CommonItemModels::update(const RadioModelObjects radioModelObjects)
{
switch (radioModelObjects) {
case RMO_CHANNELS:
case RMO_INPUTS:
case RMO_TELEMETRY_SENSORS:
case RMO_TIMERS:
m_rawSourceItemModel->update();
break;
case RMO_FLIGHT_MODES:
case RMO_GLOBAL_VARIABLES:
case RMO_LOGICAL_SWITCHES:
m_rawSourceItemModel->update();
m_rawSwitchItemModel->update();
break;
case RMO_CURVES:
m_curveItemModel->update();
break;
case RMO_SCRIPTS:
// no need to refresh
break;
default:
qDebug() << "Unknown RadioModelObject:" << radioModelObjects;
}
}
@@ -105,4 +105,36 @@ class CurveItemModel: public AbstractRawItemDataModel
void setDynamicItemData(QStandardItem * item, int index) const; void setDynamicItemData(QStandardItem * item, int index) const;
}; };
class CommonItemModels: public QObject
{
Q_OBJECT
public:
enum RadioModelObjects {
RMO_CHANNELS,
RMO_CURVES,
RMO_FLIGHT_MODES,
RMO_GLOBAL_VARIABLES,
RMO_INPUTS,
RMO_LOGICAL_SWITCHES,
RMO_SCRIPTS,
RMO_TELEMETRY_SENSORS,
RMO_TIMERS
};
Q_ENUM(RadioModelObjects)
explicit CommonItemModels(const GeneralSettings * const generalSettings, const ModelData * const modelData, QObject * parent = nullptr);
~CommonItemModels();
void update(const RadioModelObjects radioModelObjects);
RawSourceItemModel * rawSourceItemModel() const { return m_rawSourceItemModel; }
RawSwitchItemModel * rawSwitchItemModel() const { return m_rawSwitchItemModel; }
CurveItemModel * curveItemModel() const { return m_curveItemModel; }
private:
RawSourceItemModel *m_rawSourceItemModel;
RawSwitchItemModel *m_rawSwitchItemModel;
CurveItemModel *m_curveItemModel;
};
#endif // RAWITEMDATAMODELS_H #endif // RAWITEMDATAMODELS_H
@@ -19,7 +19,6 @@
*/ */
#include "rawitemfilteredmodel.h" #include "rawitemfilteredmodel.h"
#include "rawitemdatamodels.h"
RawItemFilteredModel::RawItemFilteredModel(QAbstractItemModel * sourceModel, int flags, QObject * parent) : RawItemFilteredModel::RawItemFilteredModel(QAbstractItemModel * sourceModel, int flags, QObject * parent) :
QSortFilterProxyModel(parent), QSortFilterProxyModel(parent),
@@ -31,10 +30,10 @@ RawItemFilteredModel::RawItemFilteredModel(QAbstractItemModel * sourceModel, int
setDynamicSortFilter(true); setDynamicSortFilter(true);
setSourceModel(sourceModel); setSourceModel(sourceModel);
AbstractRawItemDataModel * model = qobject_cast<AbstractRawItemDataModel *>(sourceModel); AbstractRawItemDataModel * itemModel = qobject_cast<AbstractRawItemDataModel *>(sourceModel);
if (model) { if (itemModel) {
connect(model, &AbstractRawItemDataModel::dataAboutToBeUpdated, this, &RawItemFilteredModel::onDataAboutToBeUpdated); connect(itemModel, &AbstractRawItemDataModel::dataAboutToBeUpdated, this, &RawItemFilteredModel::onDataAboutToBeUpdated);
connect(model, &AbstractRawItemDataModel::dataUpdateComplete, this, &RawItemFilteredModel::onDataUpdateComplete); connect(itemModel, &AbstractRawItemDataModel::dataUpdateComplete, this, &RawItemFilteredModel::onDataUpdateComplete);
} }
} }
@@ -62,9 +61,9 @@ bool RawItemFilteredModel::filterAcceptsRow(int sourceRow, const QModelIndex & s
void RawItemFilteredModel::update() const void RawItemFilteredModel::update() const
{ {
AbstractRawItemDataModel * model = qobject_cast<AbstractRawItemDataModel *>(sourceModel()); AbstractRawItemDataModel * itemModel = qobject_cast<AbstractRawItemDataModel *>(sourceModel());
if (model) if (itemModel)
model->update(); itemModel->update();
} }
void RawItemFilteredModel::onDataAboutToBeUpdated() void RawItemFilteredModel::onDataAboutToBeUpdated()
@@ -27,8 +27,6 @@
class GeneralSettings; class GeneralSettings;
class ModelData; class ModelData;
class RawSourceItemModel;
class RawSwitchItemModel;
class RawItemFilteredModel: public QSortFilterProxyModel class RawItemFilteredModel: public QSortFilterProxyModel
{ {
@@ -36,9 +34,11 @@ class RawItemFilteredModel: public QSortFilterProxyModel
public: public:
enum DataFilters { enum DataFilters {
AllFilter = AbstractRawItemDataModel::NegativeGroup | AbstractRawItemDataModel::NoneGroup | AbstractRawItemDataModel::PositiveGroup, AllFilter = AbstractRawItemDataModel::NegativeGroup | AbstractRawItemDataModel::NoneGroup | AbstractRawItemDataModel::PositiveGroup,
HideNegativeFilter = AllFilter &~ AbstractRawItemDataModel::NegativeGroup, AllExcludeNoneFilter = AllFilter &~ AbstractRawItemDataModel::NoneGroup,
NonePositiveFilter = AbstractRawItemDataModel::NoneGroup | AbstractRawItemDataModel::PositiveGroup, NegativeFilter = AbstractRawItemDataModel::NegativeGroup | AbstractRawItemDataModel::NoneGroup,
PositiveFilter = AbstractRawItemDataModel::PositiveGroup NegativeExcludeNoneFilter = AbstractRawItemDataModel::NegativeGroup,
PositiveFilter = AbstractRawItemDataModel::PositiveGroup | AbstractRawItemDataModel::NoneGroup,
PositiveExcludeNoneFilter = AbstractRawItemDataModel::PositiveGroup
}; };
Q_ENUM(DataFilters) Q_ENUM(DataFilters)
+1 -1
View File
@@ -59,7 +59,7 @@ QString RawSwitch::toString(Board::Type board, const GeneralSettings * const gen
tr("THs"), tr("TH%"), tr("THt") tr("THs"), tr("TH%"), tr("THt")
}; };
const QStringList directionIndicators = QStringList() static const QStringList directionIndicators = QStringList()
<< CPN_STR_SW_INDICATOR_UP << CPN_STR_SW_INDICATOR_UP
<< CPN_STR_SW_INDICATOR_NEUT << CPN_STR_SW_INDICATOR_NEUT
<< CPN_STR_SW_INDICATOR_DN; << CPN_STR_SW_INDICATOR_DN;
+2 -3
View File
@@ -56,11 +56,10 @@ GeneralEdit::GeneralEdit(QWidget * parent, RadioData & radioData, Firmware * fir
} }
} }
RawSourceItemModel *rawSourceModel = new RawSourceItemModel(&generalSettings, nullptr, this); commonItemModels = new CommonItemModels(&generalSettings, nullptr, this);
RawSwitchItemModel *rawSwitchModel = new RawSwitchItemModel(&generalSettings, nullptr, this);
addTab(new GeneralSetupPanel(this, generalSettings, firmware), tr("Setup")); addTab(new GeneralSetupPanel(this, generalSettings, firmware), tr("Setup"));
addTab(new CustomFunctionsPanel(this, nullptr, generalSettings, firmware, rawSourceModel, rawSwitchModel), tr("Global Functions")); addTab(new CustomFunctionsPanel(this, nullptr, generalSettings, firmware, commonItemModels), tr("Global Functions"));
addTab(new TrainerPanel(this, generalSettings, firmware), tr("Trainer")); addTab(new TrainerPanel(this, generalSettings, firmware), tr("Trainer"));
addTab(new HardwarePanel(this, generalSettings, firmware), tr("Hardware")); addTab(new HardwarePanel(this, generalSettings, firmware), tr("Hardware"));
addTab(new CalibrationPanel(this, generalSettings, firmware), tr("Calibration")); addTab(new CalibrationPanel(this, generalSettings, firmware), tr("Calibration"));
+4 -2
View File
@@ -25,6 +25,8 @@
#include "eeprominterface.h" #include "eeprominterface.h"
#include "genericpanel.h" #include "genericpanel.h"
class CommonItemModels;
namespace Ui { namespace Ui {
class GeneralEdit; class GeneralEdit;
} }
@@ -56,7 +58,7 @@ class GeneralEdit : public QDialog
void getGeneralSwitchDefPos(int i, bool val); void getGeneralSwitchDefPos(int i, bool val);
void setSwitchDefPos(); void setSwitchDefPos();
void updateVarioPitchRange(); void updateVarioPitchRange();
signals: signals:
void modified(); void modified();
@@ -71,7 +73,7 @@ class GeneralEdit : public QDialog
QVector<GenericPanel *> panels; QVector<GenericPanel *> panels;
void addTab(GenericPanel *panel, QString text); void addTab(GenericPanel *panel, QString text);
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event);
CommonItemModels *commonItemModels;
}; };
#endif // _GENERALEDIT_H_ #endif // _GENERALEDIT_H_
+20 -14
View File
@@ -96,15 +96,16 @@ void LimitsGroup::updateMinMax(int max)
} }
} }
} }
ChannelsPanel::ChannelsPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CurveItemModel * curveItemModel): ChannelsPanel::ChannelsPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels):
ModelPanel(parent, model, generalSettings, firmware) ModelPanel(parent, model, generalSettings, firmware),
commonItemModels(commonItemModels)
{ {
chnCapability = firmware->getCapability(Outputs); chnCapability = firmware->getCapability(Outputs);
int channelNameMaxLen = firmware->getCapability(ChannelsName); int channelNameMaxLen = firmware->getCapability(ChannelsName);
curveModel = new RawItemFilteredModel(curveItemModel, RawItemFilteredModel::AllFilter, this); curveFilteredModel = new RawItemFilteredModel(commonItemModels->curveItemModel(), RawItemFilteredModel::AllFilter, this);
connect(curveModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &ChannelsPanel::onModelDataAboutToBeUpdated); connect(curveFilteredModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &ChannelsPanel::onModelDataAboutToBeUpdated);
connect(curveModel, &RawItemFilteredModel::dataUpdateComplete, this, &ChannelsPanel::onModelDataUpdateComplete); connect(curveFilteredModel, &RawItemFilteredModel::dataUpdateComplete, this, &ChannelsPanel::onModelDataUpdateComplete);
QStringList headerLabels; QStringList headerLabels;
headerLabels << "#"; headerLabels << "#";
@@ -165,7 +166,7 @@ ChannelsPanel::ChannelsPanel(QWidget * parent, ModelData & model, GeneralSetting
if (IS_HORUS_OR_TARANIS(firmware->getBoard())) { if (IS_HORUS_OR_TARANIS(firmware->getBoard())) {
curveCB[i] = new QComboBox(this); curveCB[i] = new QComboBox(this);
curveCB[i]->setProperty("index", i); curveCB[i]->setProperty("index", i);
curveCB[i]->setModel(curveModel); curveCB[i]->setModel(curveFilteredModel);
connect(curveCB[i], SIGNAL(currentIndexChanged(int)), this, SLOT(curveEdited())); connect(curveCB[i], SIGNAL(currentIndexChanged(int)), this, SLOT(curveEdited()));
tableLayout->addWidget(i, col++, curveCB[i]); tableLayout->addWidget(i, col++, curveCB[i]);
} }
@@ -213,7 +214,6 @@ ChannelsPanel::~ChannelsPanel()
delete centerSB[i]; delete centerSB[i];
delete symlimitsChk[i]; delete symlimitsChk[i];
} }
delete curveModel;
} }
void ChannelsPanel::symlimitsEdited() void ChannelsPanel::symlimitsEdited()
@@ -233,7 +233,7 @@ void ChannelsPanel::nameEdited()
int index = le->property("index").toInt(); int index = le->property("index").toInt();
if (model->limitData[index].name != le->text()) { if (model->limitData[index].name != le->text()) {
strcpy(model->limitData[index].name, le->text().toLatin1()); strcpy(model->limitData[index].name, le->text().toLatin1());
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
} }
@@ -321,7 +321,7 @@ void ChannelsPanel::cmPaste()
if (hasClipboardData(&data)) { if (hasClipboardData(&data)) {
memcpy(&model->limitData[selectedIndex], data.constData(), sizeof(LimitData)); memcpy(&model->limitData[selectedIndex], data.constData(), sizeof(LimitData));
updateLine(selectedIndex); updateLine(selectedIndex);
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
} }
@@ -339,7 +339,7 @@ void ChannelsPanel::cmDelete()
updateLine(i); updateLine(i);
} }
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
@@ -430,7 +430,7 @@ void ChannelsPanel::cmClear(bool prompt)
model->limitData[selectedIndex].clear(); model->limitData[selectedIndex].clear();
model->updateAllReferences(ModelData::REF_UPD_TYPE_CHANNEL, ModelData::REF_UPD_ACT_CLEAR, selectedIndex); model->updateAllReferences(ModelData::REF_UPD_TYPE_CHANNEL, ModelData::REF_UPD_ACT_CLEAR, selectedIndex);
updateLine(selectedIndex); updateLine(selectedIndex);
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
@@ -444,7 +444,7 @@ void ChannelsPanel::cmClearAll()
model->updateAllReferences(ModelData::REF_UPD_TYPE_CHANNEL, ModelData::REF_UPD_ACT_CLEAR, i); model->updateAllReferences(ModelData::REF_UPD_TYPE_CHANNEL, ModelData::REF_UPD_ACT_CLEAR, i);
updateLine(i); updateLine(i);
} }
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
@@ -454,7 +454,7 @@ void ChannelsPanel::cmInsert()
model->limitData[selectedIndex].clear(); model->limitData[selectedIndex].clear();
model->updateAllReferences(ModelData::REF_UPD_TYPE_CHANNEL, ModelData::REF_UPD_ACT_SHIFT, selectedIndex, 0, 1); model->updateAllReferences(ModelData::REF_UPD_TYPE_CHANNEL, ModelData::REF_UPD_ACT_SHIFT, selectedIndex, 0, 1);
update(); update();
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
@@ -469,7 +469,7 @@ void ChannelsPanel::swapData(int idx1, int idx2)
model->updateAllReferences(ModelData::REF_UPD_TYPE_CHANNEL, ModelData::REF_UPD_ACT_SWAP, idx1, idx2); model->updateAllReferences(ModelData::REF_UPD_TYPE_CHANNEL, ModelData::REF_UPD_ACT_SWAP, idx1, idx2);
updateLine(idx1); updateLine(idx1);
updateLine(idx2); updateLine(idx2);
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
} }
@@ -482,4 +482,10 @@ void ChannelsPanel::onModelDataAboutToBeUpdated()
void ChannelsPanel::onModelDataUpdateComplete() void ChannelsPanel::onModelDataUpdateComplete()
{ {
update(); update();
lock = false;
}
void ChannelsPanel::updateItemModels()
{
commonItemModels->update(CommonItemModels::RMO_CHANNELS);
} }
+5 -6
View File
@@ -26,7 +26,7 @@
#include <QtCore> #include <QtCore>
class CurveItemModel; class CommonItemModels;
class RawItemFilteredModel; class RawItemFilteredModel;
constexpr char MIMETYPE_CHANNEL[] = "application/x-companion-channel"; constexpr char MIMETYPE_CHANNEL[] = "application/x-companion-channel";
@@ -57,7 +57,7 @@ class ChannelsPanel : public ModelPanel
Q_OBJECT Q_OBJECT
public: public:
ChannelsPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CurveItemModel * curveItemModel); ChannelsPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels);
~ChannelsPanel(); ~ChannelsPanel();
public slots: public slots:
@@ -84,9 +84,6 @@ class ChannelsPanel : public ModelPanel
void onModelDataAboutToBeUpdated(); void onModelDataAboutToBeUpdated();
void onModelDataUpdateComplete(); void onModelDataUpdateComplete();
signals:
void updateDataModels();
private: private:
bool hasClipboardData(QByteArray * data = nullptr) const; bool hasClipboardData(QByteArray * data = nullptr) const;
bool insertAllowed() const; bool insertAllowed() const;
@@ -103,7 +100,9 @@ class ChannelsPanel : public ModelPanel
QCheckBox *symlimitsChk[CPN_MAX_CHNOUT]; QCheckBox *symlimitsChk[CPN_MAX_CHNOUT];
int selectedIndex; int selectedIndex;
int chnCapability; int chnCapability;
RawItemFilteredModel *curveModel; CommonItemModels * commonItemModels;
RawItemFilteredModel *curveFilteredModel;
void updateItemModels();
}; };
#endif // _CHANNELS_H_ #endif // _CHANNELS_H_
+16 -9
View File
@@ -23,6 +23,7 @@
#include "node.h" #include "node.h"
#include "edge.h" #include "edge.h"
#include "helpers.h" #include "helpers.h"
#include "rawitemfilteredmodel.h"
#define GFX_MARGIN 16 #define GFX_MARGIN 16
@@ -108,10 +109,11 @@ float curveSymmetricalX(float x, float coeff, float yMin, float yMid, float yMax
return y; return y;
} }
CurvesPanel::CurvesPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware): CurvesPanel::CurvesPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels):
ModelPanel(parent, model, generalSettings, firmware), ModelPanel(parent, model, generalSettings, firmware),
ui(new Ui::Curves), ui(new Ui::Curves),
currentCurve(0) currentCurve(0),
commonItemModels(commonItemModels)
{ {
ui->setupUi(this); ui->setupUi(this);
@@ -523,7 +525,7 @@ void CurvesPanel::on_curveName_editingFinished()
if (ui->curveName->text() != model->curves[currentCurve].name) { if (ui->curveName->text() != model->curves[currentCurve].name) {
memset(model->curves[currentCurve].name, 0, sizeof(model->curves[currentCurve].name)); memset(model->curves[currentCurve].name, 0, sizeof(model->curves[currentCurve].name));
strcpy(model->curves[currentCurve].name, ui->curveName->text().toLatin1()); strcpy(model->curves[currentCurve].name, ui->curveName->text().toLatin1());
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
} }
@@ -712,7 +714,7 @@ void CurvesPanel::cmClear(bool prompt)
model->curves[selectedIndex].clear(); model->curves[selectedIndex].clear();
model->updateAllReferences(ModelData::REF_UPD_TYPE_CURVE, ModelData::REF_UPD_ACT_CLEAR, selectedIndex); model->updateAllReferences(ModelData::REF_UPD_TYPE_CURVE, ModelData::REF_UPD_ACT_CLEAR, selectedIndex);
update(); update();
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
@@ -726,7 +728,7 @@ void CurvesPanel::cmClearAll()
model->updateAllReferences(ModelData::REF_UPD_TYPE_CURVE, ModelData::REF_UPD_ACT_CLEAR, i); model->updateAllReferences(ModelData::REF_UPD_TYPE_CURVE, ModelData::REF_UPD_ACT_CLEAR, i);
} }
update(); update();
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
@@ -756,7 +758,7 @@ void CurvesPanel::cmDelete()
model->curves[maxCurves - 1].clear(); model->curves[maxCurves - 1].clear();
model->updateAllReferences(ModelData::REF_UPD_TYPE_CURVE, ModelData::REF_UPD_ACT_SHIFT, selectedIndex, 0, -1); model->updateAllReferences(ModelData::REF_UPD_TYPE_CURVE, ModelData::REF_UPD_ACT_SHIFT, selectedIndex, 0, -1);
update(); update();
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
@@ -766,7 +768,7 @@ void CurvesPanel::cmInsert()
model->curves[selectedIndex].clear(); model->curves[selectedIndex].clear();
model->updateAllReferences(ModelData::REF_UPD_TYPE_CURVE, ModelData::REF_UPD_ACT_SHIFT, selectedIndex, 0, 1); model->updateAllReferences(ModelData::REF_UPD_TYPE_CURVE, ModelData::REF_UPD_ACT_SHIFT, selectedIndex, 0, 1);
update(); update();
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
@@ -787,7 +789,7 @@ void CurvesPanel::cmPaste()
CurveData *cd = &model->curves[selectedIndex]; CurveData *cd = &model->curves[selectedIndex];
memcpy(cd, data.constData(), sizeof(CurveData)); memcpy(cd, data.constData(), sizeof(CurveData));
update(); update();
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
} }
@@ -802,11 +804,16 @@ void CurvesPanel::swapData(int idx1, int idx2)
memcpy(cd1, &cdtmp, sizeof(CurveData)); memcpy(cd1, &cdtmp, sizeof(CurveData));
model->updateAllReferences(ModelData::REF_UPD_TYPE_CURVE, ModelData::REF_UPD_ACT_SWAP, idx1, idx2); model->updateAllReferences(ModelData::REF_UPD_TYPE_CURVE, ModelData::REF_UPD_ACT_SWAP, idx1, idx2);
update(); update();
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
} }
void CurvesPanel::updateItemModels()
{
commonItemModels->update(CommonItemModels::RMO_CURVES);
}
CustomScene::CustomScene(QGraphicsView * view) : CustomScene::CustomScene(QGraphicsView * view) :
QGraphicsScene(view) QGraphicsScene(view)
{ {
+5 -4
View File
@@ -26,6 +26,8 @@
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QGraphicsView> #include <QGraphicsView>
class CommonItemModels;
constexpr char MIMETYPE_CURVE[] = "application/x-companion-curve"; constexpr char MIMETYPE_CURVE[] = "application/x-companion-curve";
namespace Ui { namespace Ui {
@@ -59,7 +61,7 @@ class CurvesPanel : public ModelPanel
Q_OBJECT Q_OBJECT
public: public:
CurvesPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware); CurvesPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels);
virtual ~CurvesPanel(); virtual ~CurvesPanel();
virtual void update(); virtual void update();
@@ -91,9 +93,6 @@ class CurvesPanel : public ModelPanel
void cmMoveDown(); void cmMoveDown();
void cmMoveUp(); void cmMoveUp();
signals:
void updateDataModels();
protected: protected:
virtual void resizeEvent(QResizeEvent *event); virtual void resizeEvent(QResizeEvent *event);
void addTemplate(QString name, unsigned int flags, curveFunction function); void addTemplate(QString name, unsigned int flags, curveFunction function);
@@ -122,6 +121,8 @@ class CurvesPanel : public ModelPanel
bool moveDownAllowed() const; bool moveDownAllowed() const;
bool moveUpAllowed() const; bool moveUpAllowed() const;
void swapData(int idx1, int idx2); void swapData(int idx1, int idx2);
CommonItemModels * commonItemModels;
void updateItemModels();
}; };
#endif // _CURVES_H_ #endif // _CURVES_H_
+22 -24
View File
@@ -66,10 +66,10 @@ void RepeatComboBox::update()
setCurrentIndex(value); setCurrentIndex(value);
} }
CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, GeneralSettings & generalSettings, Firmware * firmware, CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels):
RawSourceItemModel * rawSourceItemModel, RawSwitchItemModel * rawSwitchItemModel):
GenericPanel(parent, model, generalSettings, firmware), GenericPanel(parent, model, generalSettings, firmware),
functions(model ? model->customFn : generalSettings.customFn), functions(model ? model->customFn : generalSettings.customFn),
commonItemModels(commonItemModels),
mediaPlayerCurrent(-1), mediaPlayerCurrent(-1),
mediaPlayer(nullptr), mediaPlayer(nullptr),
modelsUpdateCnt(0) modelsUpdateCnt(0)
@@ -77,21 +77,21 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
lock = true; lock = true;
fswCapability = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions); fswCapability = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions);
rawSwitchModel = new RawItemFilteredModel(rawSwitchItemModel, model ? RawSwitch::SpecialFunctionsContext : RawSwitch::GlobalFunctionsContext); rawSwitchFilteredModel = new RawItemFilteredModel(commonItemModels->rawSwitchItemModel(), model ? RawSwitch::SpecialFunctionsContext : RawSwitch::GlobalFunctionsContext, this);
connect(rawSwitchModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &CustomFunctionsPanel::onModelDataAboutToBeUpdated); connect(rawSwitchFilteredModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &CustomFunctionsPanel::onModelDataAboutToBeUpdated);
connect(rawSwitchModel, &RawItemFilteredModel::dataUpdateComplete, this, &CustomFunctionsPanel::onModelDataUpdateComplete); connect(rawSwitchFilteredModel, &RawItemFilteredModel::dataUpdateComplete, this, &CustomFunctionsPanel::onModelDataUpdateComplete);
rawSrcAllModel = new RawItemFilteredModel(rawSourceItemModel); rawSourceAllModel = new RawItemFilteredModel(commonItemModels->rawSourceItemModel(), this);
connect(rawSrcAllModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &CustomFunctionsPanel::onModelDataAboutToBeUpdated); connect(rawSourceAllModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &CustomFunctionsPanel::onModelDataAboutToBeUpdated);
connect(rawSrcAllModel, &RawItemFilteredModel::dataUpdateComplete, this, &CustomFunctionsPanel::onModelDataUpdateComplete); connect(rawSourceAllModel, &RawItemFilteredModel::dataUpdateComplete, this, &CustomFunctionsPanel::onModelDataUpdateComplete);
rawSrcInputsModel = new RawItemFilteredModel(rawSourceItemModel, RawSource::InputSourceGroups); rawSourceInputsModel = new RawItemFilteredModel(commonItemModels->rawSourceItemModel(), RawSource::InputSourceGroups, this);
connect(rawSrcInputsModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &CustomFunctionsPanel::onModelDataAboutToBeUpdated); connect(rawSourceInputsModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &CustomFunctionsPanel::onModelDataAboutToBeUpdated);
connect(rawSrcInputsModel, &RawItemFilteredModel::dataUpdateComplete, this, &CustomFunctionsPanel::onModelDataUpdateComplete); connect(rawSourceInputsModel, &RawItemFilteredModel::dataUpdateComplete, this, &CustomFunctionsPanel::onModelDataUpdateComplete);
rawSrcGVarsModel = new RawItemFilteredModel(rawSourceItemModel, RawSource::GVarsGroup); rawSourceGVarsModel = new RawItemFilteredModel(commonItemModels->rawSourceItemModel(), RawSource::GVarsGroup, this);
connect(rawSrcGVarsModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &CustomFunctionsPanel::onModelDataAboutToBeUpdated); connect(rawSourceGVarsModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &CustomFunctionsPanel::onModelDataAboutToBeUpdated);
connect(rawSrcGVarsModel, &RawItemFilteredModel::dataUpdateComplete, this, &CustomFunctionsPanel::onModelDataUpdateComplete); connect(rawSourceGVarsModel, &RawItemFilteredModel::dataUpdateComplete, this, &CustomFunctionsPanel::onModelDataUpdateComplete);
if (!firmware->getCapability(VoicesAsNumbers)) { if (!firmware->getCapability(VoicesAsNumbers)) {
tracksSet = getFilesSet(getSoundsPath(generalSettings), QStringList() << "*.wav" << "*.WAV", firmware->getCapability(VoicesMaxLength)); tracksSet = getFilesSet(getSoundsPath(generalSettings), QStringList() << "*.wav" << "*.WAV", firmware->getCapability(VoicesMaxLength));
@@ -142,7 +142,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
// The switch // The switch
fswtchSwtch[i] = new QComboBox(this); fswtchSwtch[i] = new QComboBox(this);
fswtchSwtch[i]->setModel(rawSwitchModel); fswtchSwtch[i]->setModel(rawSwitchFilteredModel);
fswtchSwtch[i]->setCurrentIndex(fswtchSwtch[i]->findData(functions[i].swtch.toValue())); fswtchSwtch[i]->setCurrentIndex(fswtchSwtch[i]->findData(functions[i].swtch.toValue()));
fswtchSwtch[i]->setProperty("index", i); fswtchSwtch[i]->setProperty("index", i);
fswtchSwtch[i]->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum); fswtchSwtch[i]->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum);
@@ -253,10 +253,6 @@ CustomFunctionsPanel::~CustomFunctionsPanel()
{ {
if (mediaPlayer) if (mediaPlayer)
stopSound(mediaPlayerCurrent); stopSound(mediaPlayerCurrent);
delete rawSwitchModel;
delete rawSrcAllModel;
delete rawSrcInputsModel;
delete rawSrcGVarsModel;
} }
void CustomFunctionsPanel::onMediaPlayerStateChanged(QMediaPlayer::State state) void CustomFunctionsPanel::onMediaPlayerStateChanged(QMediaPlayer::State state)
@@ -707,21 +703,21 @@ void CustomFunctionsPanel::populateFuncParamCB(QComboBox *b, uint function, unsi
CustomFunctionData::populateResetParams(model, b, value); CustomFunctionData::populateResetParams(model, b, value);
} }
else if (function == FuncVolume || function == FuncBacklight) { else if (function == FuncVolume || function == FuncBacklight) {
b->setModel(rawSrcInputsModel); b->setModel(rawSourceInputsModel);
b->setCurrentIndex(b->findData(value)); b->setCurrentIndex(b->findData(value));
} }
else if (function == FuncPlayValue) { else if (function == FuncPlayValue) {
b->setModel(rawSrcAllModel); b->setModel(rawSourceAllModel);
b->setCurrentIndex(b->findData(value)); b->setCurrentIndex(b->findData(value));
} }
else if (function >= FuncAdjustGV1 && function <= FuncAdjustGVLast) { else if (function >= FuncAdjustGV1 && function <= FuncAdjustGVLast) {
switch (adjustmode) { switch (adjustmode) {
case 1: case 1:
b->setModel(rawSrcInputsModel); b->setModel(rawSourceInputsModel);
b->setCurrentIndex(b->findData(value)); b->setCurrentIndex(b->findData(value));
break; break;
case 2: case 2:
b->setModel(rawSrcGVarsModel); b->setModel(rawSourceGVarsModel);
b->setCurrentIndex(b->findData(value)); b->setCurrentIndex(b->findData(value));
break; break;
} }
@@ -836,11 +832,13 @@ void CustomFunctionsPanel::onModelDataAboutToBeUpdated()
void CustomFunctionsPanel::onModelDataUpdateComplete() void CustomFunctionsPanel::onModelDataUpdateComplete()
{ {
modelsUpdateCnt--; modelsUpdateCnt--;
if (modelsUpdateCnt < 1) if (modelsUpdateCnt < 1) {
lock = true; lock = true;
for (int i = 0; i < fswCapability; i++) { for (int i = 0; i < fswCapability; i++) {
fswtchSwtch[i]->setCurrentIndex(fswtchSwtch[i]->findData(functions[i].swtch.toValue())); fswtchSwtch[i]->setCurrentIndex(fswtchSwtch[i]->findData(functions[i].swtch.toValue()));
fswtchFunc[i]->setCurrentIndex(fswtchFunc[i]->findData(functions[i].func)); fswtchFunc[i]->setCurrentIndex(fswtchFunc[i]->findData(functions[i].func));
} }
update(); update();
lock = false;
}
} }
+7 -8
View File
@@ -26,8 +26,7 @@
#include <QMediaPlayer> #include <QMediaPlayer>
class RawSourceItemModel; class CommonItemModels;
class RawSwitchItemModel;
class RawItemFilteredModel; class RawItemFilteredModel;
class TimerEdit; class TimerEdit;
@@ -56,8 +55,7 @@ class CustomFunctionsPanel : public GenericPanel
Q_OBJECT Q_OBJECT
public: public:
CustomFunctionsPanel(QWidget *parent, ModelData * model, GeneralSettings & generalSettings, Firmware * firmware, CustomFunctionsPanel(QWidget *parent, ModelData * model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels);
RawSourceItemModel * rawSourceItemModel, RawSwitchItemModel * rawSwitchItemModel);
~CustomFunctionsPanel(); ~CustomFunctionsPanel();
virtual void update(); virtual void update();
@@ -98,10 +96,11 @@ class CustomFunctionsPanel : public GenericPanel
bool moveUpAllowed() const; bool moveUpAllowed() const;
void swapData(int idx1, int idx2); void swapData(int idx1, int idx2);
void resetCBsAndRefresh(int idx); void resetCBsAndRefresh(int idx);
RawItemFilteredModel * rawSwitchModel; CommonItemModels * commonItemModels;
RawItemFilteredModel * rawSrcAllModel; RawItemFilteredModel * rawSwitchFilteredModel;
RawItemFilteredModel * rawSrcInputsModel; RawItemFilteredModel * rawSourceAllModel;
RawItemFilteredModel * rawSrcGVarsModel; RawItemFilteredModel * rawSourceInputsModel;
RawItemFilteredModel * rawSourceGVarsModel;
QSet<QString> tracksSet; QSet<QString> tracksSet;
QSet<QString> scriptsSet; QSet<QString> scriptsSet;
+14 -13
View File
@@ -24,15 +24,15 @@
#include "helpers.h" #include "helpers.h"
#include "customdebug.h" #include "customdebug.h"
FlightModePanel::FlightModePanel(QWidget * parent, ModelData & model, int phaseIdx, GeneralSettings & generalSettings, Firmware * firmware, RawItemFilteredModel * switchModel): FlightModePanel::FlightModePanel(QWidget * parent, ModelData & model, int phaseIdx, GeneralSettings & generalSettings, Firmware * firmware, RawItemFilteredModel * rawSwitchFilteredModel):
ModelPanel(parent, model, generalSettings, firmware), ModelPanel(parent, model, generalSettings, firmware),
ui(new Ui::FlightMode), ui(new Ui::FlightMode),
phaseIdx(phaseIdx), phaseIdx(phaseIdx),
phase(model.flightModeData[phaseIdx]) phase(model.flightModeData[phaseIdx])
{ {
ui->setupUi(this); ui->setupUi(this);
connect(switchModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &FlightModePanel::onModelDataAboutToBeUpdated); connect(rawSwitchFilteredModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &FlightModePanel::onModelDataAboutToBeUpdated);
connect(switchModel, &RawItemFilteredModel::dataUpdateComplete, this, &FlightModePanel::onModelDataUpdateComplete); connect(rawSwitchFilteredModel, &RawItemFilteredModel::dataUpdateComplete, this, &FlightModePanel::onModelDataUpdateComplete);
ui->labelName->setContextMenuPolicy(Qt::CustomContextMenu); ui->labelName->setContextMenuPolicy(Qt::CustomContextMenu);
ui->labelName->setToolTip(tr("Popup menu available")); ui->labelName->setToolTip(tr("Popup menu available"));
@@ -57,7 +57,7 @@ FlightModePanel::FlightModePanel(QWidget * parent, ModelData & model, int phaseI
// Flight mode switch // Flight mode switch
if (phaseIdx > 0) { if (phaseIdx > 0) {
ui->swtch->setModel(switchModel); ui->swtch->setModel(rawSwitchFilteredModel);
connect(ui->swtch, SIGNAL(currentIndexChanged(int)), this, SLOT(phaseSwitch_currentIndexChanged(int))); connect(ui->swtch, SIGNAL(currentIndexChanged(int)), this, SLOT(phaseSwitch_currentIndexChanged(int)));
} }
else { else {
@@ -1374,10 +1374,11 @@ void FlightModePanel::onModelDataUpdateComplete()
/**********************************************************/ /**********************************************************/
FlightModesPanel::FlightModesPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, RawSwitchItemModel * rawSwitchItemModel): FlightModesPanel::FlightModesPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels):
ModelPanel(parent, model, generalSettings, firmware) ModelPanel(parent, model, generalSettings, firmware),
commonItemModels(commonItemModels)
{ {
rawSwitchFilteredModel = new RawItemFilteredModel(rawSwitchItemModel, RawSwitch::MixesContext, this); rawSwitchFilteredModel = new RawItemFilteredModel(commonItemModels->rawSwitchItemModel(), RawSwitch::MixesContext, this);
modesCount = firmware->getCapability(FlightModes); modesCount = firmware->getCapability(FlightModes);
QGridLayout * gridLayout = new QGridLayout(this); QGridLayout * gridLayout = new QGridLayout(this);
@@ -1388,8 +1389,8 @@ FlightModesPanel::FlightModesPanel(QWidget * parent, ModelData & model, GeneralS
connect(tab, &FlightModePanel::modified, this, &FlightModesPanel::modified); connect(tab, &FlightModePanel::modified, this, &FlightModesPanel::modified);
connect(tab, &FlightModePanel::phaseDataChanged, this, &FlightModesPanel::onPhaseNameChanged); connect(tab, &FlightModePanel::phaseDataChanged, this, &FlightModesPanel::onPhaseNameChanged);
connect(tab, &FlightModePanel::phaseNameChanged, this, &FlightModesPanel::onPhaseNameChanged); connect(tab, &FlightModePanel::phaseNameChanged, this, &FlightModesPanel::onPhaseNameChanged);
connect(tab, &FlightModePanel::phaseSwitchChanged, this, &FlightModesPanel::refreshDataModels); connect(tab, &FlightModePanel::phaseSwitchChanged, this, &FlightModesPanel::updateItemModels);
connect(tab, &FlightModePanel::gvNameChanged, this, &FlightModesPanel::refreshDataModels); connect(tab, &FlightModePanel::gvNameChanged, this, &FlightModesPanel::updateItemModels);
connect(this, &FlightModesPanel::updated, tab, &FlightModePanel::update); connect(this, &FlightModesPanel::updated, tab, &FlightModePanel::update);
tabWidget->addTab(tab, getTabName(i)); tabWidget->addTab(tab, getTabName(i));
@@ -1402,7 +1403,6 @@ FlightModesPanel::FlightModesPanel(QWidget * parent, ModelData & model, GeneralS
FlightModesPanel::~FlightModesPanel() FlightModesPanel::~FlightModesPanel()
{ {
delete rawSwitchFilteredModel;
} }
QString FlightModesPanel::getTabName(int index) QString FlightModesPanel::getTabName(int index)
@@ -1423,7 +1423,7 @@ void FlightModesPanel::onPhaseNameChanged()
{ {
int index = sender()->property("index").toInt(); int index = sender()->property("index").toInt();
tabWidget->setTabText(index, getTabName(index)); tabWidget->setTabText(index, getTabName(index));
refreshDataModels(); updateItemModels();
} }
void FlightModesPanel::update() void FlightModesPanel::update()
@@ -1431,9 +1431,10 @@ void FlightModesPanel::update()
emit updated(); emit updated();
} }
void FlightModesPanel::refreshDataModels() void FlightModesPanel::updateItemModels()
{ {
emit updateDataModels(); commonItemModels->update(CommonItemModels::RMO_FLIGHT_MODES);
commonItemModels->update(CommonItemModels::RMO_GLOBAL_VARIABLES);
} }
void FlightModesPanel::onTabIndexChanged(int index) void FlightModesPanel::onTabIndexChanged(int index)
+5 -5
View File
@@ -24,7 +24,7 @@
#include "modeledit.h" #include "modeledit.h"
#include "eeprominterface.h" #include "eeprominterface.h"
class RawSwitchItemModel; class CommonItemModels;
class RawItemFilteredModel; class RawItemFilteredModel;
constexpr char MIMETYPE_FLIGHTMODE[] = "application/x-companion-flightmode"; constexpr char MIMETYPE_FLIGHTMODE[] = "application/x-companion-flightmode";
@@ -41,7 +41,7 @@ class FlightModePanel : public ModelPanel
Q_OBJECT Q_OBJECT
public: public:
FlightModePanel(QWidget *parent, ModelData &model, int modeIdx, GeneralSettings & generalSettings, Firmware * firmware, RawItemFilteredModel * switchModel); FlightModePanel(QWidget *parent, ModelData &model, int modeIdx, GeneralSettings & generalSettings, Firmware * firmware, RawItemFilteredModel * rawSwitchFilteredModel);
virtual ~FlightModePanel(); virtual ~FlightModePanel();
virtual void update(); virtual void update();
@@ -145,19 +145,17 @@ class FlightModesPanel : public ModelPanel
Q_OBJECT Q_OBJECT
public: public:
FlightModesPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, RawSwitchItemModel * rawSwitchItemModel); FlightModesPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels);
virtual ~FlightModesPanel(); virtual ~FlightModesPanel();
public slots: public slots:
virtual void update() override; virtual void update() override;
signals: signals:
void updateDataModels();
void updated(); void updated();
private slots: private slots:
void onPhaseNameChanged(); void onPhaseNameChanged();
void refreshDataModels();
void onTabIndexChanged(int index); void onTabIndexChanged(int index);
private: private:
@@ -165,8 +163,10 @@ class FlightModesPanel : public ModelPanel
int modesCount; int modesCount;
QTabWidget *tabWidget; QTabWidget *tabWidget;
CommonItemModels *commonItemModels;
RawItemFilteredModel *rawSwitchFilteredModel; RawItemFilteredModel *rawSwitchFilteredModel;
QVector<GenericPanel *> panels; QVector<GenericPanel *> panels;
void updateItemModels();
}; };
#endif // _FLIGHTMODES_H_ #endif // _FLIGHTMODES_H_
+10 -9
View File
@@ -23,22 +23,26 @@
#include "helpers.h" #include "helpers.h"
#include "rawitemfilteredmodel.h" #include "rawitemfilteredmodel.h"
HeliPanel::HeliPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, RawSourceItemModel * rawSourceItemModel): HeliPanel::HeliPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels):
ModelPanel(parent, model, generalSettings, firmware), ModelPanel(parent, model, generalSettings, firmware),
ui(new Ui::Heli) ui(new Ui::Heli),
commonItemModels(commonItemModels)
{ {
ui->setupUi(this); ui->setupUi(this);
rawSourceModel = new RawItemFilteredModel(rawSourceItemModel, RawSource::InputSourceGroups, this); rawSourceFilteredModel = new RawItemFilteredModel(commonItemModels->rawSourceItemModel(), RawSource::InputSourceGroups, this);
connect(rawSourceModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &HeliPanel::onModelDataAboutToBeUpdated); connect(rawSourceFilteredModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &HeliPanel::onModelDataAboutToBeUpdated);
connect(rawSourceModel, &RawItemFilteredModel::dataUpdateComplete, this, &HeliPanel::onModelDataUpdateComplete); connect(rawSourceFilteredModel, &RawItemFilteredModel::dataUpdateComplete, this, &HeliPanel::onModelDataUpdateComplete);
connect(ui->swashType, SIGNAL(currentIndexChanged(int)), this, SLOT(edited())); connect(ui->swashType, SIGNAL(currentIndexChanged(int)), this, SLOT(edited()));
connect(ui->swashRingVal, SIGNAL(editingFinished()), this, SLOT(edited())); connect(ui->swashRingVal, SIGNAL(editingFinished()), this, SLOT(edited()));
ui->swashCollectiveSource->setModel(rawSourceFilteredModel);
connect(ui->swashCollectiveSource, SIGNAL(currentIndexChanged(int)), this, SLOT(edited())); connect(ui->swashCollectiveSource, SIGNAL(currentIndexChanged(int)), this, SLOT(edited()));
if (firmware->getCapability(VirtualInputs)) { if (firmware->getCapability(VirtualInputs)) {
ui->swashAileronSource->setModel(rawSourceFilteredModel);
connect(ui->swashAileronSource, SIGNAL(currentIndexChanged(int)), this, SLOT(edited())); connect(ui->swashAileronSource, SIGNAL(currentIndexChanged(int)), this, SLOT(edited()));
ui->swashElevatorSource->setModel(rawSourceFilteredModel);
connect(ui->swashElevatorSource, SIGNAL(currentIndexChanged(int)), this, SLOT(edited())); connect(ui->swashElevatorSource, SIGNAL(currentIndexChanged(int)), this, SLOT(edited()));
connect(ui->swashAileronWeight, SIGNAL(editingFinished()), this, SLOT(edited())); connect(ui->swashAileronWeight, SIGNAL(editingFinished()), this, SLOT(edited()));
connect(ui->swashElevatorWeight, SIGNAL(editingFinished()), this, SLOT(edited())); connect(ui->swashElevatorWeight, SIGNAL(editingFinished()), this, SLOT(edited()));
@@ -66,7 +70,6 @@ HeliPanel::HeliPanel(QWidget *parent, ModelData & model, GeneralSettings & gener
HeliPanel::~HeliPanel() HeliPanel::~HeliPanel()
{ {
delete rawSourceModel;
delete ui; delete ui;
} }
@@ -75,13 +78,10 @@ void HeliPanel::update()
lock = true; lock = true;
ui->swashType->setCurrentIndex(model->swashRingData.type); ui->swashType->setCurrentIndex(model->swashRingData.type);
ui->swashCollectiveSource->setModel(rawSourceModel);
ui->swashCollectiveSource->setCurrentIndex(ui->swashCollectiveSource->findData(model->swashRingData.collectiveSource.toValue())); ui->swashCollectiveSource->setCurrentIndex(ui->swashCollectiveSource->findData(model->swashRingData.collectiveSource.toValue()));
ui->swashRingVal->setValue(model->swashRingData.value); ui->swashRingVal->setValue(model->swashRingData.value);
if (firmware->getCapability(VirtualInputs)) { if (firmware->getCapability(VirtualInputs)) {
ui->swashElevatorSource->setModel(rawSourceModel);
ui->swashElevatorSource->setCurrentIndex(ui->swashElevatorSource->findData(model->swashRingData.elevatorSource.toValue())); ui->swashElevatorSource->setCurrentIndex(ui->swashElevatorSource->findData(model->swashRingData.elevatorSource.toValue()));
ui->swashAileronSource->setModel(rawSourceModel);
ui->swashAileronSource->setCurrentIndex(ui->swashAileronSource->findData(model->swashRingData.aileronSource.toValue())); ui->swashAileronSource->setCurrentIndex(ui->swashAileronSource->findData(model->swashRingData.aileronSource.toValue()));
ui->swashElevatorWeight->setValue(model->swashRingData.elevatorWeight); ui->swashElevatorWeight->setValue(model->swashRingData.elevatorWeight);
ui->swashAileronWeight->setValue(model->swashRingData.aileronWeight); ui->swashAileronWeight->setValue(model->swashRingData.aileronWeight);
@@ -126,4 +126,5 @@ void HeliPanel::onModelDataAboutToBeUpdated()
void HeliPanel::onModelDataUpdateComplete() void HeliPanel::onModelDataUpdateComplete()
{ {
update(); update();
lock = false;
} }
+4 -3
View File
@@ -23,7 +23,7 @@
#include "modeledit.h" #include "modeledit.h"
class RawSourceItemModel; class CommonItemModels;
class RawItemFilteredModel; class RawItemFilteredModel;
namespace Ui { namespace Ui {
@@ -35,7 +35,7 @@ class HeliPanel : public ModelPanel
Q_OBJECT Q_OBJECT
public: public:
HeliPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, RawSourceItemModel * rawSourceItemModel); HeliPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels);
~HeliPanel(); ~HeliPanel();
void update(); void update();
@@ -46,7 +46,8 @@ class HeliPanel : public ModelPanel
private: private:
Ui::Heli *ui; Ui::Heli *ui;
RawItemFilteredModel * rawSourceModel; CommonItemModels * commonItemModels;
RawItemFilteredModel * rawSourceFilteredModel;
}; };
#endif // _HELI_H_ #endif // _HELI_H_
+25 -21
View File
@@ -23,19 +23,19 @@
#include "helpers.h" #include "helpers.h"
#include "rawitemfilteredmodel.h" #include "rawitemfilteredmodel.h"
InputsPanel::InputsPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, InputsPanel::InputsPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels):
RawSourceItemModel * rawSourceItemModel, RawSwitchItemModel * rawSwitchItemModel):
ModelPanel(parent, model, generalSettings, firmware), ModelPanel(parent, model, generalSettings, firmware),
expoInserted(false), expoInserted(false),
modelPrinter(firmware, generalSettings, model) modelPrinter(firmware, generalSettings, model),
commonItemModels(commonItemModels)
{ {
rawSourceModel = new RawItemFilteredModel(rawSourceItemModel, (RawSource::InputSourceGroups & ~ RawSource::NoneGroup & ~RawSource::InputsGroup), this); rawSourceFilteredModel = new RawItemFilteredModel(commonItemModels->rawSourceItemModel(), (RawSource::InputSourceGroups & ~ RawSource::NoneGroup & ~RawSource::InputsGroup), this);
connect(rawSourceModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &InputsPanel::onModelDataAboutToBeUpdated); connect(rawSourceFilteredModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &InputsPanel::onModelDataAboutToBeUpdated);
connect(rawSourceModel, &RawItemFilteredModel::dataUpdateComplete, this, &InputsPanel::onModelDataUpdateComplete); connect(rawSourceFilteredModel, &RawItemFilteredModel::dataUpdateComplete, this, &InputsPanel::onModelDataUpdateComplete);
rawSwitchModel = new RawItemFilteredModel(rawSwitchItemModel, RawSwitch::MixesContext, this); rawSwitchFilteredModel = new RawItemFilteredModel(commonItemModels->rawSwitchItemModel(), RawSwitch::MixesContext, this);
connect(rawSwitchModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &InputsPanel::onModelDataAboutToBeUpdated); connect(rawSwitchFilteredModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &InputsPanel::onModelDataAboutToBeUpdated);
connect(rawSwitchModel, &RawItemFilteredModel::dataUpdateComplete, this, &InputsPanel::onModelDataUpdateComplete); connect(rawSwitchFilteredModel, &RawItemFilteredModel::dataUpdateComplete, this, &InputsPanel::onModelDataUpdateComplete);
inputsCount = firmware->getCapability(VirtualInputs); inputsCount = firmware->getCapability(VirtualInputs);
if (inputsCount == 0) if (inputsCount == 0)
@@ -75,8 +75,6 @@ InputsPanel::InputsPanel(QWidget *parent, ModelData & model, GeneralSettings & g
InputsPanel::~InputsPanel() InputsPanel::~InputsPanel()
{ {
delete rawSourceModel;
delete rawSwitchModel;
} }
void InputsPanel::update() void InputsPanel::update()
@@ -192,13 +190,13 @@ void InputsPanel::gm_openExpo(int index)
if (firmware->getCapability(VirtualInputs)) if (firmware->getCapability(VirtualInputs))
inputName = model->inputNames[ed.chn]; inputName = model->inputNames[ed.chn];
ExpoDialog *g = new ExpoDialog(this, *model, &ed, generalSettings, firmware, inputName, rawSourceModel, rawSwitchModel); ExpoDialog *g = new ExpoDialog(this, *model, &ed, generalSettings, firmware, inputName, rawSourceFilteredModel, rawSwitchFilteredModel);
if (g->exec()) { if (g->exec()) {
model->expoData[index] = ed; model->expoData[index] = ed;
if (firmware->getCapability(VirtualInputs)) if (firmware->getCapability(VirtualInputs))
strncpy(model->inputNames[ed.chn], inputName.toLatin1().data(), INPUT_NAME_LEN); strncpy(model->inputNames[ed.chn], inputName.toLatin1().data(), INPUT_NAME_LEN);
update(); update();
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
else { else {
@@ -253,7 +251,7 @@ void InputsPanel::exposDelete(bool prompt)
exposDeleteList(list, prompt); exposDeleteList(list, prompt);
update(); update();
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
@@ -328,7 +326,7 @@ void InputsPanel::pasteExpoMimeData(const QMimeData * mimeData, int destIdx)
} }
update(); update();
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
} }
@@ -497,7 +495,7 @@ void InputsPanel::moveExpoList(bool down)
} }
if (mod) { if (mod) {
update(); update();
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
setSelectedByExpoList(highlightList); setSelectedByExpoList(highlightList);
@@ -537,7 +535,7 @@ void InputsPanel::clearExpos()
model->updateAllReferences(ModelData::REF_UPD_TYPE_INPUT, ModelData::REF_UPD_ACT_CLEAR, i); model->updateAllReferences(ModelData::REF_UPD_TYPE_INPUT, ModelData::REF_UPD_ACT_CLEAR, i);
} }
update(); update();
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
} }
@@ -586,7 +584,7 @@ void InputsPanel::cmInputClear()
} }
model->updateAllReferences(ModelData::REF_UPD_TYPE_INPUT, ModelData::REF_UPD_ACT_CLEAR, inputIdx); model->updateAllReferences(ModelData::REF_UPD_TYPE_INPUT, ModelData::REF_UPD_ACT_CLEAR, inputIdx);
update(); update();
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
@@ -610,7 +608,7 @@ void InputsPanel::cmInputDelete()
model->updateAllReferences(ModelData::REF_UPD_TYPE_INPUT, ModelData::REF_UPD_ACT_SHIFT, inputIdx, 0, -1); model->updateAllReferences(ModelData::REF_UPD_TYPE_INPUT, ModelData::REF_UPD_ACT_SHIFT, inputIdx, 0, -1);
update(); update();
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
@@ -629,7 +627,7 @@ void InputsPanel::cmInputInsert()
model->updateAllReferences(ModelData::REF_UPD_TYPE_INPUT, ModelData::REF_UPD_ACT_SHIFT, inputIdx, 0, 1); model->updateAllReferences(ModelData::REF_UPD_TYPE_INPUT, ModelData::REF_UPD_ACT_SHIFT, inputIdx, 0, 1);
update(); update();
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
@@ -691,7 +689,7 @@ void InputsPanel::cmInputSwapData(int idx1, int idx2)
model->updateAllReferences(ModelData::REF_UPD_TYPE_INPUT, ModelData::REF_UPD_ACT_SWAP, idx1, idx2); model->updateAllReferences(ModelData::REF_UPD_TYPE_INPUT, ModelData::REF_UPD_ACT_SWAP, idx1, idx2);
update(); update();
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
@@ -735,4 +733,10 @@ void InputsPanel::onModelDataAboutToBeUpdated()
void InputsPanel::onModelDataUpdateComplete() void InputsPanel::onModelDataUpdateComplete()
{ {
update(); update();
lock = false;
}
void InputsPanel::updateItemModels()
{
commonItemModels->update(CommonItemModels::RMO_INPUTS);
} }
+6 -9
View File
@@ -25,8 +25,7 @@
#include "mixerslistwidget.h" #include "mixerslistwidget.h"
#include "modelprinter.h" #include "modelprinter.h"
class RawSourceItemModel; class CommonItemModels;
class RawSwitchItemModel;
class RawItemFilteredModel; class RawItemFilteredModel;
constexpr char MIMETYPE_EXPO[] = "application/x-companion-expo"; constexpr char MIMETYPE_EXPO[] = "application/x-companion-expo";
@@ -36,8 +35,7 @@ class InputsPanel : public ModelPanel
Q_OBJECT Q_OBJECT
public: public:
InputsPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, InputsPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels);
RawSourceItemModel * rawSourceItemModel, RawSwitchItemModel * rawSwitchItemModel);
virtual ~InputsPanel(); virtual ~InputsPanel();
virtual void update(); virtual void update();
@@ -67,9 +65,6 @@ class InputsPanel : public ModelPanel
void onModelDataAboutToBeUpdated(); void onModelDataAboutToBeUpdated();
void onModelDataUpdateComplete(); void onModelDataUpdateComplete();
signals:
void updateDataModels();
private: private:
bool expoInserted; bool expoInserted;
MixersListWidget *ExposlistWidget; MixersListWidget *ExposlistWidget;
@@ -77,8 +72,9 @@ class InputsPanel : public ModelPanel
ModelPrinter modelPrinter; ModelPrinter modelPrinter;
int selectedIdx; int selectedIdx;
int inputIdx; int inputIdx;
RawItemFilteredModel *rawSourceModel; CommonItemModels * commonItemModels;
RawItemFilteredModel *rawSwitchModel; RawItemFilteredModel *rawSourceFilteredModel;
RawItemFilteredModel *rawSwitchFilteredModel;
int getExpoIndex(unsigned int dch); int getExpoIndex(unsigned int dch);
bool gm_insertExpo(int idx); bool gm_insertExpo(int idx);
@@ -99,6 +95,7 @@ class InputsPanel : public ModelPanel
bool isExpoIndex(const int index); bool isExpoIndex(const int index);
int getIndexFromSelected(); int getIndexFromSelected();
int getInputIndexFromSelected(); int getInputIndexFromSelected();
void updateItemModels();
}; };
#endif // _INPUTS_H_ #endif // _INPUTS_H_
+34 -32
View File
@@ -24,20 +24,20 @@
#include <TimerEdit> #include <TimerEdit>
LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels):
RawSourceItemModel * rawSourceItemModel, RawSwitchItemModel * rawSwitchItemModel):
ModelPanel(parent, model, generalSettings, firmware), ModelPanel(parent, model, generalSettings, firmware),
commonItemModels(commonItemModels),
selectedIndex(0), selectedIndex(0),
modelsUpdateCnt(0) modelsUpdateCnt(0)
{ {
rawSwitchModel = new RawItemFilteredModel(rawSwitchItemModel, RawSwitch::LogicalSwitchesContext); rawSwitchFilteredModel = new RawItemFilteredModel(commonItemModels->rawSwitchItemModel(), RawSwitch::LogicalSwitchesContext, this);
connect(rawSwitchModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &LogicalSwitchesPanel::onModelDataAboutToBeUpdated); connect(rawSwitchFilteredModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &LogicalSwitchesPanel::onModelDataAboutToBeUpdated);
connect(rawSwitchModel, &RawItemFilteredModel::dataUpdateComplete, this, &LogicalSwitchesPanel::onModelDataUpdateComplete); connect(rawSwitchFilteredModel, &RawItemFilteredModel::dataUpdateComplete, this, &LogicalSwitchesPanel::onModelDataUpdateComplete);
const int srcGroups = firmware->getCapability(GvarsInCS) ? 0 : (RawSource::AllSourceGroups & ~RawSource::GVarsGroup); const int srcGroups = firmware->getCapability(GvarsInCS) ? 0 : (RawSource::AllSourceGroups & ~RawSource::GVarsGroup);
rawSourceModel = new RawItemFilteredModel(rawSourceItemModel, srcGroups, this); rawSourceFilteredModel = new RawItemFilteredModel(commonItemModels->rawSourceItemModel(), srcGroups, this);
connect(rawSourceModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &LogicalSwitchesPanel::onModelDataAboutToBeUpdated); connect(rawSourceFilteredModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &LogicalSwitchesPanel::onModelDataAboutToBeUpdated);
connect(rawSourceModel, &RawItemFilteredModel::dataUpdateComplete, this, &LogicalSwitchesPanel::onModelDataUpdateComplete); connect(rawSourceFilteredModel, &RawItemFilteredModel::dataUpdateComplete, this, &LogicalSwitchesPanel::onModelDataUpdateComplete);
lsCapability = firmware->getCapability(LogicalSwitches); lsCapability = firmware->getCapability(LogicalSwitches);
lsCapabilityExt = firmware->getCapability(LogicalSwitchesExt); lsCapabilityExt = firmware->getCapability(LogicalSwitchesExt);
@@ -124,7 +124,7 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model,
// AND // AND
cbAndSwitch[i] = new QComboBox(this); cbAndSwitch[i] = new QComboBox(this);
cbAndSwitch[i]->setProperty("index", i); cbAndSwitch[i]->setProperty("index", i);
cbAndSwitch[i]->setModel(rawSwitchModel); cbAndSwitch[i]->setModel(rawSwitchFilteredModel);
cbAndSwitch[i]->setVisible(true); cbAndSwitch[i]->setVisible(true);
connect(cbAndSwitch[i], SIGNAL(currentIndexChanged(int)), this, SLOT(onAndSwitchChanged(int))); connect(cbAndSwitch[i], SIGNAL(currentIndexChanged(int)), this, SLOT(onAndSwitchChanged(int)));
tableLayout->addWidget(i, 4, cbAndSwitch[i]); tableLayout->addWidget(i, 4, cbAndSwitch[i]);
@@ -161,8 +161,6 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model,
LogicalSwitchesPanel::~LogicalSwitchesPanel() LogicalSwitchesPanel::~LogicalSwitchesPanel()
{ {
delete rawSourceModel;
delete rawSwitchModel;
} }
void LogicalSwitchesPanel::onFunctionChanged() void LogicalSwitchesPanel::onFunctionChanged()
@@ -174,7 +172,6 @@ void LogicalSwitchesPanel::onFunctionChanged()
if (model->logicalSw[i].func == newFunc) if (model->logicalSw[i].func == newFunc)
return; return;
unsigned oldFunc = model->logicalSw[i].func;
CSFunctionFamily oldFuncFamily = model->logicalSw[i].getFunctionFamily(); CSFunctionFamily oldFuncFamily = model->logicalSw[i].getFunctionFamily();
model->logicalSw[i].func = newFunc; model->logicalSw[i].func = newFunc;
CSFunctionFamily newFuncFamily = model->logicalSw[i].getFunctionFamily(); CSFunctionFamily newFuncFamily = model->logicalSw[i].getFunctionFamily();
@@ -191,10 +188,7 @@ void LogicalSwitchesPanel::onFunctionChanged()
} }
} }
if (oldFunc == LS_FN_OFF || newFunc == LS_FN_OFF) updateLine(i);
updateCBLists();
else
updateLine(i);
emit modified(); emit modified();
} }
} }
@@ -345,6 +339,7 @@ void LogicalSwitchesPanel::updateTimerParam(QDoubleSpinBox *sb, int timer, doubl
void LogicalSwitchesPanel::updateLine(int i) void LogicalSwitchesPanel::updateLine(int i)
{ {
const bool savelock = lock;
lock = true; lock = true;
unsigned int mask = 0; unsigned int mask = 0;
@@ -362,7 +357,7 @@ void LogicalSwitchesPanel::updateLine(int i)
RawSource source = RawSource(model->logicalSw[i].val1); RawSource source = RawSource(model->logicalSw[i].val1);
RawSourceRange range = source.getRange(model, generalSettings, model->logicalSw[i].getRangeFlags()); RawSourceRange range = source.getRange(model, generalSettings, model->logicalSw[i].getRangeFlags());
double value = range.step * model->logicalSw[i].val2 + range.offset; /* TODO+source.getRawOffset(model)*/ double value = range.step * model->logicalSw[i].val2 + range.offset; /* TODO+source.getRawOffset(model)*/
cbSource1[i]->setModel(rawSourceModel); cbSource1[i]->setModel(rawSourceFilteredModel);
cbSource1[i]->setCurrentIndex(cbSource1[i]->findData(source.toValue())); cbSource1[i]->setCurrentIndex(cbSource1[i]->findData(source.toValue()));
if (source.isTimeBased()) { if (source.isTimeBased()) {
mask |= VALUE_TO_VISIBLE; mask |= VALUE_TO_VISIBLE;
@@ -391,16 +386,16 @@ void LogicalSwitchesPanel::updateLine(int i)
case LS_FAMILY_STICKY: // no break case LS_FAMILY_STICKY: // no break
case LS_FAMILY_VBOOL: case LS_FAMILY_VBOOL:
mask |= SOURCE1_VISIBLE | SOURCE2_VISIBLE; mask |= SOURCE1_VISIBLE | SOURCE2_VISIBLE;
cbSource1[i]->setModel(rawSwitchModel); cbSource1[i]->setModel(rawSwitchFilteredModel);
cbSource1[i]->setCurrentIndex(cbSource1[i]->findData(model->logicalSw[i].val1)); cbSource1[i]->setCurrentIndex(cbSource1[i]->findData(model->logicalSw[i].val1));
cbSource2[i]->setModel(rawSwitchModel); cbSource2[i]->setModel(rawSwitchFilteredModel);
cbSource2[i]->setCurrentIndex(cbSource2[i]->findData(model->logicalSw[i].val2)); cbSource2[i]->setCurrentIndex(cbSource2[i]->findData(model->logicalSw[i].val2));
break; break;
case LS_FAMILY_EDGE: case LS_FAMILY_EDGE:
mask |= SOURCE1_VISIBLE | VALUE2_VISIBLE | VALUE3_VISIBLE; mask |= SOURCE1_VISIBLE | VALUE2_VISIBLE | VALUE3_VISIBLE;
mask &= ~DELAY_ENABLED; mask &= ~DELAY_ENABLED;
cbSource1[i]->setModel(rawSwitchModel); cbSource1[i]->setModel(rawSwitchFilteredModel);
cbSource1[i]->setCurrentIndex(cbSource1[i]->findData(model->logicalSw[i].val1)); cbSource1[i]->setCurrentIndex(cbSource1[i]->findData(model->logicalSw[i].val1));
updateTimerParam(dsbOffset[i], model->logicalSw[i].val2, 0.0); updateTimerParam(dsbOffset[i], model->logicalSw[i].val2, 0.0);
updateTimerParam(dsbOffset2[i], model->logicalSw[i].val2 + model->logicalSw[i].val3, ValToTim(TimToVal(dsbOffset[i]->value()) - 1)); updateTimerParam(dsbOffset2[i], model->logicalSw[i].val2 + model->logicalSw[i].val3, ValToTim(TimToVal(dsbOffset[i]->value()) - 1));
@@ -409,9 +404,9 @@ void LogicalSwitchesPanel::updateLine(int i)
case LS_FAMILY_VCOMP: case LS_FAMILY_VCOMP:
mask |= SOURCE1_VISIBLE | SOURCE2_VISIBLE; mask |= SOURCE1_VISIBLE | SOURCE2_VISIBLE;
cbSource1[i]->setModel(rawSourceModel); cbSource1[i]->setModel(rawSourceFilteredModel);
cbSource1[i]->setCurrentIndex(cbSource1[i]->findData(model->logicalSw[i].val1)); cbSource1[i]->setCurrentIndex(cbSource1[i]->findData(model->logicalSw[i].val1));
cbSource2[i]->setModel(rawSourceModel); cbSource2[i]->setModel(rawSourceFilteredModel);
cbSource2[i]->setCurrentIndex(cbSource2[i]->findData(model->logicalSw[i].val2)); cbSource2[i]->setCurrentIndex(cbSource2[i]->findData(model->logicalSw[i].val2));
break; break;
@@ -439,7 +434,7 @@ void LogicalSwitchesPanel::updateLine(int i)
dsbDelay[i]->setValue(model->logicalSw[i].delay / 10.0); dsbDelay[i]->setValue(model->logicalSw[i].delay / 10.0);
} }
lock = false; lock = savelock;
} }
void LogicalSwitchesPanel::populateFunctionCB(QComboBox *b) void LogicalSwitchesPanel::populateFunctionCB(QComboBox *b)
@@ -491,6 +486,7 @@ void LogicalSwitchesPanel::cmPaste()
QByteArray data; QByteArray data;
if (hasClipboardData(&data)) { if (hasClipboardData(&data)) {
memcpy(&model->logicalSw[selectedIndex], data.constData(), sizeof(LogicalSwitchData)); memcpy(&model->logicalSw[selectedIndex], data.constData(), sizeof(LogicalSwitchData));
updateLine(selectedIndex);
updateCBLists(); updateCBLists();
emit modified(); emit modified();
} }
@@ -505,6 +501,7 @@ void LogicalSwitchesPanel::cmDelete()
model->logicalSw[lsCapability - 1].clear(); model->logicalSw[lsCapability - 1].clear();
model->updateAllReferences(ModelData::REF_UPD_TYPE_LOGICAL_SWITCH, ModelData::REF_UPD_ACT_SHIFT, selectedIndex, 0, -1); model->updateAllReferences(ModelData::REF_UPD_TYPE_LOGICAL_SWITCH, ModelData::REF_UPD_ACT_SHIFT, selectedIndex, 0, -1);
update();
updateCBLists(); updateCBLists();
emit modified(); emit modified();
} }
@@ -515,7 +512,7 @@ void LogicalSwitchesPanel::cmCopy()
data.append((char*)&model->logicalSw[selectedIndex], sizeof(LogicalSwitchData)); data.append((char*)&model->logicalSw[selectedIndex], sizeof(LogicalSwitchData));
QMimeData *mimeData = new QMimeData; QMimeData *mimeData = new QMimeData;
mimeData->setData(MIMETYPE_LOGICAL_SWITCH, data); mimeData->setData(MIMETYPE_LOGICAL_SWITCH, data);
QApplication::clipboard()->setMimeData(mimeData,QClipboard::Clipboard); QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard);
} }
void LogicalSwitchesPanel::cmCut() void LogicalSwitchesPanel::cmCut()
@@ -526,7 +523,6 @@ void LogicalSwitchesPanel::cmCut()
cmClear(false); cmClear(false);
} }
// TODO make something generic here!
void LogicalSwitchesPanel::onCustomContextMenuRequested(QPoint pos) void LogicalSwitchesPanel::onCustomContextMenuRequested(QPoint pos)
{ {
QLabel *label = (QLabel *)sender(); QLabel *label = (QLabel *)sender();
@@ -595,6 +591,7 @@ void LogicalSwitchesPanel::cmClear(bool prompt)
model->logicalSw[selectedIndex].clear(); model->logicalSw[selectedIndex].clear();
model->updateAllReferences(ModelData::REF_UPD_TYPE_LOGICAL_SWITCH, ModelData::REF_UPD_ACT_CLEAR, selectedIndex); model->updateAllReferences(ModelData::REF_UPD_TYPE_LOGICAL_SWITCH, ModelData::REF_UPD_ACT_CLEAR, selectedIndex);
updateLine(selectedIndex);
updateCBLists(); updateCBLists();
emit modified(); emit modified();
} }
@@ -608,6 +605,7 @@ void LogicalSwitchesPanel::cmClearAll()
model->logicalSw[i].clear(); model->logicalSw[i].clear();
model->updateAllReferences(ModelData::REF_UPD_TYPE_LOGICAL_SWITCH, ModelData::REF_UPD_ACT_CLEAR, i); model->updateAllReferences(ModelData::REF_UPD_TYPE_LOGICAL_SWITCH, ModelData::REF_UPD_ACT_CLEAR, i);
} }
update();
updateCBLists(); updateCBLists();
emit modified(); emit modified();
} }
@@ -617,6 +615,7 @@ void LogicalSwitchesPanel::cmInsert()
memmove(&model->logicalSw[selectedIndex + 1], &model->logicalSw[selectedIndex], (CPN_MAX_LOGICAL_SWITCHES - (selectedIndex + 1)) * sizeof(LogicalSwitchData)); memmove(&model->logicalSw[selectedIndex + 1], &model->logicalSw[selectedIndex], (CPN_MAX_LOGICAL_SWITCHES - (selectedIndex + 1)) * sizeof(LogicalSwitchData));
model->logicalSw[selectedIndex].clear(); model->logicalSw[selectedIndex].clear();
model->updateAllReferences(ModelData::REF_UPD_TYPE_LOGICAL_SWITCH, ModelData::REF_UPD_ACT_SHIFT, selectedIndex, 0, 1); model->updateAllReferences(ModelData::REF_UPD_TYPE_LOGICAL_SWITCH, ModelData::REF_UPD_ACT_SHIFT, selectedIndex, 0, 1);
update();
updateCBLists(); updateCBLists();
emit modified(); emit modified();
} }
@@ -630,6 +629,8 @@ void LogicalSwitchesPanel::swapData(int idx1, int idx2)
memcpy(lsw2, lsw1, sizeof(LogicalSwitchData)); memcpy(lsw2, lsw1, sizeof(LogicalSwitchData));
memcpy(lsw1, &lstmp, sizeof(LogicalSwitchData)); memcpy(lsw1, &lstmp, sizeof(LogicalSwitchData));
model->updateAllReferences(ModelData::REF_UPD_TYPE_LOGICAL_SWITCH, ModelData::REF_UPD_ACT_SWAP, idx1, idx2); model->updateAllReferences(ModelData::REF_UPD_TYPE_LOGICAL_SWITCH, ModelData::REF_UPD_ACT_SWAP, idx1, idx2);
updateLine(idx1);
updateLine(idx2);
updateCBLists(); updateCBLists();
emit modified(); emit modified();
} }
@@ -642,15 +643,14 @@ void LogicalSwitchesPanel::updateCBLists()
// So this workaround gives time for other events to be processed before refreshing // So this workaround gives time for other events to be processed before refreshing
// Not sure if this an OS related issue or a QT bug in QT 5.7 (and higher?) // Not sure if this an OS related issue or a QT bug in QT 5.7 (and higher?)
// The delay is abitary // The delay is abitary
QTimer::singleShot(1000, this, &LogicalSwitchesPanel::updateDataModels); //QTimer::singleShot(1000, this, &LogicalSwitchesPanel::updateItemModels);
updateItemModels();
} }
void LogicalSwitchesPanel::updateDataModels() void LogicalSwitchesPanel::updateItemModels()
{ {
// This is inconsistent but needed as part of the workaround lock = true;
//emit updateCBLists(); adds to the event stack so call direct commonItemModels->update(CommonItemModels::RMO_LOGICAL_SWITCHES);
rawSourceModel->update();
rawSwitchModel->update();
} }
void LogicalSwitchesPanel::onModelDataAboutToBeUpdated() void LogicalSwitchesPanel::onModelDataAboutToBeUpdated()
@@ -662,6 +662,8 @@ void LogicalSwitchesPanel::onModelDataAboutToBeUpdated()
void LogicalSwitchesPanel::onModelDataUpdateComplete() void LogicalSwitchesPanel::onModelDataUpdateComplete()
{ {
modelsUpdateCnt--; modelsUpdateCnt--;
if (modelsUpdateCnt < 1) if (modelsUpdateCnt < 1) {
update(); update();
lock = false;
}
} }
+6 -7
View File
@@ -24,8 +24,7 @@
#include "modeledit.h" #include "modeledit.h"
#include "radiodata.h" #include "radiodata.h"
class RawSourceItemModel; class CommonItemModels;
class RawSwitchItemModel;
class RawItemFilteredModel; class RawItemFilteredModel;
class TimerEdit; class TimerEdit;
@@ -36,8 +35,7 @@ class LogicalSwitchesPanel : public ModelPanel
Q_OBJECT Q_OBJECT
public: public:
LogicalSwitchesPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, LogicalSwitchesPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels);
RawSourceItemModel * rawSourceItemModel, RawSwitchItemModel * rawSwitchItemModel);
virtual ~LogicalSwitchesPanel(); virtual ~LogicalSwitchesPanel();
virtual void update(); virtual void update();
@@ -76,8 +74,9 @@ class LogicalSwitchesPanel : public ModelPanel
QDoubleSpinBox * dsbDelay[CPN_MAX_LOGICAL_SWITCHES]; QDoubleSpinBox * dsbDelay[CPN_MAX_LOGICAL_SWITCHES];
QComboBox * cbSource1[CPN_MAX_LOGICAL_SWITCHES]; QComboBox * cbSource1[CPN_MAX_LOGICAL_SWITCHES];
QComboBox * cbSource2[CPN_MAX_LOGICAL_SWITCHES]; QComboBox * cbSource2[CPN_MAX_LOGICAL_SWITCHES];
RawItemFilteredModel * rawSwitchModel; CommonItemModels * commonItemModels;
RawItemFilteredModel * rawSourceModel; RawItemFilteredModel * rawSwitchFilteredModel;
RawItemFilteredModel * rawSourceFilteredModel;
int selectedIndex; int selectedIndex;
void populateFunctionCB(QComboBox *b); void populateFunctionCB(QComboBox *b);
void updateTimerParam(QDoubleSpinBox *sb, int timer, double minimum=0); void updateTimerParam(QDoubleSpinBox *sb, int timer, double minimum=0);
@@ -90,7 +89,7 @@ class LogicalSwitchesPanel : public ModelPanel
bool moveUpAllowed() const; bool moveUpAllowed() const;
int modelsUpdateCnt; int modelsUpdateCnt;
void updateCBLists(); void updateCBLists();
void updateDataModels(); void updateItemModels();
}; };
#endif // _LOGICALSWITCHES_H_ #endif // _LOGICALSWITCHES_H_
+1 -1
View File
@@ -148,10 +148,10 @@ MixerDialog::MixerDialog(QWidget *parent, ModelData & model, MixData * mixdata,
MixerDialog::~MixerDialog() MixerDialog::~MixerDialog()
{ {
delete ui;
delete gvWeightGroup; delete gvWeightGroup;
delete gvOffsetGroup; delete gvOffsetGroup;
delete curveGroup; delete curveGroup;
delete ui;
} }
void MixerDialog::changeEvent(QEvent *e) void MixerDialog::changeEvent(QEvent *e)
+11 -12
View File
@@ -22,20 +22,20 @@
#include "helpers.h" #include "helpers.h"
#include "rawitemfilteredmodel.h" #include "rawitemfilteredmodel.h"
MixesPanel::MixesPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, MixesPanel::MixesPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware,CommonItemModels * commonItemModels):
RawSourceItemModel * rawSourceItemModel, RawSwitchItemModel * rawSwitchItemModel):
ModelPanel(parent, model, generalSettings, firmware), ModelPanel(parent, model, generalSettings, firmware),
mixInserted(false), mixInserted(false),
highlightedSource(0), highlightedSource(0),
modelPrinter(firmware, generalSettings, model) modelPrinter(firmware, generalSettings, model),
commonItemModels(commonItemModels)
{ {
rawSourceModel = new RawItemFilteredModel(rawSourceItemModel, ((RawSource::InputSourceGroups | RawSource::ScriptsGroup) & ~ RawSource::NoneGroup), this); rawSourceFilteredModel = new RawItemFilteredModel(commonItemModels->rawSourceItemModel(), ((RawSource::InputSourceGroups | RawSource::ScriptsGroup) & ~ RawSource::NoneGroup), this);
connect(rawSourceModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &MixesPanel::onModelDataAboutToBeUpdated); connect(rawSourceFilteredModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &MixesPanel::onModelDataAboutToBeUpdated);
connect(rawSourceModel, &RawItemFilteredModel::dataUpdateComplete, this, &MixesPanel::onModelDataUpdateComplete); connect(rawSourceFilteredModel, &RawItemFilteredModel::dataUpdateComplete, this, &MixesPanel::onModelDataUpdateComplete);
rawSwitchModel = new RawItemFilteredModel(rawSwitchItemModel, RawSwitch::MixesContext, this); rawSwitchFilteredModel = new RawItemFilteredModel(commonItemModels->rawSwitchItemModel(), RawSwitch::MixesContext, this);
connect(rawSwitchModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &MixesPanel::onModelDataAboutToBeUpdated); connect(rawSwitchFilteredModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &MixesPanel::onModelDataAboutToBeUpdated);
connect(rawSwitchModel, &RawItemFilteredModel::dataUpdateComplete, this, &MixesPanel::onModelDataUpdateComplete); connect(rawSwitchFilteredModel, &RawItemFilteredModel::dataUpdateComplete, this, &MixesPanel::onModelDataUpdateComplete);
QGridLayout * mixesLayout = new QGridLayout(this); QGridLayout * mixesLayout = new QGridLayout(this);
@@ -70,8 +70,6 @@ MixesPanel::MixesPanel(QWidget *parent, ModelData & model, GeneralSettings & gen
MixesPanel::~MixesPanel() MixesPanel::~MixesPanel()
{ {
delete rawSourceModel;
delete rawSwitchModel;
} }
void MixesPanel::update() void MixesPanel::update()
@@ -187,7 +185,7 @@ void MixesPanel::gm_openMix(int index)
MixData mixd(model->mixData[index]); MixData mixd(model->mixData[index]);
MixerDialog *g = new MixerDialog(this, *model, &mixd, generalSettings, firmware, rawSourceModel, rawSwitchModel); MixerDialog *g = new MixerDialog(this, *model, &mixd, generalSettings, firmware, rawSourceFilteredModel, rawSwitchFilteredModel);
if(g->exec()) { if(g->exec()) {
model->mixData[index] = mixd; model->mixData[index] = mixd;
emit modified(); emit modified();
@@ -550,4 +548,5 @@ void MixesPanel::onModelDataAboutToBeUpdated()
void MixesPanel::onModelDataUpdateComplete() void MixesPanel::onModelDataUpdateComplete()
{ {
update(); update();
lock = false;
} }
+5 -6
View File
@@ -26,8 +26,7 @@
#include "mixerdialog.h" #include "mixerdialog.h"
#include "modelprinter.h" #include "modelprinter.h"
class RawSourceItemModel; class CommonItemModels;
class RawSwitchItemModel;
class RawItemFilteredModel; class RawItemFilteredModel;
class MixesPanel : public ModelPanel class MixesPanel : public ModelPanel
@@ -35,8 +34,7 @@ class MixesPanel : public ModelPanel
Q_OBJECT Q_OBJECT
public: public:
MixesPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, MixesPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels);
RawSourceItemModel * rawSourceItemModel, RawSwitchItemModel * rawSwitchItemModel);
virtual ~MixesPanel(); virtual ~MixesPanel();
virtual void update(); virtual void update();
@@ -70,8 +68,9 @@ class MixesPanel : public ModelPanel
bool mixInserted; bool mixInserted;
unsigned int highlightedSource; unsigned int highlightedSource;
ModelPrinter modelPrinter; ModelPrinter modelPrinter;
RawItemFilteredModel *rawSourceModel; CommonItemModels * commonItemModels;
RawItemFilteredModel *rawSwitchModel; RawItemFilteredModel *rawSourceFilteredModel;
RawItemFilteredModel *rawSwitchFilteredModel;
int getMixerIndex(unsigned int dch); int getMixerIndex(unsigned int dch);
bool gm_insertMix(int idx); bool gm_insertMix(int idx);
+11 -35
View File
@@ -53,89 +53,65 @@ ModelEdit::ModelEdit(QWidget * parent, RadioData & radioData, int modelId, Firmw
GeneralSettings &generalSettings = radioData.generalSettings; GeneralSettings &generalSettings = radioData.generalSettings;
ModelData &model = radioData.models[modelId]; ModelData &model = radioData.models[modelId];
/* commonItemModels = new CommonItemModels(&generalSettings, &model, this);
Create reusable model specific ui datamodels here and pass pointers as needed
They should be referenced through filters in each use case
Code that updates the source for one or more ui datamodels should emit a SIGNAL that can be trapped (see below) and the datamodels refreshed
WARNING: beware of looping signals and slots and unnecessary data field updates from refreshing datamodels
where practical make signals granular to only those fields that affect datamodels thus needing to be refreshed
*/
rawSourceModel = new RawSourceItemModel(&generalSettings, &model, this);
rawSwitchModel = new RawSwitchItemModel(&generalSettings, &model, this);
curveModel = new CurveItemModel(&generalSettings, &model, this);
s1.report("Init"); s1.report("Init");
SetupPanel * setupPanel = new SetupPanel(this, model, generalSettings, firmware, rawSwitchModel); SetupPanel * setupPanel = new SetupPanel(this, model, generalSettings, firmware, commonItemModels);
addTab(setupPanel, tr("Setup")); addTab(setupPanel, tr("Setup"));
s1.report("Setup"); s1.report("Setup");
if (firmware->getCapability(Heli)) { if (firmware->getCapability(Heli)) {
HeliPanel * heliPanel = new HeliPanel(this, model, generalSettings, firmware, rawSourceModel); HeliPanel * heliPanel = new HeliPanel(this, model, generalSettings, firmware, commonItemModels);
addTab(heliPanel, tr("Heli")); addTab(heliPanel, tr("Heli"));
s1.report("Heli"); s1.report("Heli");
} }
FlightModesPanel * flightModesPanel = new FlightModesPanel(this, model, generalSettings, firmware, rawSwitchModel); FlightModesPanel * flightModesPanel = new FlightModesPanel(this, model, generalSettings, firmware, commonItemModels);
addTab(flightModesPanel, tr("Flight Modes")); addTab(flightModesPanel, tr("Flight Modes"));
s1.report("Flight Modes"); s1.report("Flight Modes");
InputsPanel * inputsPanel = new InputsPanel(this, model, generalSettings, firmware, rawSourceModel, rawSwitchModel); InputsPanel * inputsPanel = new InputsPanel(this, model, generalSettings, firmware, commonItemModels);
addTab(inputsPanel, tr("Inputs")); addTab(inputsPanel, tr("Inputs"));
s1.report("Inputs"); s1.report("Inputs");
MixesPanel * mixesPanel = new MixesPanel(this, model, generalSettings, firmware, rawSourceModel, rawSwitchModel); MixesPanel * mixesPanel = new MixesPanel(this, model, generalSettings, firmware, commonItemModels);
addTab(mixesPanel, tr("Mixes")); addTab(mixesPanel, tr("Mixes"));
s1.report("Mixes"); s1.report("Mixes");
ChannelsPanel * channelsPanel = new ChannelsPanel(this, model, generalSettings, firmware, curveModel); ChannelsPanel * channelsPanel = new ChannelsPanel(this, model, generalSettings, firmware, commonItemModels);
addTab(channelsPanel, tr("Outputs")); addTab(channelsPanel, tr("Outputs"));
s1.report("Outputs"); s1.report("Outputs");
CurvesPanel * curvesPanel = new CurvesPanel(this, model, generalSettings, firmware); CurvesPanel * curvesPanel = new CurvesPanel(this, model, generalSettings, firmware, commonItemModels);
addTab(curvesPanel, tr("Curves")); addTab(curvesPanel, tr("Curves"));
s1.report("Curves"); s1.report("Curves");
LogicalSwitchesPanel * logicalSwitchesPanel = new LogicalSwitchesPanel(this, model, generalSettings, firmware, rawSourceModel, rawSwitchModel); LogicalSwitchesPanel * logicalSwitchesPanel = new LogicalSwitchesPanel(this, model, generalSettings, firmware, commonItemModels);
addTab(logicalSwitchesPanel, tr("Logical Switches")); addTab(logicalSwitchesPanel, tr("Logical Switches"));
s1.report("Logical Switches"); s1.report("Logical Switches");
CustomFunctionsPanel * customFunctionsPanel = new CustomFunctionsPanel(this, &model, generalSettings, firmware, rawSourceModel, rawSwitchModel); CustomFunctionsPanel * customFunctionsPanel = new CustomFunctionsPanel(this, &model, generalSettings, firmware, commonItemModels);
addTab(customFunctionsPanel, tr("Special Functions")); addTab(customFunctionsPanel, tr("Special Functions"));
s1.report("Special Functions"); s1.report("Special Functions");
if (firmware->getCapability(Telemetry)) { if (firmware->getCapability(Telemetry)) {
TelemetryPanel * telemetryPanel = new TelemetryPanel(this, model, generalSettings, firmware, rawSourceModel); TelemetryPanel * telemetryPanel = new TelemetryPanel(this, model, generalSettings, firmware, commonItemModels);
addTab(telemetryPanel, tr("Telemetry")); addTab(telemetryPanel, tr("Telemetry"));
connect(telemetryPanel, &TelemetryPanel::updateDataModels, rawSourceModel, &RawSourceItemModel::update);
s1.report("Telemetry"); s1.report("Telemetry");
} }
connect(setupPanel, &SetupPanel::extendedLimitsToggled, channelsPanel, &ChannelsPanel::refreshExtendedLimits); connect(setupPanel, &SetupPanel::extendedLimitsToggled, channelsPanel, &ChannelsPanel::refreshExtendedLimits);
connect(setupPanel, &SetupPanel::updateDataModels, rawSourceModel, &RawSourceItemModel::update);
connect(flightModesPanel, &FlightModesPanel::updateDataModels, rawSourceModel, &RawSourceItemModel::update);
connect(flightModesPanel, &FlightModesPanel::updateDataModels, rawSwitchModel, &RawSwitchItemModel::update);
connect(inputsPanel, &InputsPanel::updateDataModels, rawSourceModel, &RawSourceItemModel::update);
connect(channelsPanel, &ChannelsPanel::updateDataModels, rawSourceModel, &RawSourceItemModel::update);
connect(curvesPanel, &CurvesPanel::updateDataModels, curveModel, &CurveItemModel::update);
connect(ui->tabWidget, &QTabWidget::currentChanged, this, &ModelEdit::onTabIndexChanged); connect(ui->tabWidget, &QTabWidget::currentChanged, this, &ModelEdit::onTabIndexChanged);
connect(ui->pushButton, &QPushButton::clicked, this, &ModelEdit::launchSimulation); connect(ui->pushButton, &QPushButton::clicked, this, &ModelEdit::launchSimulation);
onTabIndexChanged(ui->tabWidget->currentIndex()); // make sure to trigger update on default tab panel onTabIndexChanged(ui->tabWidget->currentIndex()); // make sure to trigger update on default tab panel
s1.report("Signals and Slots");
gStopwatch.report("ModelEdit end constructor"); gStopwatch.report("ModelEdit end constructor");
} }
ModelEdit::~ModelEdit() ModelEdit::~ModelEdit()
{ {
delete rawSourceModel;
delete rawSwitchModel;
delete curveModel;
delete ui; delete ui;
} }
+2 -6
View File
@@ -25,9 +25,7 @@
#include "genericpanel.h" #include "genericpanel.h"
class RadioData; class RadioData;
class RawSourceItemModel; class CommonItemModels;
class RawSwitchItemModel;
class CurveItemModel;
namespace Ui { namespace Ui {
class ModelEdit; class ModelEdit;
@@ -65,9 +63,7 @@ class ModelEdit : public QDialog
RadioData & radioData; RadioData & radioData;
Firmware * firmware; Firmware * firmware;
QVector<GenericPanel *> panels; QVector<GenericPanel *> panels;
RawSourceItemModel *rawSourceModel; CommonItemModels * commonItemModels;
RawSwitchItemModel *rawSwitchModel;
CurveItemModel *curveModel;
void addTab(GenericPanel *panel, QString text); void addTab(GenericPanel *panel, QString text);
void launchSimulation(); void launchSimulation();
+73 -68
View File
@@ -31,15 +31,14 @@
#include <QDir> #include <QDir>
TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware, QWidget * prevFocus, RawItemFilteredModel * rawSwitchModel): TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware, QWidget * prevFocus, RawItemFilteredModel * rawSwitchFilteredModel):
ModelPanel(parent, model, generalSettings, firmware), ModelPanel(parent, model, generalSettings, firmware),
timer(timer), timer(timer),
ui(new Ui::Timer) ui(new Ui::Timer)
{ {
ui->setupUi(this); ui->setupUi(this);
connect(rawSwitchModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &TimerPanel::onModelDataAboutToBeUpdated); connect(rawSwitchFilteredModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &TimerPanel::onModelDataAboutToBeUpdated);
connect(rawSwitchModel, &RawItemFilteredModel::dataUpdateComplete, this, &TimerPanel::onModelDataUpdateComplete); connect(rawSwitchFilteredModel, &RawItemFilteredModel::dataUpdateComplete, this, &TimerPanel::onModelDataUpdateComplete);
lock = true; lock = true;
@@ -50,11 +49,10 @@ TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, Ge
} }
else { else {
ui->name->setMaxLength(length); ui->name->setMaxLength(length);
//ui->name->setText(timer.name);
} }
// Mode // Mode
ui->mode->setModel(rawSwitchModel); ui->mode->setModel(rawSwitchFilteredModel);
ui->mode->setCurrentIndex(ui->mode->findData(timer.mode.toValue())); ui->mode->setCurrentIndex(ui->mode->findData(timer.mode.toValue()));
connect(ui->mode, SIGNAL(activated(int)), this, SLOT(onModeChanged(int))); connect(ui->mode, SIGNAL(activated(int)), this, SLOT(onModeChanged(int)));
@@ -96,6 +94,7 @@ TimerPanel::~TimerPanel()
void TimerPanel::update() void TimerPanel::update()
{ {
lock = true; lock = true;
ui->name->setText(timer.name); ui->name->setText(timer.name);
int hour = timer.val / 3600; int hour = timer.val / 3600;
@@ -116,7 +115,7 @@ void TimerPanel::update()
pvalue -= hours * 3600; pvalue -= hours * 3600;
int minutes = pvalue / 60; int minutes = pvalue / 60;
int seconds = pvalue % 60; int seconds = pvalue % 60;
ui->persistentValue->setText(QString(" %1(%2:%3:%4)").arg(sign<0 ? "-" :" ").arg(hours, 2, 10, QLatin1Char('0')).arg(minutes, 2, 10, QLatin1Char('0')).arg(seconds, 2, 10, QLatin1Char('0'))); ui->persistentValue->setText(QString(" %1(%2:%3:%4)").arg(sign < 0 ? "-" :" ").arg(hours, 2, 10, QLatin1Char('0')).arg(minutes, 2, 10, QLatin1Char('0')).arg(seconds, 2, 10, QLatin1Char('0')));
} }
ui->countdownBeep->updateValue(); ui->countdownBeep->updateValue();
@@ -133,7 +132,7 @@ QWidget * TimerPanel::getLastFocus()
void TimerPanel::on_value_editingFinished() void TimerPanel::on_value_editingFinished()
{ {
if (!lock) { if (!lock) {
unsigned val = ui->value->time().hour()*3600 + ui->value->time().minute()*60 + ui->value->time().second(); unsigned val = ui->value->time().hour() * 3600 + ui->value->time().minute() * 60 + ui->value->time().second();
if (timer.val != val) { if (timer.val != val) {
timer.val = val; timer.val = val;
emit modified(); emit modified();
@@ -181,6 +180,7 @@ void TimerPanel::onModelDataAboutToBeUpdated()
void TimerPanel::onModelDataUpdateComplete() void TimerPanel::onModelDataUpdateComplete()
{ {
update(); update();
lock = false;
} }
/******************************************************************************/ /******************************************************************************/
@@ -250,19 +250,19 @@ ModulePanel::ModulePanel(QWidget * parent, ModelData & model, ModuleData & modul
} }
// The protocols available on this board // The protocols available on this board
for (unsigned int i=0; i<PULSES_PROTOCOL_LAST; i++) { for (unsigned int i = 0; i < PULSES_PROTOCOL_LAST; i++) {
if (firmware->isAvailable((PulsesProtocol) i, moduleIdx)) { if (firmware->isAvailable((PulsesProtocol) i, moduleIdx)) {
ui->protocol->addItem(ModuleData::protocolToString(i), i); ui->protocol->addItem(ModuleData::protocolToString(i), i);
if (i == module.protocol) if (i == module.protocol)
ui->protocol->setCurrentIndex(ui->protocol->count()-1); ui->protocol->setCurrentIndex(ui->protocol->count() - 1);
} }
} }
for (int i=0; i<=MODULE_SUBTYPE_MULTI_LAST; i++) { for (int i = 0; i <= MODULE_SUBTYPE_MULTI_LAST; i++) {
if (i == MODULE_SUBTYPE_MULTI_SCANNER) if (i == MODULE_SUBTYPE_MULTI_SCANNER)
continue; continue;
ui->multiProtocol->addItem(Multiprotocols::protocolToString(i), i); ui->multiProtocol->addItem(Multiprotocols::protocolToString(i), i);
} }
for (int i=MODULE_SUBTYPE_MULTI_LAST + 1; i <= 124; i++) { for (int i = MODULE_SUBTYPE_MULTI_LAST + 1; i <= 124; i++) {
ui->multiProtocol->addItem(QString::number(i + 3), i); ui->multiProtocol->addItem(QString::number(i + 3), i);
} }
@@ -340,7 +340,7 @@ void ModulePanel::setupFailsafes()
else { else {
QLabel * label = new QLabel(this); QLabel * label = new QLabel(this);
label->setProperty("index", i); label->setProperty("index", i);
label->setText(QString::number(i+1)); label->setText(QString::number(i + 1));
QComboBox * combo = new QComboBox(this); QComboBox * combo = new QComboBox(this);
combo->setProperty("index", i); combo->setProperty("index", i);
@@ -519,7 +519,7 @@ void ModulePanel::update()
ui->ppmFrameLength->setVisible(mask & MASK_SBUSPPM_FIELDS); ui->ppmFrameLength->setVisible(mask & MASK_SBUSPPM_FIELDS);
ui->ppmFrameLength->setMinimum(module.channelsCount * (model->extendedLimits ? 2.250 : 2)+3.5); ui->ppmFrameLength->setMinimum(module.channelsCount * (model->extendedLimits ? 2.250 : 2)+3.5);
ui->ppmFrameLength->setMaximum(firmware->getCapability(PPMFrameLength)); ui->ppmFrameLength->setMaximum(firmware->getCapability(PPMFrameLength));
ui->ppmFrameLength->setValue(22.5+((double)module.ppm.frameLength)*0.5); ui->ppmFrameLength->setValue(22.5 + ((double)module.ppm.frameLength) * 0.5);
// Antenna mode on Horus and XLite // Antenna mode on Horus and XLite
if (mask & MASK_ANTENNA) { if (mask & MASK_ANTENNA) {
@@ -613,17 +613,17 @@ void ModulePanel::update()
ui->registrationIdLabel->setVisible(mask & MASK_ACCESS); ui->registrationIdLabel->setVisible(mask & MASK_ACCESS);
ui->registrationId->setVisible(mask & MASK_ACCESS); ui->registrationId->setVisible(mask & MASK_ACCESS);
ui->rx1Label->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1<<0))); ui->rx1Label->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1 << 0)));
ui->clearRx1->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1<<0))); ui->clearRx1->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1 << 0)));
ui->rx1->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1<<0))); ui->rx1->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1 << 0)));
ui->rx2Label->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1<<1))); ui->rx2Label->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1 << 1)));
ui->clearRx2->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1<<1))); ui->clearRx2->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1 << 1)));
ui->rx2->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1<<1))); ui->rx2->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1 << 1)));
ui->rx3Label->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1<<2))); ui->rx3Label->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1 << 2)));
ui->clearRx3->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1<<2))); ui->clearRx3->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1 << 2)));
ui->rx3->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1<<2))); ui->rx3->setVisible((mask & MASK_ACCESS) && (module.access.receivers & (1 << 2)));
// Failsafes // Failsafes
ui->label_failsafeMode->setVisible(mask & MASK_FAILSAFES); ui->label_failsafeMode->setVisible(mask & MASK_FAILSAFES);
@@ -751,7 +751,7 @@ void ModulePanel::on_rxNumber_editingFinished()
void ModulePanel::on_ppmFrameLength_editingFinished() void ModulePanel::on_ppmFrameLength_editingFinished()
{ {
int val = (ui->ppmFrameLength->value()-22.5) / 0.5; int val = (ui->ppmFrameLength->value() - 22.5) / 0.5;
if (module.ppm.frameLength != val) { if (module.ppm.frameLength != val) {
module.ppm.frameLength = val; module.ppm.frameLength = val;
emit modified(); emit modified();
@@ -775,8 +775,8 @@ void ModulePanel::onMultiProtocolChanged(int index)
module.multi.rfProtocol = (unsigned int)rfProtocol; module.multi.rfProtocol = (unsigned int)rfProtocol;
unsigned int maxSubTypes = multiProtocols.getProtocol(index).numSubTypes(); unsigned int maxSubTypes = multiProtocols.getProtocol(index).numSubTypes();
if (rfProtocol > MODULE_SUBTYPE_MULTI_LAST) if (rfProtocol > MODULE_SUBTYPE_MULTI_LAST)
maxSubTypes=8; maxSubTypes = 8;
module.subType = std::min(module.subType, maxSubTypes -1); module.subType = std::min(module.subType, maxSubTypes - 1);
module.channelsCount = module.getMaxChannelCount(); module.channelsCount = module.getMaxChannelCount();
update(); update();
emit modified(); emit modified();
@@ -970,19 +970,19 @@ void ModulePanel::onClearAccessRxClicked()
QPushButton *button = qobject_cast<QPushButton *>(sender()); QPushButton *button = qobject_cast<QPushButton *>(sender());
if (button == ui->clearRx1) { if (button == ui->clearRx1) {
module.access.receivers &= ~(1<<0); module.access.receivers &= ~(1 << 0);
ui->rx1->clear(); ui->rx1->clear();
update(); update();
emit modified(); emit modified();
} }
else if (button == ui->clearRx2) { else if (button == ui->clearRx2) {
module.access.receivers &= ~(1<<1); module.access.receivers &= ~(1 << 1);
ui->rx2->clear(); ui->rx2->clear();
update(); update();
emit modified(); emit modified();
} }
else if (button == ui->clearRx3) { else if (button == ui->clearRx3) {
module.access.receivers &= ~(1<<2); module.access.receivers &= ~(1 << 2);
ui->rx3->clear(); ui->rx3->clear();
update(); update();
emit modified(); emit modified();
@@ -991,18 +991,20 @@ void ModulePanel::onClearAccessRxClicked()
/******************************************************************************/ /******************************************************************************/
SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, RawSwitchItemModel * rawSwitchItemModel): SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels):
ModelPanel(parent, model, generalSettings, firmware), ModelPanel(parent, model, generalSettings, firmware),
ui(new Ui::Setup) ui(new Ui::Setup),
commonItemModels(commonItemModels)
{ {
ui->setupUi(this);
rawSwitchFilteredModel = new RawItemFilteredModel(commonItemModels->rawSwitchItemModel(), RawSwitch::TimersContext, this);
Board::Type board = firmware->getBoard(); Board::Type board = firmware->getBoard();
lock = true; lock = true;
memset(modules, 0, sizeof(modules)); memset(modules, 0, sizeof(modules));
ui->setupUi(this);
QRegExp rx(CHAR_FOR_NAMES_REGEX); QRegExp rx(CHAR_FOR_NAMES_REGEX);
ui->name->setValidator(new QRegExpValidator(rx, this)); ui->name->setValidator(new QRegExpValidator(rx, this));
ui->name->setMaxLength(firmware->getCapability(ModelName)); ui->name->setMaxLength(firmware->getCapability(ModelName));
@@ -1020,7 +1022,7 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
foreach ( QString file, qd.entryList(filters, QDir::Files) ) { foreach ( QString file, qd.entryList(filters, QDir::Files) ) {
QFileInfo fi(file); QFileInfo fi(file);
QString temp = fi.fileName(); QString temp = fi.fileName();
if (!items.contains(temp) && temp.length() <= 6+4) { if (!items.contains(temp) && temp.length() <= 6 + 4) {
items.append(temp); items.append(temp);
} }
} }
@@ -1030,7 +1032,7 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
foreach (QString file, qd.entryList(filters, QDir::Files)) { foreach (QString file, qd.entryList(filters, QDir::Files)) {
QFileInfo fi(file); QFileInfo fi(file);
QString temp = fi.completeBaseName(); QString temp = fi.completeBaseName();
if (!items.contains(temp) && temp.length() <= 10+4) { if (!items.contains(temp) && temp.length() <= 10 + 4) {
items.append(temp); items.append(temp);
} }
} }
@@ -1043,7 +1045,7 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
foreach (QString file, items) { foreach (QString file, items) {
ui->image->addItem(file); ui->image->addItem(file);
if (file == model.bitmap) { if (file == model.bitmap) {
ui->image->setCurrentIndex(ui->image->count()-1); ui->image->setCurrentIndex(ui->image->count() - 1);
QString fileName = path; QString fileName = path;
fileName.append(model.bitmap); fileName.append(model.bitmap);
if (!IS_FAMILY_HORUS_OR_T16(board)) if (!IS_FAMILY_HORUS_OR_T16(board))
@@ -1075,7 +1077,6 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
} }
QWidget * prevFocus = ui->image; QWidget * prevFocus = ui->image;
rawSwitchFilteredModel = new RawItemFilteredModel(rawSwitchItemModel, RawSwitch::TimersContext, this);
timersCount = firmware->getCapability(Timers); timersCount = firmware->getCapability(Timers);
@@ -1107,7 +1108,7 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
if (firmware->getCapability(HasTopLcd)) { if (firmware->getCapability(HasTopLcd)) {
ui->toplcdTimer->setField(model.toplcdTimer, this); ui->toplcdTimer->setField(model.toplcdTimer, this);
for (int i = 0; i < CPN_MAX_TIMERS; i++) { for (int i = 0; i < CPN_MAX_TIMERS; i++) {
if (i<timersCount) { if (i < timersCount) {
ui->toplcdTimer->addItem(tr("Timer %1").arg(i + 1), i); ui->toplcdTimer->addItem(tr("Timer %1").arg(i + 1), i);
} }
} }
@@ -1130,12 +1131,12 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
prevFocus = ui->trimsDisplay; prevFocus = ui->trimsDisplay;
int analogs = CPN_MAX_STICKS + getBoardCapability(board, Board::Pots) + getBoardCapability(board, Board::Sliders); int analogs = CPN_MAX_STICKS + getBoardCapability(board, Board::Pots) + getBoardCapability(board, Board::Sliders);
int genAryIdx = 0; int genAryIdx = 0;
for (int i=0; i < analogs + firmware->getCapability(RotaryEncoders); i++) { for (int i = 0; i < analogs + firmware->getCapability(RotaryEncoders); i++) {
RawSource src((i < analogs) ? SOURCE_TYPE_STICK : SOURCE_TYPE_ROTARY_ENCODER, (i < analogs) ? i : analogs - i); RawSource src((i < analogs) ? SOURCE_TYPE_STICK : SOURCE_TYPE_ROTARY_ENCODER, (i < analogs) ? i : analogs - i);
QCheckBox * checkbox = new QCheckBox(this); QCheckBox * checkbox = new QCheckBox(this);
checkbox->setProperty("index", i); checkbox->setProperty("index", i);
checkbox->setText(src.toString(&model, &generalSettings)); checkbox->setText(src.toString(&model, &generalSettings));
ui->centerBeepLayout->addWidget(checkbox, 0, i+1); ui->centerBeepLayout->addWidget(checkbox, 0, i + 1);
connect(checkbox, SIGNAL(toggled(bool)), this, SLOT(onBeepCenterToggled(bool))); connect(checkbox, SIGNAL(toggled(bool)), this, SLOT(onBeepCenterToggled(bool)));
centerBeepCheckboxes << checkbox; centerBeepCheckboxes << checkbox;
if (IS_HORUS_OR_TARANIS(board)) { if (IS_HORUS_OR_TARANIS(board)) {
@@ -1151,7 +1152,7 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
} }
// Startup switches warnings // Startup switches warnings
for (int i=0; i<getBoardCapability(board, Board::Switches); i++) { for (int i = 0; i < getBoardCapability(board, Board::Switches); i++) {
Board::SwitchInfo switchInfo = Boards::getSwitchInfo(board, i); Board::SwitchInfo switchInfo = Boards::getSwitchInfo(board, i);
switchInfo.config = Board::SwitchType(generalSettings.switchConfig[i]); switchInfo.config = Board::SwitchType(generalSettings.switchConfig[i]);
if (switchInfo.config == Board::SWITCH_NOT_AVAILABLE || switchInfo.config == Board::SWITCH_TOGGLE) { if (switchInfo.config == Board::SWITCH_NOT_AVAILABLE || switchInfo.config == Board::SWITCH_TOGGLE) {
@@ -1175,11 +1176,11 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
label->setText(src.toString(&model, &generalSettings)); label->setText(src.toString(&model, &generalSettings));
slider->setMaximum(switchInfo.config == Board::SWITCH_3POS ? 2 : 1); slider->setMaximum(switchInfo.config == Board::SWITCH_3POS ? 2 : 1);
cb->setProperty("index", i); cb->setProperty("index", i);
ui->switchesStartupLayout->addWidget(label, 0, i+1); ui->switchesStartupLayout->addWidget(label, 0, i + 1);
ui->switchesStartupLayout->setAlignment(label, Qt::AlignCenter); ui->switchesStartupLayout->setAlignment(label, Qt::AlignCenter);
ui->switchesStartupLayout->addWidget(slider, 1, i+1); ui->switchesStartupLayout->addWidget(slider, 1, i + 1);
ui->switchesStartupLayout->setAlignment(slider, Qt::AlignCenter); ui->switchesStartupLayout->setAlignment(slider, Qt::AlignCenter);
ui->switchesStartupLayout->addWidget(cb, 2, i+1); ui->switchesStartupLayout->addWidget(cb, 2, i + 1);
ui->switchesStartupLayout->setAlignment(cb, Qt::AlignCenter); ui->switchesStartupLayout->setAlignment(cb, Qt::AlignCenter);
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(startupSwitchEdited(int))); connect(slider, SIGNAL(valueChanged(int)), this, SLOT(startupSwitchEdited(int)));
connect(cb, SIGNAL(toggled(bool)), this, SLOT(startupSwitchToggled(bool))); connect(cb, SIGNAL(toggled(bool)), this, SLOT(startupSwitchToggled(bool)));
@@ -1193,12 +1194,12 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
// Pot warnings // Pot warnings
prevFocus = ui->potWarningMode; prevFocus = ui->potWarningMode;
if (IS_HORUS_OR_TARANIS(board)) { if (IS_HORUS_OR_TARANIS(board)) {
for (int i=0; i<getBoardCapability(board, Board::Pots)+getBoardCapability(board, Board::Sliders); i++) { for (int i = 0; i < getBoardCapability(board, Board::Pots) + getBoardCapability(board, Board::Sliders); i++) {
RawSource src(SOURCE_TYPE_STICK, CPN_MAX_STICKS + i); RawSource src(SOURCE_TYPE_STICK, CPN_MAX_STICKS + i);
QCheckBox * cb = new QCheckBox(this); QCheckBox * cb = new QCheckBox(this);
cb->setProperty("index", i); cb->setProperty("index", i);
cb->setText(src.toString(&model, &generalSettings)); cb->setText(src.toString(&model, &generalSettings));
ui->potWarningLayout->addWidget(cb, 0, i+1); ui->potWarningLayout->addWidget(cb, 0, i + 1);
connect(cb, SIGNAL(toggled(bool)), this, SLOT(potWarningToggled(bool))); connect(cb, SIGNAL(toggled(bool)), this, SLOT(potWarningToggled(bool)));
potWarningCheckboxes << cb; potWarningCheckboxes << cb;
if (src.isPot(&genAryIdx) && !generalSettings.isPotAvailable(genAryIdx)) { if (src.isPot(&genAryIdx) && !generalSettings.isPotAvailable(genAryIdx)) {
@@ -1246,7 +1247,6 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
SetupPanel::~SetupPanel() SetupPanel::~SetupPanel()
{ {
delete rawSwitchFilteredModel;
delete ui; delete ui;
} }
@@ -1277,7 +1277,7 @@ void SetupPanel::on_extendedTrims_toggled(bool checked)
void SetupPanel::on_trimIncrement_currentIndexChanged(int index) void SetupPanel::on_trimIncrement_currentIndexChanged(int index)
{ {
model->trimInc = index-2; model->trimInc = index - 2;
emit modified(); emit modified();
} }
@@ -1346,13 +1346,13 @@ void SetupPanel::populateThrottleSourceCB()
ui->throttleSource->clear(); ui->throttleSource->clear();
ui->throttleSource->addItem(tr("THR"), 0); ui->throttleSource->addItem(tr("THR"), 0);
int idx=1; int idx = 1;
for (int i=0; i<getBoardCapability(board, Board::Pots)+getBoardCapability(board, Board::Sliders); i++, idx++) { for (int i = 0; i < getBoardCapability(board, Board::Pots) + getBoardCapability(board, Board::Sliders); i++, idx++) {
if (RawSource(SOURCE_TYPE_STICK,4+i).isAvailable(model,&generalSettings,board)) { if (RawSource(SOURCE_TYPE_STICK, 4 + i).isAvailable(model, &generalSettings, board)) {
ui->throttleSource->addItem(firmware->getAnalogInputName(4+i), idx); ui->throttleSource->addItem(firmware->getAnalogInputName(4 + i), idx);
} }
} }
for (int i=0; i<firmware->getCapability(Outputs); i++, idx++) { for (int i = 0; i < firmware->getCapability(Outputs); i++, idx++) {
ui->throttleSource->addItem(RawSource(SOURCE_TYPE_CH, i).toString(model, &generalSettings), idx); ui->throttleSource->addItem(RawSource(SOURCE_TYPE_CH, i).toString(model, &generalSettings), idx);
} }
@@ -1381,7 +1381,7 @@ void SetupPanel::update()
updatePotWarnings(); updatePotWarnings();
} }
for (int i=0; i<CPN_MAX_MODULES+1; i++) { for (int i = 0; i < CPN_MAX_MODULES + 1; i++) {
if (modules[i]) { if (modules[i]) {
modules[i]->update(); modules[i]->update();
} }
@@ -1392,7 +1392,7 @@ void SetupPanel::update()
void SetupPanel::updateBeepCenter() void SetupPanel::updateBeepCenter()
{ {
for (int i=0; i<centerBeepCheckboxes.size(); i++) { for (int i = 0; i < centerBeepCheckboxes.size(); i++) {
centerBeepCheckboxes[i]->setChecked(model->beepANACenter & (0x01 << i)); centerBeepCheckboxes[i]->setChecked(model->beepANACenter & (0x01 << i));
} }
} }
@@ -1404,20 +1404,20 @@ void SetupPanel::updateStartupSwitches()
uint64_t switchStates = model->switchWarningStates; uint64_t switchStates = model->switchWarningStates;
uint64_t value; uint64_t value;
for (int i=0; i<startupSwitchesSliders.size(); i++) { for (int i = 0; i < startupSwitchesSliders.size(); i++) {
QSlider * slider = startupSwitchesSliders[i]; QSlider * slider = startupSwitchesSliders[i];
QCheckBox * cb = startupSwitchesCheckboxes[i]; QCheckBox * cb = startupSwitchesCheckboxes[i];
int index = slider->property("index").toInt(); int index = slider->property("index").toInt();
bool enabled = !(model->switchWarningEnable & (1 << index)); bool enabled = !(model->switchWarningEnable & (1 << index));
if (IS_HORUS_OR_TARANIS(firmware->getBoard())) { if (IS_HORUS_OR_TARANIS(firmware->getBoard())) {
value = (switchStates >> (2*index)) & 0x03; value = (switchStates >> (2 * index)) & 0x03;
if (generalSettings.switchConfig[index] != Board::SWITCH_3POS && value == 2) { if (generalSettings.switchConfig[index] != Board::SWITCH_3POS && value == 2) {
value = 1; value = 1;
} }
} }
else { else {
value = (i==0 ? switchStates & 0x3 : switchStates & 0x1); value = (i == 0 ? switchStates & 0x3 : switchStates & 0x1);
switchStates >>= (i==0 ? 2 : 1); switchStates >>= (i == 0 ? 2 : 1);
} }
slider->setValue(value); slider->setValue(value);
slider->setEnabled(enabled); slider->setEnabled(enabled);
@@ -1443,7 +1443,7 @@ void SetupPanel::startupSwitchEdited(int value)
mask = 0x03; mask = 0x03;
} }
else { else {
shift = index+1; shift = index + 1;
mask = 0x01ull << shift; mask = 0x01ull << shift;
} }
} }
@@ -1484,7 +1484,7 @@ void SetupPanel::updatePotWarnings()
{ {
lock = true; lock = true;
ui->potWarningMode->setCurrentIndex(model->potsWarningMode); ui->potWarningMode->setCurrentIndex(model->potsWarningMode);
for (int i=0; i<potWarningCheckboxes.size(); i++) { for (int i = 0; i < potWarningCheckboxes.size(); i++) {
QCheckBox *checkbox = potWarningCheckboxes[i]; QCheckBox *checkbox = potWarningCheckboxes[i];
int index = checkbox->property("index").toInt(); int index = checkbox->property("index").toInt();
checkbox->setChecked(!model->potsWarnEnabled[index]); checkbox->setChecked(!model->potsWarnEnabled[index]);
@@ -1614,7 +1614,7 @@ void SetupPanel::cmTimerClear(bool prompt)
model->timers[selectedTimerIndex].clear(); model->timers[selectedTimerIndex].clear();
model->updateAllReferences(ModelData::REF_UPD_TYPE_TIMER, ModelData::REF_UPD_ACT_CLEAR, selectedTimerIndex); model->updateAllReferences(ModelData::REF_UPD_TYPE_TIMER, ModelData::REF_UPD_ACT_CLEAR, selectedTimerIndex);
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
@@ -1627,7 +1627,7 @@ void SetupPanel::cmTimerClearAll()
model->timers[i].clear(); model->timers[i].clear();
model->updateAllReferences(ModelData::REF_UPD_TYPE_TIMER, ModelData::REF_UPD_ACT_CLEAR, i); model->updateAllReferences(ModelData::REF_UPD_TYPE_TIMER, ModelData::REF_UPD_ACT_CLEAR, i);
} }
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
@@ -1661,7 +1661,7 @@ void SetupPanel::cmTimerDelete()
} }
model->timers[maxidx].clear(); model->timers[maxidx].clear();
model->updateAllReferences(ModelData::REF_UPD_TYPE_TIMER, ModelData::REF_UPD_ACT_SHIFT, selectedTimerIndex, 0, -1); model->updateAllReferences(ModelData::REF_UPD_TYPE_TIMER, ModelData::REF_UPD_ACT_SHIFT, selectedTimerIndex, 0, -1);
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
@@ -1674,7 +1674,7 @@ void SetupPanel::cmTimerInsert()
} }
model->timers[selectedTimerIndex].clear(); model->timers[selectedTimerIndex].clear();
model->updateAllReferences(ModelData::REF_UPD_TYPE_TIMER, ModelData::REF_UPD_ACT_SHIFT, selectedTimerIndex, 0, 1); model->updateAllReferences(ModelData::REF_UPD_TYPE_TIMER, ModelData::REF_UPD_ACT_SHIFT, selectedTimerIndex, 0, 1);
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
@@ -1694,7 +1694,7 @@ void SetupPanel::cmTimerPaste()
if (hasTimerClipboardData(&data)) { if (hasTimerClipboardData(&data)) {
TimerData *td = &model->timers[selectedTimerIndex]; TimerData *td = &model->timers[selectedTimerIndex];
memcpy(td, data.constData(), sizeof(TimerData)); memcpy(td, data.constData(), sizeof(TimerData));
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
} }
@@ -1708,12 +1708,17 @@ void SetupPanel::swapTimerData(int idx1, int idx2)
memcpy(td2, td1, sizeof(TimerData)); memcpy(td2, td1, sizeof(TimerData));
memcpy(td1, &tdtmp, sizeof(TimerData)); memcpy(td1, &tdtmp, sizeof(TimerData));
model->updateAllReferences(ModelData::REF_UPD_TYPE_TIMER, ModelData::REF_UPD_ACT_SWAP, idx1, idx2); model->updateAllReferences(ModelData::REF_UPD_TYPE_TIMER, ModelData::REF_UPD_ACT_SWAP, idx1, idx2);
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
} }
void SetupPanel::onTimerNameChanged() void SetupPanel::onTimerNameChanged()
{ {
emit updateDataModels(); updateItemModels();
}
void SetupPanel::updateItemModels()
{
commonItemModels->update(CommonItemModels::RMO_TIMERS);
} }
+4 -3
View File
@@ -26,7 +26,7 @@
constexpr char MIMETYPE_TIMER[] = "application/x-companion-timer"; constexpr char MIMETYPE_TIMER[] = "application/x-companion-timer";
class RawSwitchItemModel; class CommonItemModels;
class RawItemFilteredModel; class RawItemFilteredModel;
namespace Ui { namespace Ui {
@@ -131,7 +131,7 @@ class SetupPanel : public ModelPanel
Q_OBJECT Q_OBJECT
public: public:
SetupPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, RawSwitchItemModel * rawSwitchItemModel); SetupPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels);
virtual ~SetupPanel(); virtual ~SetupPanel();
virtual void update(); virtual void update();
@@ -139,7 +139,6 @@ class SetupPanel : public ModelPanel
signals: signals:
void extendedLimitsToggled(); void extendedLimitsToggled();
void updated(); void updated();
void updateDataModels();
private slots: private slots:
void on_name_editingFinished(); void on_name_editingFinished();
@@ -190,7 +189,9 @@ class SetupPanel : public ModelPanel
bool moveTimerDownAllowed() const; bool moveTimerDownAllowed() const;
bool moveTimerUpAllowed() const; bool moveTimerUpAllowed() const;
void swapTimerData(int idx1, int idx2); void swapTimerData(int idx1, int idx2);
CommonItemModels * commonItemModels;
RawItemFilteredModel * rawSwitchFilteredModel; RawItemFilteredModel * rawSwitchFilteredModel;
void updateItemModels();
}; };
#endif // _SETUP_H_ #endif // _SETUP_H_
+15 -9
View File
@@ -297,6 +297,7 @@ void TelemetryCustomScreen::onModelDataAboutToBeUpdated()
void TelemetryCustomScreen::onModelDataUpdateComplete() void TelemetryCustomScreen::onModelDataUpdateComplete()
{ {
update(); update();
lock = false;
} }
/******************************************************/ /******************************************************/
@@ -690,12 +691,13 @@ void TelemetrySensorPanel::cmMoveDown()
/******************************************************/ /******************************************************/
TelemetryPanel::TelemetryPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, RawSourceItemModel * rawSourceItemModel): TelemetryPanel::TelemetryPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels):
ModelPanel(parent, model, generalSettings, firmware), ModelPanel(parent, model, generalSettings, firmware),
ui(new Ui::Telemetry) ui(new Ui::Telemetry),
commonItemModels(commonItemModels)
{ {
ui->setupUi(this); ui->setupUi(this);
rawSourceModel = new RawItemFilteredModel(rawSourceItemModel, this); rawSourceFilteredModel = new RawItemFilteredModel(commonItemModels->rawSourceItemModel(), this);
sensorCapability = firmware->getCapability(Sensors); sensorCapability = firmware->getCapability(Sensors);
if (sensorCapability > CPN_MAX_SENSORS) // TODO should be role of getCapability if (sensorCapability > CPN_MAX_SENSORS) // TODO should be role of getCapability
@@ -732,7 +734,7 @@ TelemetryPanel::TelemetryPanel(QWidget *parent, ModelData & model, GeneralSettin
} }
for (int i = 0; i < firmware->getCapability(TelemetryCustomScreens); i++) { for (int i = 0; i < firmware->getCapability(TelemetryCustomScreens); i++) {
TelemetryCustomScreen * tab = new TelemetryCustomScreen(this, model, model.frsky.screens[i], generalSettings, firmware, rawSourceModel); TelemetryCustomScreen * tab = new TelemetryCustomScreen(this, model, model.frsky.screens[i], generalSettings, firmware, rawSourceFilteredModel);
ui->customScreens->addTab(tab, tr("Telemetry screen %1").arg(i + 1)); ui->customScreens->addTab(tab, tr("Telemetry screen %1").arg(i + 1));
telemetryCustomScreens[i] = tab; telemetryCustomScreens[i] = tab;
connect(tab, &TelemetryCustomScreen::modified, this, &TelemetryPanel::onModified); connect(tab, &TelemetryCustomScreen::modified, this, &TelemetryPanel::onModified);
@@ -745,7 +747,6 @@ TelemetryPanel::TelemetryPanel(QWidget *parent, ModelData & model, GeneralSettin
TelemetryPanel::~TelemetryPanel() TelemetryPanel::~TelemetryPanel()
{ {
delete rawSourceModel;
delete ui; delete ui;
} }
@@ -983,7 +984,7 @@ void TelemetryPanel::on_clearAllSensors()
} }
update(); update();
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
@@ -994,7 +995,7 @@ void TelemetryPanel::on_insertSensor(int selectedIndex)
model->updateAllReferences(ModelData::REF_UPD_TYPE_SENSOR, ModelData::REF_UPD_ACT_SHIFT, selectedIndex, 0, 1); model->updateAllReferences(ModelData::REF_UPD_TYPE_SENSOR, ModelData::REF_UPD_ACT_SHIFT, selectedIndex, 0, 1);
update(); update();
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
@@ -1008,7 +1009,7 @@ void TelemetryPanel::on_deleteSensor(int selectedIndex)
model->updateAllReferences(ModelData::REF_UPD_TYPE_SENSOR, ModelData::REF_UPD_ACT_SHIFT, selectedIndex, 0, -1); model->updateAllReferences(ModelData::REF_UPD_TYPE_SENSOR, ModelData::REF_UPD_ACT_SHIFT, selectedIndex, 0, -1);
update(); update();
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
@@ -1032,7 +1033,12 @@ void TelemetryPanel::swapData(int idx1, int idx2)
memcpy(sd1, &sdtmp, sizeof(SensorData)); memcpy(sd1, &sdtmp, sizeof(SensorData));
model->updateAllReferences(ModelData::REF_UPD_TYPE_SENSOR, ModelData::REF_UPD_ACT_SWAP, idx1, idx2); model->updateAllReferences(ModelData::REF_UPD_TYPE_SENSOR, ModelData::REF_UPD_ACT_SWAP, idx1, idx2);
update(); update();
emit updateDataModels(); updateItemModels();
emit modified(); emit modified();
} }
} }
void TelemetryPanel::updateItemModels()
{
commonItemModels->update(CommonItemModels::RMO_TELEMETRY_SENSORS);
}
+5 -5
View File
@@ -27,7 +27,7 @@
constexpr char MIMETYPE_TELE_SENSOR[] = "application/x-companion-tele-sensor"; constexpr char MIMETYPE_TELE_SENSOR[] = "application/x-companion-tele-sensor";
class AutoComboBox; class AutoComboBox;
class RawSourceItemModel; class CommonItemModels;
class RawItemFilteredModel; class RawItemFilteredModel;
class TimerEdit; class TimerEdit;
@@ -125,14 +125,12 @@ class TelemetryPanel : public ModelPanel
Q_OBJECT Q_OBJECT
public: public:
TelemetryPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, RawSourceItemModel * rawSourceItemModel); TelemetryPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels);
virtual ~TelemetryPanel(); virtual ~TelemetryPanel();
virtual void update(); virtual void update();
signals: signals:
void updated(); void updated();
void updateDataModels();
private slots: private slots:
void on_telemetryProtocol_currentIndexChanged(int index); void on_telemetryProtocol_currentIndexChanged(int index);
@@ -159,7 +157,8 @@ class TelemetryPanel : public ModelPanel
TelemetryCustomScreen * telemetryCustomScreens[4]; TelemetryCustomScreen * telemetryCustomScreens[4];
TelemetrySensorPanel * sensorPanels[CPN_MAX_SENSORS]; TelemetrySensorPanel * sensorPanels[CPN_MAX_SENSORS];
int sensorCapability; int sensorCapability;
RawItemFilteredModel * rawSourceModel; CommonItemModels * commonItemModels;
RawItemFilteredModel * rawSourceFilteredModel;
void setup(); void setup();
void telBarUpdate(); void telBarUpdate();
@@ -167,6 +166,7 @@ class TelemetryPanel : public ModelPanel
void populateCurrentSource(); void populateCurrentSource();
void populateVarioSource(); void populateVarioSource();
void swapData(int idx1, int idx2); void swapData(int idx1, int idx2);
void updateItemModels();
}; };
#endif // _TELEMETRY_H_ #endif // _TELEMETRY_H_