Skip to content

Commit d0eb492

Browse files
author
Ананьев Александр
committed
Correct ByteOrder icons updating
1 parent 07f9efb commit d0eb492

2 files changed

Lines changed: 36 additions & 6 deletions

File tree

omodsim/mainwindow.cpp

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ MainWindow::MainWindow(QWidget *parent)
7070
connect(dispatcher, &QAbstractEventDispatcher::awake, this, &MainWindow::on_awake);
7171

7272
connect(ui->mdiArea, &QMdiArea::subWindowActivated, this, &MainWindow::updateMenuWindow);
73+
connect(_dataSimulator.get(), &DataSimulator::dataSimulated, this, &MainWindow::on_dataSimulated);
7374
connect(&_mbMultiServer, &ModbusMultiServer::connectionError, this, &MainWindow::on_connectionError);
7475

7576
ui->actionNew->trigger();
@@ -148,6 +149,7 @@ bool MainWindow::eventFilter(QObject * obj, QEvent * e)
148149
case QEvent::Close:
149150
_windowActionList->removeWindow(qobject_cast<QMdiSubWindow*>(obj));
150151
break;
152+
break;
151153
default:
152154
qt_noop();
153155
}
@@ -229,6 +231,7 @@ void MainWindow::on_actionNew_triggered()
229231
auto frm = createMdiChild(++_windowCounter);
230232

231233
if(cur) {
234+
frm->setByteOrder(cur->byteOrder());
232235
frm->setDisplayMode(cur->displayMode());
233236
frm->setDataDisplayMode(cur->dataDisplayMode());
234237

@@ -679,6 +682,21 @@ void MainWindow::on_connectionError(const QString& error)
679682
QMessageBox::warning(this, windowTitle(), error);
680683
}
681684

685+
///
686+
/// \brief MainWindow::on_dataSimulated
687+
/// \param mode
688+
/// \param type
689+
/// \param addr
690+
/// \param value
691+
///
692+
void MainWindow::on_dataSimulated(DataDisplayMode mode, QModbusDataUnit::RegisterType type, quint16 addr, QVariant value)
693+
{
694+
auto frm = currentMdiChild();
695+
const auto order = (frm)? frm->byteOrder() : ByteOrder::LittleEndian;
696+
697+
_mbMultiServer.writeRegister(type, { addr, value, mode, order });
698+
}
699+
682700
///
683701
/// \brief MainWindow::updateMenuWindow
684702
///
@@ -822,17 +840,28 @@ FormModSim* MainWindow::createMdiChild(int id)
822840
wnd->installEventFilter(this);
823841
wnd->setAttribute(Qt::WA_DeleteOnClose, true);
824842

825-
connect(frm, &FormModSim::showed, this, [this, wnd]
826-
{
827-
windowActivate(wnd);
828-
});
829-
830-
connect(frm, &FormModSim::byteOrderChanged, this, [this](ByteOrder order)
843+
auto updateIcons = [this](ByteOrder order)
831844
{
832845
switch(order){
833846
case ByteOrder::BigEndian: ui->actionByteOrder->setIcon(_icoBigEndian); break;
834847
case ByteOrder::LittleEndian: ui->actionByteOrder->setIcon(_icoLittleEndian); break;
835848
}
849+
};
850+
851+
connect(wnd, &QMdiSubWindow::windowStateChanged, this, [frm, updateIcons](Qt::WindowStates, Qt::WindowStates newState)
852+
{
853+
if(newState == Qt::WindowActive)
854+
updateIcons(frm->byteOrder());
855+
});
856+
857+
connect(frm, &FormModSim::byteOrderChanged, this, [updateIcons](ByteOrder order)
858+
{
859+
updateIcons(order);
860+
});
861+
862+
connect(frm, &FormModSim::showed, this, [this, wnd]
863+
{
864+
windowActivate(wnd);
836865
});
837866

838867
_windowActionList->addWindow(wnd);

omodsim/mainwindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ private slots:
8888
void on_actionAbout_triggered();
8989

9090
void on_connectionError(const QString& error);
91+
void on_dataSimulated(DataDisplayMode mode, QModbusDataUnit::RegisterType type, quint16 addr, QVariant value);
9192

9293
void updateMenuWindow();
9394
void openFile(const QString& filename);

0 commit comments

Comments
 (0)