Revert "PR 7939"

This reverts commit 4318d113
This commit is contained in:
3djc
2020-12-10 13:55:38 +01:00
parent 4318d113f3
commit 959560ded5
5 changed files with 119 additions and 168 deletions
-1
View File
@@ -338,7 +338,6 @@ class ModelData {
value = swtch.toValue(); value = swtch.toValue();
} }
void sortMixes(); void sortMixes();
void updateResetParam(CustomFunctionData * cfd);
}; };
#endif // MODELDATA_H #endif // MODELDATA_H
+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")
}; };
static const QStringList directionIndicators = QStringList() 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;
+41 -57
View File
@@ -23,7 +23,6 @@
#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
@@ -109,11 +108,10 @@ 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, CommonItemModels * commonItemModels): Curves::Curves(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
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);
@@ -232,12 +230,12 @@ CurvesPanel::CurvesPanel(QWidget * parent, ModelData & model, GeneralSettings &
lock = false; lock = false;
} }
CurvesPanel::~CurvesPanel() Curves::~Curves()
{ {
delete ui; delete ui;
} }
void CurvesPanel::editCurve() void Curves::editCurve()
{ {
QPushButton *button = (QPushButton *)sender(); QPushButton *button = (QPushButton *)sender();
int index = button->property("index").toInt(); int index = button->property("index").toInt();
@@ -245,7 +243,7 @@ void CurvesPanel::editCurve()
update(); update();
} }
void CurvesPanel::plotCurve(bool checked) void Curves::plotCurve(bool checked)
{ {
QCheckBox *chk = (QCheckBox *)sender(); QCheckBox *chk = (QCheckBox *)sender();
int index = chk->property("index").toInt(); int index = chk->property("index").toInt();
@@ -253,7 +251,7 @@ void CurvesPanel::plotCurve(bool checked)
updateCurve(); updateCurve();
} }
void CurvesPanel::update() void Curves::update()
{ {
lock = true; lock = true;
@@ -268,12 +266,12 @@ void CurvesPanel::update()
lock = false; lock = false;
} }
void CurvesPanel::setCurrentCurve(int index) void Curves::setCurrentCurve(int index)
{ {
currentCurve = index; currentCurve = index;
} }
void CurvesPanel::updateCurveType() void Curves::updateCurveType()
{ {
lock = true; lock = true;
@@ -299,7 +297,7 @@ void CurvesPanel::updateCurveType()
lock = false; lock = false;
} }
void CurvesPanel::updateCurve() void Curves::updateCurve()
{ {
lock = true; lock = true;
@@ -373,7 +371,7 @@ void CurvesPanel::updateCurve()
lock = false; lock = false;
} }
void CurvesPanel::updateCurvePoints() void Curves::updateCurvePoints()
{ {
lock = true; lock = true;
@@ -407,7 +405,7 @@ void CurvesPanel::updateCurvePoints()
lock = false; lock = false;
} }
void CurvesPanel::onPointEdited() void Curves::onPointEdited()
{ {
if (!lock) { if (!lock) {
int index = sender()->property("index").toInt(); int index = sender()->property("index").toInt();
@@ -419,7 +417,7 @@ void CurvesPanel::onPointEdited()
} }
} }
void CurvesPanel::onNodeMoved(int x, int y) void Curves::onNodeMoved(int x, int y)
{ {
if (!lock) { if (!lock) {
lock = true; lock = true;
@@ -437,20 +435,20 @@ void CurvesPanel::onNodeMoved(int x, int y)
} }
} }
void CurvesPanel::onNodeFocus() void Curves::onNodeFocus()
{ {
int index = sender()->property("index").toInt(); int index = sender()->property("index").toInt();
spny[index]->setFocus(); spny[index]->setFocus();
} }
void CurvesPanel::onNodeUnfocus() void Curves::onNodeUnfocus()
{ {
int index = sender()->property("index").toInt(); int index = sender()->property("index").toInt();
spny[index]->clearFocus(); spny[index]->clearFocus();
updateCurve(); updateCurve();
} }
bool CurvesPanel::allowCurveType(int points, CurveData::CurveType type) bool Curves::allowCurveType(int points, CurveData::CurveType type)
{ {
int totalpoints = 0; int totalpoints = 0;
for (int i = 0; i < maxCurves; i++) { for (int i = 0; i < maxCurves; i++) {
@@ -468,7 +466,7 @@ bool CurvesPanel::allowCurveType(int points, CurveData::CurveType type)
} }
} }
void CurvesPanel::on_curvePoints_currentIndexChanged(int index) void Curves::on_curvePoints_currentIndexChanged(int index)
{ {
if (!lock) { if (!lock) {
int numpoints = ((QComboBox *)sender())->itemData(index).toInt(); int numpoints = ((QComboBox *)sender())->itemData(index).toInt();
@@ -491,7 +489,7 @@ void CurvesPanel::on_curvePoints_currentIndexChanged(int index)
} }
} }
void CurvesPanel::on_curveCustom_currentIndexChanged(int index) void Curves::on_curveCustom_currentIndexChanged(int index)
{ {
if (!lock) { if (!lock) {
CurveData::CurveType type = (CurveData::CurveType)index; CurveData::CurveType type = (CurveData::CurveType)index;
@@ -515,23 +513,20 @@ void CurvesPanel::on_curveCustom_currentIndexChanged(int index)
} }
} }
void CurvesPanel::on_curveSmooth_currentIndexChanged(int index) void Curves::on_curveSmooth_currentIndexChanged(int index)
{ {
model->curves[currentCurve].smooth = index; model->curves[currentCurve].smooth = index;
update(); update();
} }
void CurvesPanel::on_curveName_editingFinished() void Curves::on_curveName_editingFinished()
{ {
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());
updateItemModels();
emit modified(); emit modified();
} }
}
void CurvesPanel::resizeEvent(QResizeEvent *event) void Curves::resizeEvent(QResizeEvent *event)
{ {
QRect qr = ui->curvePreview->contentsRect(); QRect qr = ui->curvePreview->contentsRect();
ui->curvePreview->scene()->setSceneRect(GFX_MARGIN, GFX_MARGIN, qr.width() - GFX_MARGIN * 2, qr.height() - GFX_MARGIN * 2); ui->curvePreview->scene()->setSceneRect(GFX_MARGIN, GFX_MARGIN, qr.width() - GFX_MARGIN * 2, qr.height() - GFX_MARGIN * 2);
@@ -539,7 +534,7 @@ void CurvesPanel::resizeEvent(QResizeEvent *event)
ModelPanel::resizeEvent(event); ModelPanel::resizeEvent(event);
} }
void CurvesPanel::on_curveType_currentIndexChanged(int index) void Curves::on_curveType_currentIndexChanged(int index)
{ {
unsigned int flags = templates[index].flags; unsigned int flags = templates[index].flags;
ui->curveCoeffLabel->setVisible(flags & CURVE_COEFF_ENABLE); ui->curveCoeffLabel->setVisible(flags & CURVE_COEFF_ENABLE);
@@ -553,7 +548,7 @@ void CurvesPanel::on_curveType_currentIndexChanged(int index)
ui->yMin->setValue(-100); ui->yMin->setValue(-100);
} }
void CurvesPanel::addTemplate(QString name, unsigned int flags, curveFunction function) void Curves::addTemplate(QString name, unsigned int flags, curveFunction function)
{ {
CurveCreatorTemplate tmpl; CurveCreatorTemplate tmpl;
tmpl.name = name; tmpl.name = name;
@@ -563,7 +558,7 @@ void CurvesPanel::addTemplate(QString name, unsigned int flags, curveFunction fu
ui->curveType->addItem(name); ui->curveType->addItem(name);
} }
void CurvesPanel::on_curveApply_clicked() void Curves::on_curveApply_clicked()
{ {
int index = ui->curveType->currentIndex(); int index = ui->curveType->currentIndex();
int numpoints = model->curves[currentCurve].count; int numpoints = model->curves[currentCurve].count;
@@ -600,14 +595,14 @@ void CurvesPanel::on_curveApply_clicked()
emit modified(); emit modified();
} }
void CurvesPanel::onPointSizeEdited() void Curves::onPointSizeEdited()
{ {
if (!lock) { if (!lock) {
update(); update();
} }
} }
void CurvesPanel::onNodeDelete() void Curves::onNodeDelete()
{ {
int index = sender()->property("index").toInt(); int index = sender()->property("index").toInt();
int numpoints = model->curves[currentCurve].count; int numpoints = model->curves[currentCurve].count;
@@ -625,7 +620,7 @@ void CurvesPanel::onNodeDelete()
} }
} }
void CurvesPanel::onSceneNewPoint(int x, int y) void Curves::onSceneNewPoint(int x, int y)
{ {
if ((model->curves[currentCurve].type == CurveData::CURVE_TYPE_CUSTOM) && (model->curves[currentCurve].count < CPN_MAX_POINTS)) { if ((model->curves[currentCurve].type == CurveData::CURVE_TYPE_CUSTOM) && (model->curves[currentCurve].count < CPN_MAX_POINTS)) {
int newidx = 0; int newidx = 0;
@@ -656,7 +651,7 @@ void CurvesPanel::onSceneNewPoint(int x, int y)
} }
} }
void CurvesPanel::onCustomContextMenuRequested(QPoint pos) void Curves::onCustomContextMenuRequested(QPoint pos)
{ {
QPushButton *button = (QPushButton *)sender(); QPushButton *button = (QPushButton *)sender();
selectedIndex = button->property("index").toInt(); selectedIndex = button->property("index").toInt();
@@ -678,7 +673,7 @@ void CurvesPanel::onCustomContextMenuRequested(QPoint pos)
contextMenu.exec(globalPos); contextMenu.exec(globalPos);
} }
bool CurvesPanel::hasClipboardData(QByteArray * data) const bool Curves::hasClipboardData(QByteArray * data) const
{ {
const QClipboard * clipboard = QApplication::clipboard(); const QClipboard * clipboard = QApplication::clipboard();
const QMimeData * mimeData = clipboard->mimeData(); const QMimeData * mimeData = clipboard->mimeData();
@@ -690,22 +685,22 @@ bool CurvesPanel::hasClipboardData(QByteArray * data) const
return false; return false;
} }
bool CurvesPanel::insertAllowed() const bool Curves::insertAllowed() const
{ {
return ((selectedIndex < maxCurves - 1) && (model->curves[maxCurves - 1].isEmpty())); return ((selectedIndex < maxCurves - 1) && (model->curves[maxCurves - 1].isEmpty()));
} }
bool CurvesPanel::moveDownAllowed() const bool Curves::moveDownAllowed() const
{ {
return selectedIndex < maxCurves - 1; return selectedIndex < maxCurves - 1;
} }
bool CurvesPanel::moveUpAllowed() const bool Curves::moveUpAllowed() const
{ {
return selectedIndex > 0; return selectedIndex > 0;
} }
void CurvesPanel::cmClear(bool prompt) void Curves::cmClear(bool prompt)
{ {
if (prompt) { if (prompt) {
if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Clear Curve. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Clear Curve. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
@@ -715,11 +710,10 @@ 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();
updateItemModels();
emit modified(); emit modified();
} }
void CurvesPanel::cmClearAll() void Curves::cmClearAll()
{ {
if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Clear all Curves. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Clear all Curves. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
return; return;
@@ -729,11 +723,10 @@ 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();
updateItemModels();
emit modified(); emit modified();
} }
void CurvesPanel::cmCopy() void Curves::cmCopy()
{ {
QByteArray data; QByteArray data;
data.append((char*)&model->curves[selectedIndex], sizeof(CurveData)); data.append((char*)&model->curves[selectedIndex], sizeof(CurveData));
@@ -742,7 +735,7 @@ void CurvesPanel::cmCopy()
QApplication::clipboard()->setMimeData(mimeData,QClipboard::Clipboard); QApplication::clipboard()->setMimeData(mimeData,QClipboard::Clipboard);
} }
void CurvesPanel::cmCut() void Curves::cmCut()
{ {
if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Cut Curve. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Cut Curve. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
return; return;
@@ -750,7 +743,7 @@ void CurvesPanel::cmCut()
cmClear(false); cmClear(false);
} }
void CurvesPanel::cmDelete() void Curves::cmDelete()
{ {
if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Delete Curve. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Delete Curve. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
return; return;
@@ -759,43 +752,40 @@ 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();
updateItemModels();
emit modified(); emit modified();
} }
void CurvesPanel::cmInsert() void Curves::cmInsert()
{ {
memmove(&model->curves[selectedIndex + 1], &model->curves[selectedIndex], (CPN_MAX_CURVES - (selectedIndex + 1)) * sizeof(CurveData)); memmove(&model->curves[selectedIndex + 1], &model->curves[selectedIndex], (CPN_MAX_CURVES - (selectedIndex + 1)) * sizeof(CurveData));
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();
updateItemModels();
emit modified(); emit modified();
} }
void CurvesPanel::cmMoveDown() void Curves::cmMoveDown()
{ {
swapData(selectedIndex, selectedIndex + 1); swapData(selectedIndex, selectedIndex + 1);
} }
void CurvesPanel::cmMoveUp() void Curves::cmMoveUp()
{ {
swapData(selectedIndex, selectedIndex - 1); swapData(selectedIndex, selectedIndex - 1);
} }
void CurvesPanel::cmPaste() void Curves::cmPaste()
{ {
QByteArray data; QByteArray data;
if (hasClipboardData(&data)) { if (hasClipboardData(&data)) {
CurveData *cd = &model->curves[selectedIndex]; CurveData *cd = &model->curves[selectedIndex];
memcpy(cd, data.constData(), sizeof(CurveData)); memcpy(cd, data.constData(), sizeof(CurveData));
update(); update();
updateItemModels();
emit modified(); emit modified();
} }
} }
void CurvesPanel::swapData(int idx1, int idx2) void Curves::swapData(int idx1, int idx2)
{ {
if ((idx1 != idx2) && (!model->curves[idx1].isEmpty() || !model->curves[idx2].isEmpty())) { if ((idx1 != idx2) && (!model->curves[idx1].isEmpty() || !model->curves[idx2].isEmpty())) {
CurveData cdtmp = model->curves[idx2]; CurveData cdtmp = model->curves[idx2];
@@ -805,16 +795,10 @@ 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();
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)
{ {
+20 -43
View File
@@ -31,14 +31,13 @@
#include <QDir> #include <QDir>
TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware, QWidget * prevFocus, RawItemFilteredModel * rawSwitchFilteredModel): TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware, QWidget * prevFocus, RawSwitchFilterItemModel * switchModel):
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(rawSwitchFilteredModel, &RawItemFilteredModel::dataAboutToBeUpdated, this, &TimerPanel::onModelDataAboutToBeUpdated);
connect(rawSwitchFilteredModel, &RawItemFilteredModel::dataUpdateComplete, this, &TimerPanel::onModelDataUpdateComplete);
lock = true; lock = true;
@@ -49,10 +48,11 @@ 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(rawSwitchFilteredModel); ui->mode->setModel(switchModel);
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)));
@@ -94,7 +94,6 @@ 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;
@@ -166,23 +165,11 @@ void TimerPanel::on_name_editingFinished()
if (QString(timer.name) != ui->name->text()) { if (QString(timer.name) != ui->name->text()) {
int length = ui->name->maxLength(); int length = ui->name->maxLength();
strncpy(timer.name, ui->name->text().toLatin1(), length); strncpy(timer.name, ui->name->text().toLatin1(), length);
emit nameChanged();
emit modified(); emit modified();
} }
} }
} }
void TimerPanel::onModelDataAboutToBeUpdated()
{
lock = true;
}
void TimerPanel::onModelDataUpdateComplete()
{
update();
lock = false;
}
/******************************************************************************/ /******************************************************************************/
#define FAILSAFE_CHANNEL_HOLD 2000 #define FAILSAFE_CHANNEL_HOLD 2000
@@ -716,8 +703,8 @@ void ModulePanel::on_channelsCount_editingFinished()
{ {
if (!lock && module.channelsCount != ui->channelsCount->value()) { if (!lock && module.channelsCount != ui->channelsCount->value()) {
module.channelsCount = ui->channelsCount->value(); module.channelsCount = ui->channelsCount->value();
emit channelsRangeChanged();
update(); update();
emit channelsRangeChanged();
emit modified(); emit modified();
} }
} }
@@ -726,8 +713,8 @@ void ModulePanel::on_channelsStart_editingFinished()
{ {
if (!lock && module.channelsStart != (unsigned)ui->channelsStart->value() - 1) { if (!lock && module.channelsStart != (unsigned)ui->channelsStart->value() - 1) {
module.channelsStart = (unsigned)ui->channelsStart->value() - 1; module.channelsStart = (unsigned)ui->channelsStart->value() - 1;
emit channelsRangeChanged();
update(); update();
emit channelsRangeChanged();
emit modified(); emit modified();
} }
} }
@@ -991,20 +978,18 @@ void ModulePanel::onClearAccessRxClicked()
/******************************************************************************/ /******************************************************************************/
SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels): SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
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));
@@ -1077,16 +1062,18 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
} }
QWidget * prevFocus = ui->image; QWidget * prevFocus = ui->image;
RawSwitchFilterItemModel * swModel = new RawSwitchFilterItemModel(&generalSettings, &model, RawSwitch::TimersContext, this);
connect(this, &SetupPanel::updated, swModel, &RawSwitchFilterItemModel::update);
timersCount = firmware->getCapability(Timers); timersCount = firmware->getCapability(Timers);
for (int i = 0; i < CPN_MAX_TIMERS; i++) { for (int i = 0; i < CPN_MAX_TIMERS; i++) {
if (i < timersCount) { if (i < timersCount) {
timers[i] = new TimerPanel(this, model, model.timers[i], generalSettings, firmware, prevFocus, rawSwitchFilteredModel); timers[i] = new TimerPanel(this, model, model.timers[i], generalSettings, firmware, prevFocus, swModel);
ui->gridLayout->addWidget(timers[i], 1+i, 1); ui->gridLayout->addWidget(timers[i], 1+i, 1);
connect(timers[i], &TimerPanel::modified, this, &SetupPanel::modified); connect(timers[i], &TimerPanel::modified, this, &SetupPanel::modified);
connect(timers[i], &TimerPanel::nameChanged, this, &SetupPanel::onTimerNameChanged);
connect(this, &SetupPanel::updated, timers[i], &TimerPanel::update); connect(this, &SetupPanel::updated, timers[i], &TimerPanel::update);
connect(this, &SetupPanel::timerUpdated, timers[i], &TimerPanel::update);
prevFocus = timers[i]->getLastFocus(); prevFocus = timers[i]->getLastFocus();
// TODO more reliable method required // TODO more reliable method required
QLabel *label = findChild<QLabel *>(QString("label_timer%1").arg(i + 1)); QLabel *label = findChild<QLabel *>(QString("label_timer%1").arg(i + 1));
@@ -1640,7 +1627,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);
updateItemModels(); emit timerUpdated();
emit modified(); emit modified();
} }
@@ -1653,7 +1640,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);
} }
updateItemModels(); emit timerUpdated();
emit modified(); emit modified();
} }
@@ -1687,7 +1674,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);
updateItemModels(); emit timerUpdated();
emit modified(); emit modified();
} }
@@ -1700,7 +1687,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);
updateItemModels(); emit timerUpdated();
emit modified(); emit modified();
} }
@@ -1720,7 +1707,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));
updateItemModels(); emit timerUpdated();
emit modified(); emit modified();
} }
} }
@@ -1734,17 +1721,7 @@ 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);
updateItemModels(); emit timerUpdated();
emit modified(); emit modified();
} }
} }
void SetupPanel::onTimerNameChanged()
{
updateItemModels();
}
void SetupPanel::updateItemModels()
{
commonItemModels->update(CommonItemModels::RMO_TIMERS);
}
+4 -13
View File
@@ -26,8 +26,7 @@
constexpr char MIMETYPE_TIMER[] = "application/x-companion-timer"; constexpr char MIMETYPE_TIMER[] = "application/x-companion-timer";
class CommonItemModels; class RawSwitchFilterItemModel;
class RawItemFilteredModel;
namespace Ui { namespace Ui {
class Setup; class Setup;
@@ -40,7 +39,7 @@ class TimerPanel : public ModelPanel
Q_OBJECT Q_OBJECT
public: public:
TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware, QWidget *prevFocus, RawItemFilteredModel * switchModel); TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware, QWidget *prevFocus, RawSwitchFilterItemModel * switchModel);
virtual ~TimerPanel(); virtual ~TimerPanel();
virtual void update(); virtual void update();
@@ -51,11 +50,6 @@ class TimerPanel : public ModelPanel
void on_value_editingFinished(); void on_value_editingFinished();
void on_minuteBeep_toggled(bool checked); void on_minuteBeep_toggled(bool checked);
void on_name_editingFinished(); void on_name_editingFinished();
void onModelDataAboutToBeUpdated();
void onModelDataUpdateComplete();
signals:
void nameChanged();
private: private:
TimerData & timer; TimerData & timer;
@@ -131,7 +125,7 @@ class SetupPanel : public ModelPanel
Q_OBJECT Q_OBJECT
public: public:
SetupPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware, CommonItemModels * commonItemModels); SetupPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware);
virtual ~SetupPanel(); virtual ~SetupPanel();
virtual void update(); virtual void update();
@@ -139,6 +133,7 @@ class SetupPanel : public ModelPanel
signals: signals:
void extendedLimitsToggled(); void extendedLimitsToggled();
void updated(); void updated();
void timerUpdated();
private slots: private slots:
void on_name_editingFinished(); void on_name_editingFinished();
@@ -169,7 +164,6 @@ class SetupPanel : public ModelPanel
void cmTimerPaste(); void cmTimerPaste();
void cmTimerMoveDown(); void cmTimerMoveDown();
void cmTimerMoveUp(); void cmTimerMoveUp();
void onTimerNameChanged();
private: private:
Ui::Setup *ui; Ui::Setup *ui;
@@ -191,9 +185,6 @@ 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;
void updateItemModels();
}; };
#endif // _SETUP_H_ #endif // _SETUP_H_