Minor cleanup on RawSourceItemModel and TelemetryCustomScreen.

This commit is contained in:
Max Paperno
2018-07-12 13:20:07 -04:00
parent ed255ce1c3
commit b76a0a8789
4 changed files with 12 additions and 13 deletions
@@ -50,7 +50,7 @@ RawSourceItemModel::RawSourceItemModel(const GeneralSettings * const generalSett
addItems(SOURCE_TYPE_GVAR, RawSource::GVarsGroup, fw->getCapability(Gvars));
}
void RawSourceItemModel::setDynamicItemData(QStandardItem * item, const RawSource & src)
void RawSourceItemModel::setDynamicItemData(QStandardItem * item, const RawSource & src) const
{
Board::Type board = getCurrentBoard();
item->setText(src.toString(modelData, generalSettings, board));
@@ -70,7 +70,7 @@ void RawSourceItemModel::addItems(const RawSourceType & type, const unsigned gro
}
}
void RawSourceItemModel::update()
void RawSourceItemModel::update() const
{
for (int i=0; i < rowCount(); ++i)
setDynamicItemData(item(i), RawSource(item(i)->data(ItemIdRole).toInt()));
@@ -107,18 +107,19 @@ void RawSourceFilterItemModel::setFilterGroups(unsigned groups)
bool RawSourceFilterItemModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const
{
bool ok = true;
const QModelIndex & srcIdx = sourceModel()->index(sourceRow, 0, sourceParent);
if (!sourceModel()->data(srcIdx, filterRole()).toBool())
if (!srcIdx.isValid() || !sourceModel()->data(srcIdx, filterRole()).toBool())
return false;
if (filterGroups && filterGroups != RawSource::AllSourceGroups) {
bool ok;
const unsigned group = sourceModel()->data(srcIdx, RawSourceItemModel::ItemGroupRole).toUInt(&ok);
return (ok && (filterGroups & group));
}
return true;
}
void RawSourceFilterItemModel::update()
void RawSourceFilterItemModel::update() const
{
RawSourceItemModel * model = qobject_cast<RawSourceItemModel *>(sourceModel());
if (model)
@@ -39,10 +39,10 @@ class RawSourceItemModel: public QStandardItemModel
RawSourceItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData, QObject * parent = nullptr);
public slots:
void update();
void update() const;
protected:
void setDynamicItemData(QStandardItem * item, const RawSource & src);
void setDynamicItemData(QStandardItem * item, const RawSource & src) const;
void addItems(const RawSourceType & type, const unsigned group, const int count, const int start = 0);
const GeneralSettings * generalSettings;
@@ -66,7 +66,7 @@ class RawSourceFilterItemModel: public QSortFilterProxyModel
public slots:
void setFilterGroups(unsigned groups);
void update();
void update() const;
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const override;
+3 -4
View File
@@ -320,8 +320,7 @@ TelemetryAnalog::~TelemetryAnalog()
TelemetryCustomScreen::TelemetryCustomScreen(QWidget *parent, ModelData & model, FrSkyScreenData & screen, GeneralSettings & generalSettings, Firmware * firmware, RawSourceFilterItemModel * srcModel):
ModelPanel(parent, model, generalSettings, firmware),
ui(new Ui::TelemetryCustomScreen),
screen(screen),
rawSourceItemModel(srcModel)
screen(screen)
{
ui->setupUi(this);
@@ -329,7 +328,7 @@ TelemetryCustomScreen::TelemetryCustomScreen(QWidget *parent, ModelData & model,
for (int c=0; c<firmware->getCapability(TelemetryCustomScreensFieldsPerLine); c++) {
fieldsCB[l][c] = new QComboBox(this);
fieldsCB[l][c]->setProperty("index", c + (l<<8));
fieldsCB[l][c]->setModel(rawSourceItemModel);
fieldsCB[l][c]->setModel(srcModel);
ui->screenNumsLayout->addWidget(fieldsCB[l][c], l, c, 1, 1);
connect(fieldsCB[l][c], SIGNAL(activated(int)), this, SLOT(customFieldChanged(int)));
}
@@ -338,7 +337,7 @@ TelemetryCustomScreen::TelemetryCustomScreen(QWidget *parent, ModelData & model,
for (int l=0; l<4; l++) {
barsCB[l] = new QComboBox(this);
barsCB[l]->setProperty("index", l);
barsCB[l]->setModel(rawSourceItemModel);
barsCB[l]->setModel(srcModel);
connect(barsCB[l], SIGNAL(activated(int)), this, SLOT(barSourceChanged(int)));
ui->screenBarsLayout->addWidget(barsCB[l], l, 0, 1, 1);
-1
View File
@@ -90,7 +90,6 @@ class TelemetryCustomScreen: public ModelPanel
void updateBar(int line);
Ui::TelemetryCustomScreen * ui;
FrSkyScreenData & screen;
RawSourceFilterItemModel * rawSourceItemModel;
QComboBox * fieldsCB[4][3];
QComboBox * barsCB[4];
QDoubleSpinBox * minSB[4];