aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/extcap_options_dialog.cpp
diff options
context:
space:
mode:
authorRoland Knall <roland.knall@br-automation.com>2015-12-29 15:35:43 +0100
committerStig Bjørlykke <stig@bjorlykke.org>2016-01-05 14:41:12 +0000
commitcfd5457ec0575be3b1b8726daf95fdc4da0e50fb (patch)
treefe3ff5d04d5f0c8d077831b3fb9135ae9520960e /ui/qt/extcap_options_dialog.cpp
parenta7e3ba03ce6eaeebc762322cb1691adeeda46ff8 (diff)
extcap: Add regular expression validation support
Regular expressions follow the Qt Regex syntax, which is formulated after the Perl Regex syntax. A more detailed overview of the possible rules can be found at: http://doc.qt.io/qt-4.8/qregexp.html If a required option is present, even the double-click on the interface will first start the options dialog (Qt only) Required fields are marked bold and put first in the dialog. Additionally if validation failes (which it will if a required field is kept empty, but also if a non-required textfield is violating the defined regex), the label of the field is marked with red. Change-Id: If04a1146d0dfa778332ab2a39122c7a6ee1e93d2 Reviewed-on: https://code.wireshark.org/review/12914 Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Diffstat (limited to 'ui/qt/extcap_options_dialog.cpp')
-rw-r--r--ui/qt/extcap_options_dialog.cpp108
1 files changed, 84 insertions, 24 deletions
diff --git a/ui/qt/extcap_options_dialog.cpp b/ui/qt/extcap_options_dialog.cpp
index 229c5e5843..e2b5c165ca 100644
--- a/ui/qt/extcap_options_dialog.cpp
+++ b/ui/qt/extcap_options_dialog.cpp
@@ -56,6 +56,7 @@
#include <ui/qt/extcap_argument.h>
#include <ui/qt/extcap_argument_file.h>
+#include <ui/qt/extcap_argument_multiselect.h>
ExtcapOptionsDialog::ExtcapOptionsDialog(QWidget *parent) :
QDialog(parent),
@@ -104,6 +105,9 @@ ExtcapOptionsDialog * ExtcapOptionsDialog::createForDevice(QString &dev_name, QW
resultDialog->updateWidgets();
+ /* mark required fields */
+ resultDialog->anyValueChanged();
+
return resultDialog;
}
@@ -122,18 +126,55 @@ void ExtcapOptionsDialog::on_buttonBox_accepted()
void ExtcapOptionsDialog::anyValueChanged()
{
- /* Guard, that only extcap arguments are given, which should be the case anyway */
- if ( dynamic_cast<ExtcapArgument *>(QObject::sender()) == NULL )
- return;
-
bool allowStart = true;
ExtcapArgumentList::const_iterator iter;
- for(iter = extcapArguments.constBegin(); iter != extcapArguments.constEnd() && allowStart; ++iter)
+ /* All arguments are being iterated, to ensure, that any error handling catches all arguments */
+ for(iter = extcapArguments.constBegin(); iter != extcapArguments.constEnd(); ++iter)
{
- if ( (*iter)->isRequired() && ! (*iter)->isValid() )
- allowStart = false;
+ /* The dynamic casts are necessary, because we come here using the Signal/Slot system
+ * of Qt, and -in short- Q_OBJECT classes cannot be multiple inherited. Another possibility
+ * would be to use Q_INTERFACE, but this causes way more nightmares, and we really just
+ * need here an explicit cast for the check functionality */
+ if ( dynamic_cast<ExtArgBool *>((*iter)) != NULL)
+ {
+ if ( ! ((ExtArgBool *)*iter)->isValid() )
+ allowStart = false;
+ }
+ else if ( dynamic_cast<ExtArgRadio *>((*iter)) != NULL)
+ {
+ if ( ! ((ExtArgRadio *)*iter)->isValid() )
+ allowStart = false;
+ }
+ else if ( dynamic_cast<ExtArgSelector *>((*iter)) != NULL)
+ {
+ if ( ! ((ExtArgSelector *)*iter)->isValid() )
+ allowStart = false;
+ }
+ else if ( dynamic_cast<ExtArgMultiSelect *>((*iter)) != NULL)
+ {
+ if ( ! ((ExtArgMultiSelect *)*iter)->isValid() )
+ allowStart = false;
+ }
+ else if ( dynamic_cast<ExtcapArgumentFileSelection *>((*iter)) != NULL)
+ {
+ if ( ! ((ExtcapArgumentFileSelection *)*iter)->isValid() )
+ allowStart = false;
+ }
+ else if ( dynamic_cast<ExtArgNumber *>((*iter)) != NULL)
+ {
+ if ( ! ((ExtArgNumber *)*iter)->isValid() )
+ allowStart = false;
+ }
+ else if ( dynamic_cast<ExtArgText *>((*iter)) != NULL)
+ {
+ if ( ! ((ExtArgText *)*iter)->isValid() )
+ allowStart = false;
+ }
+ else
+ if ( ! (*iter)->isValid() )
+ allowStart = false;
}
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(allowStart);
@@ -156,6 +197,9 @@ void ExtcapOptionsDialog::updateWidgets()
QGridLayout * layout = new QGridLayout();
+ ExtcapArgumentList required;
+ ExtcapArgumentList optional;
+
while ( walker != NULL )
{
item = g_list_first((GList *)(walker->data));
@@ -164,34 +208,50 @@ void ExtcapOptionsDialog::updateWidgets()
argument = ExtcapArgument::create((extcap_arg *)(item->data), device_defaults);
if ( argument != NULL )
{
- extcapArguments << argument;
+ if ( argument->isRequired() )
+ required << argument;
+ else
+ optional << argument;
- lblWidget = argument->createLabel((QWidget *)this);
- if ( lblWidget != NULL )
- {
- layout->addWidget(lblWidget, counter, 0, Qt::AlignVCenter);
- editWidget = argument->createEditor((QWidget *) this);
- if ( editWidget != NULL )
- {
- layout->addWidget(editWidget, counter, 1, Qt::AlignVCenter);
- }
+ }
+ item = item->next;
+ }
+ walker = walker->next;
+ }
- if ( argument->isRequired() && ! argument->isValid() )
- allowStart = false;
+ if ( required.length() > 0 )
+ extcapArguments << required;
- connect(argument, SIGNAL(valueChanged()), this, SLOT(anyValueChanged()));
+ if ( optional.length() > 0 )
+ extcapArguments << optional;
- counter++;
- }
+ ExtcapArgumentList::iterator iter = extcapArguments.begin();
+ while ( iter != extcapArguments.end() )
+ {
+ lblWidget = (*iter)->createLabel((QWidget *)this);
+ if ( lblWidget != NULL )
+ {
+ layout->addWidget(lblWidget, counter, 0, Qt::AlignVCenter);
+ editWidget = (*iter)->createEditor((QWidget *) this);
+ if ( editWidget != NULL )
+ {
+ layout->addWidget(editWidget, counter, 1, Qt::AlignVCenter);
}
- item = item->next;
+ if ( (*iter)->isRequired() && ! (*iter)->isValid() )
+ allowStart = false;
+
+ connect((*iter), SIGNAL(valueChanged()), this, SLOT(anyValueChanged()));
+
+ counter++;
}
- walker = walker->next;
+ ++iter;
}
if ( counter > 0 )
{
+ setStyleSheet ( "QLabel[isRequired=\"true\"] { font-weight: bold; } ");
+
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(allowStart);
ui->verticalLayout->addLayout(layout);