diff --git a/src/PanelCommandTable.cpp b/src/PanelCommandTable.cpp index 441cd440a45bc705c1d0156c861791aaa2009c5e..7b84dbc86cc6b7d8958d1eb555fc85f686fbf3d3 100644 --- a/src/PanelCommandTable.cpp +++ b/src/PanelCommandTable.cpp @@ -1,7 +1,6 @@ #include "PanelCommandTable.h" #include <QBoxLayout> #include <QHeaderView> -#include <iostream> PanelCommandTable::PanelCommandTable(ControlModel *_cM) { @@ -109,7 +108,14 @@ void PanelCommandTable::onStopButton() void PanelCommandTable::updateTable(std::shared_ptr<ICommand> _icom) { - QModelIndex index = tM->onChange(_icom); + tM->onChange(_icom); + + int row = cM->getCommandList().getPos(_icom) - 1; + QModelIndex index; + if (_icom) + index = tM->index(row, 0); + else + index = tM->index(- 1, 0); lSM->setCurrentIndex(index, QItemSelectionModel::SelectionFlag::ClearAndSelect | QItemSelectionModel::SelectionFlag::Rows); } diff --git a/src/TableCommandModel.cpp b/src/TableCommandModel.cpp index 890b0bd558fdd01d2235c134e17e4510c3cff06c..7b979773efde6c5589ddf2472bf2f0ab38008c6a 100644 --- a/src/TableCommandModel.cpp +++ b/src/TableCommandModel.cpp @@ -74,9 +74,8 @@ QVariant TableCommandModel::headerData(int section, Qt::Orientation orientation, return QVariant(); } -QModelIndex TableCommandModel::onChange(std::shared_ptr<ICommand> _icom) +void TableCommandModel::onChange(std::shared_ptr<ICommand> _icom) { - QModelIndex ret; if (_icom != nullptr) { //update only one command (and its neighbours) @@ -89,19 +88,11 @@ QModelIndex TableCommandModel::onChange(std::shared_ptr<ICommand> _icom) emit(dataChanged(index, index)); } } - ret = createIndex(row, 0, nullptr); } - else - { - ret = createIndex(- 1, 0, nullptr); - } - static int rowsBefore = 0; int rowsNow = rowCount(); if (rowsNow != rowsBefore) { - emit(layoutAboutToBeChanged()); emit(layoutChanged()); rowsBefore = rowsNow; } - return ret; } diff --git a/src/TableCommandModel.h b/src/TableCommandModel.h index 7dbb8b502c256ecbbdc3fa025147c7630a6ed535..3b415bb5f935557938d9c8e41d5552d648ac50de 100644 --- a/src/TableCommandModel.h +++ b/src/TableCommandModel.h @@ -8,6 +8,7 @@ class TableCommandModel : public QAbstractTableModel private: std::array<QString, 3> headerNames = {"No.", "Command", "Configuration"}; CommandList *cL; + int rowsBefore = 0; public: TableCommandModel(CommandList *_list) { cL = _list; } @@ -20,5 +21,5 @@ public: QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) { return createIndex(row, column, nullptr); } QModelIndex parent(const QModelIndex &index) { return QModelIndex(); } - QModelIndex onChange(std::shared_ptr<ICommand> _icom); + void onChange(std::shared_ptr<ICommand> _icom); };