diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2023-06-12 11:48:19 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-06-13 16:36:16 +0000 |
commit | ee6995b60ea32106be07ebf607fca71140cdef5f (patch) | |
tree | b59910ead1e9d3431b6317d36a60c705ea04a761 | |
parent | 70bd2904c2a58c7ed1366015a4bbda75df03190c (diff) |
Simple CoAP Client: extend options dialog
Add possibility to remove individual entries from the options table.
Also change the selection behavior of the table to allow selection of
individual rows only. This makes sense, because we do not allow to
change values in the already-added entries anyway, and row-selection
makes more sense when deleting entries.
Task-number: QTBUG-113858
Change-Id: Ica56c697c79c758d473f647831afc793c7ca35b0
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit e613acc6764355dd524a6d0bf601234ccdf3bb02)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | examples/coap/simplecoapclient/optiondialog.cpp | 13 | ||||
-rw-r--r-- | examples/coap/simplecoapclient/optiondialog.h | 1 | ||||
-rw-r--r-- | examples/coap/simplecoapclient/optiondialog.ui | 16 |
3 files changed, 30 insertions, 0 deletions
diff --git a/examples/coap/simplecoapclient/optiondialog.cpp b/examples/coap/simplecoapclient/optiondialog.cpp index 152d81e..1f76f98 100644 --- a/examples/coap/simplecoapclient/optiondialog.cpp +++ b/examples/coap/simplecoapclient/optiondialog.cpp @@ -9,6 +9,10 @@ OptionDialog::OptionDialog(QWidget *parent) : ui(new Ui::OptionDialog) { ui->setupUi(this); + connect(ui->tableWidget, &QTableWidget::itemSelectionChanged, this, [this]() { + const auto selection = ui->tableWidget->selectedItems(); + ui->removeButton->setEnabled(!selection.isEmpty()); + }); fillOptions(); @@ -44,6 +48,15 @@ void OptionDialog::on_addButton_clicked() ui->tableWidget->setItem(rowCount, 1, valueItem); } +void OptionDialog::on_removeButton_clicked() +{ + const auto idx = ui->tableWidget->currentRow(); + if (idx >= 0 && idx < ui->tableWidget->rowCount()) { + ui->tableWidget->removeRow(idx); + m_options.removeAt(idx); + } +} + void OptionDialog::on_clearButton_clicked() { m_options.clear(); diff --git a/examples/coap/simplecoapclient/optiondialog.h b/examples/coap/simplecoapclient/optiondialog.h index f5d306f..e44992b 100644 --- a/examples/coap/simplecoapclient/optiondialog.h +++ b/examples/coap/simplecoapclient/optiondialog.h @@ -26,6 +26,7 @@ public: private slots: void on_addButton_clicked(); void on_clearButton_clicked(); + void on_removeButton_clicked(); private: void fillOptions(); diff --git a/examples/coap/simplecoapclient/optiondialog.ui b/examples/coap/simplecoapclient/optiondialog.ui index 7313b32..174efdc 100644 --- a/examples/coap/simplecoapclient/optiondialog.ui +++ b/examples/coap/simplecoapclient/optiondialog.ui @@ -50,6 +50,12 @@ </item> <item> <widget class="QTableWidget" name="tableWidget"> + <property name="selectionMode"> + <enum>QAbstractItemView::SingleSelection</enum> + </property> + <property name="selectionBehavior"> + <enum>QAbstractItemView::SelectRows</enum> + </property> <property name="columnCount"> <number>2</number> </property> @@ -91,6 +97,16 @@ </widget> </item> <item> + <widget class="QPushButton" name="removeButton"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Remove</string> + </property> + </widget> + </item> + <item> <widget class="QPushButton" name="clearButton"> <property name="text"> <string>Clear</string> |