Add button in Qt UAT dialog/frame to remove all UAT entries at once.

Change-Id: If5a172cd69beeb0b9a22eb7f6b9e7cb25f350b49
Reviewed-on: https://code.wireshark.org/review/23968
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Michael Mann 2017-10-17 13:57:04 -04:00
parent 4e3114d01d
commit 61380f9504
12 changed files with 92 additions and 0 deletions

View File

@ -3990,3 +3990,5 @@ Martin Pool <mbp[AT]sourcefrog.net>.
Emanuel Eichhammer <support[AT]qcustomplot.com> granted permission
to use QCustomPlot.
Some icons made by Freepik, http://www.freepik.com from https://www.flaticon.com

View File

@ -61,3 +61,5 @@ plus-8.png macOS style add / remove icons. Created by Peter Hosey.
minus-8.png Released under CC-PD.
copy-8.png macOS style copy icon.
delete_list.png by Freepik, http://www.freepik.com from https://www.flaticon.com

BIN
image/delete_list.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 564 B

View File

@ -7,6 +7,7 @@
<file>minus-8.png</file>
<file>plus-8.png</file>
<file>copy-8.png</file>
<file>delete_list.png</file>
</qresource>
<qresource prefix="/icons">
<file>toolbar/14x14/x-capture-comment-update.png</file>

View File

