-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy patheditcmddialog.cpp
More file actions
78 lines (66 loc) · 2.71 KB
/
Copy patheditcmddialog.cpp
File metadata and controls
78 lines (66 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "editcmddialog.h"
#include "ui_editcmddialog.h"
#include <QAction>
#include <QAbstractItemView>
#include <QApplication>
#include <algorithm>
EditCMDdialog::EditCMDdialog(TableModel *cmdTable, QWidget *parent) :
QDialog(parent),
ui(new Ui::EditCMDdialog)
{
ui->setupUi(this);
this->cmdTable = cmdTable;
ui->tableView->setModel(cmdTable);
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableView->setSelectionMode(QAbstractItemView::ExtendedSelection);
connect(ui->pushButton_add,SIGNAL(pressed()),this,SLOT(Append()));
connect(ui->pushButton_remove,SIGNAL(pressed()),this,SLOT(Remove()));
// Single QAction for Delete — do not also add QShortcut (Ambiguous shortcut overload)
QAction *deleteAction = new QAction(tr("Delete"), this);
deleteAction->setShortcut(QKeySequence::Delete);
deleteAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
ui->tableView->addAction(deleteAction);
connect(deleteAction, SIGNAL(triggered()), this, SLOT(Remove()));
ui->comboBox_type->addItem(tr("45 Single point command"));
ui->comboBox_type->addItem(tr("46 Double point command"));
ui->comboBox_type->addItem(tr("47 Regulating step command"));
ui->comboBox_type->addItem(tr("48 Setpoint command, normalized value"));
ui->comboBox_type->addItem(tr("49 Setpoint command, scaled value"));
ui->comboBox_type->addItem(tr("50 Setpoint command, short floating point value"));
ui->comboBox_type->addItem(tr("51 Bit string 32 bit"));
}
EditCMDdialog::~EditCMDdialog()
{
delete ui;
}
void EditCMDdialog::Append()
{
uint16_t ioa = ui->lineEdit_IOA->text().toUInt();
uint type = ui->comboBox_type->currentIndex()+45;
QString descr = ui->lineEdit_desc->text();
cmdTable->updateSignal(CIECSignal(ioa,type,descr),true,true);
}
void EditCMDdialog::Remove()
{
// Qt6: QAbstractItemView::state() is protected — detect in-cell editor via focus
QWidget *fw = QApplication::focusWidget();
if (fw && fw != ui->tableView && ui->tableView->isAncestorOf(fw))
return;
QItemSelectionModel *pSelection = ui->tableView->selectionModel();
if (!pSelection)
return;
QModelIndexList indexes = pSelection->selectedRows();
if (indexes.isEmpty())
indexes = pSelection->selectedIndexes();
if (indexes.isEmpty() && pSelection->currentIndex().isValid())
indexes.append(pSelection->currentIndex());
QList<int> rows;
foreach (QModelIndex index, indexes)
{
if (index.isValid() && !rows.contains(index.row()))
rows.append(index.row());
}
std::sort(rows.begin(), rows.end());
for (int i = rows.count() - 1; i >= 0; --i)
cmdTable->removeRow(rows[i]);
}