diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2017-11-14 13:44:27 +0100 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2017-11-16 06:10:47 +0000 |
commit | 665eb78729c91b4056b3e58af4407f51df603f55 (patch) | |
tree | ea8b34e991aa5e8ed634e86770b4e3629508f9e7 /ui | |
parent | 8ee4920c76fe690142482e22148f1e2f14cae01f (diff) |
Qt: Add UAT move up and down buttons
Add two new buttons for moving entries up and down in the list.
Change-Id: I90e5c5812754391651885e2a622148cecc124099
Reviewed-on: https://code.wireshark.org/review/24413
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/qt/models/uat_model.cpp | 16 | ||||
-rw-r--r-- | ui/qt/models/uat_model.h | 2 | ||||
-rw-r--r-- | ui/qt/uat_dialog.cpp | 51 | ||||
-rw-r--r-- | ui/qt/uat_dialog.h | 2 | ||||
-rw-r--r-- | ui/qt/uat_dialog.ui | 28 | ||||
-rw-r--r-- | ui/qt/uat_frame.cpp | 49 | ||||
-rw-r--r-- | ui/qt/uat_frame.h | 2 | ||||
-rw-r--r-- | ui/qt/uat_frame.ui | 30 |
8 files changed, 180 insertions, 0 deletions
diff --git a/ui/qt/models/uat_model.cpp b/ui/qt/models/uat_model.cpp index 37879ccdbb..c4e7a1fc60 100644 --- a/ui/qt/models/uat_model.cpp +++ b/ui/qt/models/uat_model.cpp @@ -382,6 +382,22 @@ bool UatModel::copyRow(int dst_row, int src_row) return true; } +bool UatModel::moveRow(int src_row, int dst_row) +{ + if (src_row < 0 || src_row >= rowCount() || dst_row < 0 || dst_row >= rowCount()) + return false; + + int dst = src_row < dst_row ? dst_row + 1 : dst_row; + + beginMoveRows(QModelIndex(), src_row, src_row, QModelIndex(), dst); + uat_move_index(uat_, src_row, dst_row); + record_errors.move(src_row, dst_row); + dirty_records.move(src_row, dst_row); + uat_->changed = TRUE; + endMoveRows(); + + return true; +} bool UatModel::hasErrors() const { diff --git a/ui/qt/models/uat_model.h b/ui/qt/models/uat_model.h index d68684e41c..cd7029a163 100644 --- a/ui/qt/models/uat_model.h +++ b/ui/qt/models/uat_model.h @@ -54,6 +54,8 @@ public: bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); bool copyRow(int dst_row, int src_row); + bool moveRow(int src_row, int dst_row); + bool hasErrors() const; void clearAll(); diff --git a/ui/qt/uat_dialog.cpp b/ui/qt/uat_dialog.cpp index 52a7891c9c..aab410705b 100644 --- a/ui/qt/uat_dialog.cpp +++ b/ui/qt/uat_dialog.cpp @@ -50,6 +50,8 @@ UatDialog::UatDialog(QWidget *parent, epan_uat *uat) : ui->deleteToolButton->setEnabled(false); ui->copyToolButton->setEnabled(false); + ui->moveUpToolButton->setEnabled(false); + ui->moveDownToolButton->setEnabled(false); ui->clearToolButton->setEnabled(false); ok_button_ = ui->buttonBox->button(QDialogButtonBox::Ok); help_button_ = ui->buttonBox->button(QDialogButtonBox::Help); @@ -58,6 +60,8 @@ UatDialog::UatDialog(QWidget *parent, epan_uat *uat) : ui->newToolButton->setAttribute(Qt::WA_MacSmallSize, true); ui->deleteToolButton->setAttribute(Qt::WA_MacSmallSize, true); ui->copyToolButton->setAttribute(Qt::WA_MacSmallSize, true); + ui->moveUpToolButton->setAttribute(Qt::WA_MacSmallSize, true); + ui->moveDownToolButton->setAttribute(Qt::WA_MacSmallSize, true); ui->clearToolButton->setAttribute(Qt::WA_MacSmallSize, true); ui->pathLabel->setAttribute(Qt::WA_MacSmallSize, true); #endif @@ -147,6 +151,17 @@ void UatDialog::modelDataChanged(const QModelIndex &topLeft) void UatDialog::modelRowsRemoved() { const QModelIndex ¤t = ui->uatTreeView->currentIndex(); + + // Because currentItemChanged() is called before the row is removed from the model + // we also need to check for button enabling here. + if (current.isValid()) { + ui->moveUpToolButton->setEnabled(current.row() != 0); + ui->moveDownToolButton->setEnabled(current.row() != (uat_model_->rowCount() - 1)); + } else { + ui->moveUpToolButton->setEnabled(false); + ui->moveDownToolButton->setEnabled(false); + } + checkForErrorHint(current, QModelIndex()); ok_button_->setEnabled(!uat_model_->hasErrors()); } @@ -156,6 +171,8 @@ void UatDialog::modelRowsReset() ui->deleteToolButton->setEnabled(false); ui->clearToolButton->setEnabled(false); ui->copyToolButton->setEnabled(false); + ui->moveUpToolButton->setEnabled(false); + ui->moveDownToolButton->setEnabled(false); } @@ -167,10 +184,14 @@ void UatDialog::on_uatTreeView_currentItemChanged(const QModelIndex ¤t, co ui->deleteToolButton->setEnabled(true); ui->clearToolButton->setEnabled(true); ui->copyToolButton->setEnabled(true); + ui->moveUpToolButton->setEnabled(current.row() != 0); + ui->moveDownToolButton->setEnabled(current.row() != (uat_model_->rowCount() - 1)); } else { ui->deleteToolButton->setEnabled(false); ui->clearToolButton->setEnabled(false); ui->copyToolButton->setEnabled(false); + ui->moveUpToolButton->setEnabled(false); + ui->moveDownToolButton->setEnabled(false); } checkForErrorHint(current, previous); @@ -262,6 +283,36 @@ void UatDialog::on_copyToolButton_clicked() addRecord(true); } +void UatDialog::on_moveUpToolButton_clicked() +{ + const QModelIndex ¤t = ui->uatTreeView->currentIndex(); + int current_row = current.row(); + if (uat_model_ && current.isValid() && current_row > 0) { + if (!uat_model_->moveRow(current_row, current_row - 1)) { + qDebug() << "Failed to move row up"; + return; + } + current_row--; + ui->moveUpToolButton->setEnabled(current_row > 0); + ui->moveDownToolButton->setEnabled(current_row < (uat_model_->rowCount() - 1)); + } +} + +void UatDialog::on_moveDownToolButton_clicked() +{ + const QModelIndex ¤t = ui->uatTreeView->currentIndex(); + int current_row = current.row(); + if (uat_model_ && current.isValid() && current_row < (uat_model_->rowCount() - 1)) { + if (!uat_model_->moveRow(current_row, current_row + 1)) { + qDebug() << "Failed to move row down"; + return; + } + current_row++; + ui->moveUpToolButton->setEnabled(current_row > 0); + ui->moveDownToolButton->setEnabled(current_row < (uat_model_->rowCount() - 1)); + } +} + void UatDialog::on_clearToolButton_clicked() { if (uat_model_) { diff --git a/ui/qt/uat_dialog.h b/ui/qt/uat_dialog.h index 6eba0cd144..bd1a0ceb89 100644 --- a/ui/qt/uat_dialog.h +++ b/ui/qt/uat_dialog.h @@ -59,6 +59,8 @@ private slots: void on_newToolButton_clicked(); void on_deleteToolButton_clicked(); void on_copyToolButton_clicked(); + void on_moveUpToolButton_clicked(); + void on_moveDownToolButton_clicked(); void on_clearToolButton_clicked(); void on_buttonBox_helpRequested(); diff --git a/ui/qt/uat_dialog.ui b/ui/qt/uat_dialog.ui index c867b9656a..f7013add88 100644 --- a/ui/qt/uat_dialog.ui +++ b/ui/qt/uat_dialog.ui @@ -78,6 +78,34 @@ </widget> </item> <item> + <widget class="QToolButton" name="moveUpToolButton"> + <property name="toolTip"> + <string>Move entry up.</string> + </property> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset resource="../../image/toolbar.qrc"> + <normaloff>:/stock/arrow_up.png</normaloff>:/stock/arrow_up.png</iconset> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="moveDownToolButton"> + <property name="toolTip"> + <string>Move entry down.</string> + </property> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset resource="../../image/toolbar.qrc"> + <normaloff>:/stock/arrow_down.png</normaloff>:/stock/arrow_down.png</iconset> + </property> + </widget> + </item> + <item> <widget class="QToolButton" name="clearToolButton"> <property name="toolTip"> <string>Clear all entries.</string> diff --git a/ui/qt/uat_frame.cpp b/ui/qt/uat_frame.cpp index c9c493f8a1..459f32a039 100644 --- a/ui/qt/uat_frame.cpp +++ b/ui/qt/uat_frame.cpp @@ -53,6 +53,8 @@ UatFrame::UatFrame(QWidget *parent) : ui->newToolButton->setAttribute(Qt::WA_MacSmallSize, true); ui->deleteToolButton->setAttribute(Qt::WA_MacSmallSize, true); ui->copyToolButton->setAttribute(Qt::WA_MacSmallSize, true); + ui->moveUpToolButton->setAttribute(Qt::WA_MacSmallSize, true); + ui->moveDownToolButton->setAttribute(Qt::WA_MacSmallSize, true); ui->clearToolButton->setAttribute(Qt::WA_MacSmallSize, true); ui->pathLabel->setAttribute(Qt::WA_MacSmallSize, true); #endif @@ -198,10 +200,14 @@ void UatFrame::on_uatTreeView_currentItemChanged(const QModelIndex ¤t, con ui->deleteToolButton->setEnabled(true); ui->clearToolButton->setEnabled(true); ui->copyToolButton->setEnabled(true); + ui->moveUpToolButton->setEnabled(current.row() != 0); + ui->moveDownToolButton->setEnabled(current.row() != (uat_model_->rowCount() - 1)); } else { ui->deleteToolButton->setEnabled(false); ui->clearToolButton->setEnabled(false); ui->copyToolButton->setEnabled(false); + ui->moveUpToolButton->setEnabled(false); + ui->moveDownToolButton->setEnabled(false); } checkForErrorHint(current, previous); @@ -217,6 +223,17 @@ void UatFrame::modelDataChanged(const QModelIndex &topLeft) void UatFrame::modelRowsRemoved() { const QModelIndex ¤t = ui->uatTreeView->currentIndex(); + + // Because currentItemChanged() is called before the row is removed from the model + // we also need to check for button enabling here. + if (current.isValid()) { + ui->moveUpToolButton->setEnabled(current.row() != 0); + ui->moveDownToolButton->setEnabled(current.row() != (uat_model_->rowCount() - 1)); + } else { + ui->moveUpToolButton->setEnabled(false); + ui->moveDownToolButton->setEnabled(false); + } + checkForErrorHint(current, QModelIndex()); } @@ -225,6 +242,8 @@ void UatFrame::modelRowsReset() ui->deleteToolButton->setEnabled(false); ui->clearToolButton->setEnabled(false); ui->copyToolButton->setEnabled(false); + ui->moveUpToolButton->setEnabled(false); + ui->moveDownToolButton->setEnabled(false); } // If the current field has errors, show them. @@ -291,6 +310,36 @@ void UatFrame::on_copyToolButton_clicked() addRecord(true); } +void UatFrame::on_moveUpToolButton_clicked() +{ + const QModelIndex ¤t = ui->uatTreeView->currentIndex(); + int current_row = current.row(); + if (uat_model_ && current.isValid() && current_row > 0) { + if (!uat_model_->moveRow(current_row, current_row - 1)) { + qDebug() << "Failed to move row up"; + return; + } + current_row--; + ui->moveUpToolButton->setEnabled(current_row > 0); + ui->moveDownToolButton->setEnabled(current_row < (uat_model_->rowCount() - 1)); + } +} + +void UatFrame::on_moveDownToolButton_clicked() +{ + const QModelIndex ¤t = ui->uatTreeView->currentIndex(); + int current_row = current.row(); + if (uat_model_ && current.isValid() && current_row < (uat_model_->rowCount() - 1)) { + if (!uat_model_->moveRow(current_row, current_row + 1)) { + qDebug() << "Failed to move row down"; + return; + } + current_row++; + ui->moveUpToolButton->setEnabled(current_row > 0); + ui->moveDownToolButton->setEnabled(current_row < (uat_model_->rowCount() - 1)); + } +} + void UatFrame::on_clearToolButton_clicked() { if (uat_model_) { diff --git a/ui/qt/uat_frame.h b/ui/qt/uat_frame.h index c86d0ab2f4..404ca42b62 100644 --- a/ui/qt/uat_frame.h +++ b/ui/qt/uat_frame.h @@ -65,6 +65,8 @@ private slots: void on_newToolButton_clicked(); void on_deleteToolButton_clicked(); void on_copyToolButton_clicked(); + void on_moveUpToolButton_clicked(); + void on_moveDownToolButton_clicked(); void on_clearToolButton_clicked(); }; diff --git a/ui/qt/uat_frame.ui b/ui/qt/uat_frame.ui index b03b4e7965..6a22bbff65 100644 --- a/ui/qt/uat_frame.ui +++ b/ui/qt/uat_frame.ui @@ -96,6 +96,36 @@ </widget> </item> <item> + <widget class="QToolButton" name="moveUpToolButton"> + <property name="toolTip"> + <string>Move entry up.</string> + </property> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset resource="../../image/toolbar.qrc"> + <normaloff>:/stock/arrow_up.png</normaloff>:/stock/arrow_up.png + </iconset> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="moveDownToolButton"> + <property name="toolTip"> + <string>Move entry down.</string> + </property> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset resource="../../image/toolbar.qrc"> + <normaloff>:/stock/arrow_down.png</normaloff>:/stock/arrow_down.png + </iconset> + </property> + </widget> + </item> + <item> <widget class="QToolButton" name="clearToolButton"> <property name="toolTip"> <string>Clear all entries.</string> |