@ -333,6 +333,20 @@ bool UatModel::removeRows(int row, int count, const QModelIndex &/*parent*/)
return true;
}
void UatModel::clearAll()
{
if (rowCount() < 1)
return;
beginResetModel();
uat_clear(uat_);
record_errors.clear();
dirty_records.clear();
uat_->changed = TRUE;
endResetModel();
}
bool UatModel::copyRow(int dst_row, int src_row)
{
if (src_row < 0 || src_row >= rowCount() || dst_row < 0 || dst_row >= rowCount()) {

View File

@ -55,6 +55,7 @@ public:
bool copyRow(int dst_row, int src_row);
bool hasErrors() const;
void clearAll();
QModelIndex findRowForColumnContent(QVariant columnContent, int columnToCheckAgainst, int role = Qt::DisplayRole);

View File

@ -50,6 +50,7 @@ UatDialog::UatDialog(QWidget *parent, epan_uat *uat) :
ui->deleteToolButton->setEnabled(false);
ui->copyToolButton->setEnabled(false);
ui->clearToolButton->setEnabled(false);
ok_button_ = ui->buttonBox->button(QDialogButtonBox::Ok);
help_button_ = ui->buttonBox->button(QDialogButtonBox::Help);
@ -57,6 +58,7 @@ 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->clearToolButton->setAttribute(Qt::WA_MacSmallSize, true);
ui->pathLabel->setAttribute(Qt::WA_MacSmallSize, true);
#endif
@ -119,6 +121,8 @@ void UatDialog::setUat(epan_uat *uat)
this, SLOT(modelDataChanged(QModelIndex)));
connect(uat_model_, SIGNAL(rowsRemoved(QModelIndex, int, int)),
this, SLOT(modelRowsRemoved()));
connect(uat_model_, SIGNAL(modelReset()), this, SLOT(modelRowsReset()));
ok_button_->setEnabled(!uat_model_->hasErrors());
if (uat_->help && strlen(uat_->help) > 0) {
@ -147,15 +151,25 @@ void UatDialog::modelRowsRemoved()
ok_button_->setEnabled(!uat_model_->hasErrors());
}
void UatDialog::modelRowsReset()
{
ui->deleteToolButton->setEnabled(false);
ui->clearToolButton->setEnabled(false);
ui->copyToolButton->setEnabled(false);
}
// Invoked when a different field is selected. Note: when selecting a different
// field after editing, this event is triggered after modelDataChanged.
void UatDialog::on_uatTreeView_currentItemChanged(const QModelIndex &current, const QModelIndex &previous)
{
if (current.isValid()) {
ui->deleteToolButton->setEnabled(true);
ui->clearToolButton->setEnabled(true);
ui->copyToolButton->setEnabled(true);
} else {
ui->deleteToolButton->setEnabled(false);
ui->clearToolButton->setEnabled(false);
ui->copyToolButton->setEnabled(false);
}
@ -248,6 +262,13 @@ void UatDialog::on_copyToolButton_clicked()
addRecord(true);
}
void UatDialog::on_clearToolButton_clicked()
{
if (uat_model_) {
uat_model_->clearAll();
}
}
void UatDialog::applyChanges()
{
if (!uat_) return;

View File

@ -52,12 +52,14 @@ public:
private slots:
void modelDataChanged(const QModelIndex &topLeft);
void modelRowsRemoved();
void modelRowsReset();
void on_uatTreeView_currentItemChanged(const QModelIndex &current, const QModelIndex &previous);
void acceptChanges();
void rejectChanges();
void on_newToolButton_clicked();
void on_deleteToolButton_clicked();
void on_copyToolButton_clicked();
void on_clearToolButton_clicked();
void on_buttonBox_helpRequested();
private:

View File

@ -77,6 +77,21 @@
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="clearToolButton">
<property name="toolTip">
<string>Clear all entries.</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../image/toolbar.qrc">
<normaloff>:/stock/delete_list.png</normaloff>:/stock/delete_list.png
</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">

View File

@ -53,6 +53,7 @@ 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->clearToolButton->setAttribute(Qt::WA_MacSmallSize, true);
ui->pathLabel->setAttribute(Qt::WA_MacSmallSize, true);
#endif
@ -110,6 +111,7 @@ void UatFrame::setUat(epan_uat *uat)
this, SLOT(modelDataChanged(QModelIndex)));
connect(uat_model_, SIGNAL(rowsRemoved(QModelIndex, int, int)),
this, SLOT(modelRowsRemoved()));
connect(uat_model_, SIGNAL(modelReset()), this, SLOT(modelRowsReset()));
}
setWindowTitle(title);
@ -193,9 +195,11 @@ void UatFrame::on_uatTreeView_currentItemChanged(const QModelIndex &current, con
{
if (current.isValid()) {
ui->deleteToolButton->setEnabled(true);
ui->clearToolButton->setEnabled(true);
ui->copyToolButton->setEnabled(true);
} else {
ui->deleteToolButton->setEnabled(false);
ui->clearToolButton->setEnabled(false);
ui->copyToolButton->setEnabled(false);
}
@ -215,6 +219,13 @@ void UatFrame::modelRowsRemoved()
checkForErrorHint(current, QModelIndex());
}
void UatFrame::modelRowsReset()
{
ui->deleteToolButton->setEnabled(false);
ui->clearToolButton->setEnabled(false);
ui->copyToolButton->setEnabled(false);
}
// If the current field has errors, show them.
// Otherwise if the row has not changed, but the previous field has errors, show them.
// Otherwise pick the first error in the current row.
@ -279,6 +290,12 @@ void UatFrame::on_copyToolButton_clicked()
addRecord(true);
}
void UatFrame::on_clearToolButton_clicked()
{
if (uat_model_) {
uat_model_->clearAll();
}
}
/*
* Editor modelines
*

View File

@ -60,10 +60,12 @@ private:
private slots:
void modelDataChanged(const QModelIndex &topLeft);
void modelRowsRemoved();
void modelRowsReset();
void on_uatTreeView_currentItemChanged(const QModelIndex &current, const QModelIndex &previous);
void on_newToolButton_clicked();
void on_deleteToolButton_clicked();
void on_copyToolButton_clicked();
void on_clearToolButton_clicked();
};
#endif // UAT_FRAME_H

View File

@ -95,6 +95,21 @@
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="clearToolButton">
<property name="toolTip">
<string>Clear all entries.</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../image/toolbar.qrc">
<normaloff>:/stock/delete_list.png</normaloff>:/stock/delete_list.png
</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">