aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorRoland Knall <roland.knall@br-automation.com>2018-04-20 14:59:14 +0200
committerRoland Knall <rknall@gmail.com>2018-05-08 10:31:38 +0000
commit0af6ba1a53b604dc294c08c6dfc4dde17b4ea506 (patch)
tree0732809821a94b3f94ab0957fa2887e5221feb3c /ui
parent02a67d4e1e0828f1df17992330d9c4e02db95de5 (diff)
extcap: Group arguments
Group arguments together to better present them, as well as to have the possibility to better facilitate settings categories. The order of tabs is defined by the numbering of arguments and their appearance. If no tab can be found or no group has been defined for the argument, a default tab will be added. Change-Id: I032881193e09d4ad5d65c9f73fede87695acdace Reviewed-on: https://code.wireshark.org/review/27054 Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/extcap_argument.cpp19
-rw-r--r--ui/qt/extcap_argument.h4
-rw-r--r--ui/qt/extcap_options_dialog.cpp163
3 files changed, 159 insertions, 27 deletions
diff --git a/ui/qt/extcap_argument.cpp b/ui/qt/extcap_argument.cpp
index 1c46f0d857..e06cbbbc90 100644
--- a/ui/qt/extcap_argument.cpp
+++ b/ui/qt/extcap_argument.cpp
@@ -594,7 +594,7 @@ void ExtcapValue::setChildren(ExtcapValueList children)
}
ExtcapArgument::ExtcapArgument(QObject *parent) :
- QObject(parent), _argument(0), _label(0),
+ QObject(parent), _argument(0), _label(0), _number(0),
label_style(QString("QLabel { color: %1; }"))
{
}
@@ -603,6 +603,8 @@ ExtcapArgument::ExtcapArgument(extcap_arg * argument, QObject *parent) :
QObject(parent), _argument(argument), _label(0),
label_style(QString("QLabel { color: %1; }"))
{
+ _number = argument->arg_num;
+
if ( _argument->values != 0 )
{
ExtcapValueList elements = loadValues(QString(""));
@@ -615,6 +617,8 @@ ExtcapArgument::ExtcapArgument(const ExtcapArgument &obj) :
QObject(obj.parent()), _argument(obj._argument), _label(0),
label_style(QString("QLabel { color: %1; }"))
{
+ _number = obj._argument->arg_num;
+
if ( _argument->values != 0 )
{
ExtcapValueList elements = loadValues(QString(""));
@@ -754,6 +758,19 @@ QString ExtcapArgument::defaultValue()
return QString();
}
+QString ExtcapArgument::group() const
+{
+ if ( _argument != 0 && _argument->group != 0 )
+ return QString(_argument->group);
+
+ return QString();
+}
+
+int ExtcapArgument::argNr() const
+{
+ return _number;
+}
+
QString ExtcapArgument::prefKey(const QString & device_name)
{
struct preference * pref = NULL;
diff --git a/ui/qt/extcap_argument.h b/ui/qt/extcap_argument.h
index a24f25fd0f..07813f9f2a 100644
--- a/ui/qt/extcap_argument.h
+++ b/ui/qt/extcap_argument.h
@@ -94,6 +94,9 @@ public:
void resetValue();
+ virtual QString group() const;
+ virtual int argNr() const;
+
static ExtcapArgument * create(extcap_arg * argument = Q_NULLPTR, QObject * parent = Q_NULLPTR);
Q_SIGNALS:
@@ -110,6 +113,7 @@ protected:
extcap_arg * _argument;
QLabel * _label;
+ int _number;
const QString label_style;
diff --git a/ui/qt/extcap_options_dialog.cpp b/ui/qt/extcap_options_dialog.cpp
index 14ae53f1e5..3c69f99ea6 100644
--- a/ui/qt/extcap_options_dialog.cpp
+++ b/ui/qt/extcap_options_dialog.cpp
@@ -17,12 +17,13 @@
#include <wireshark_application.h>
#include <QMessageBox>
-#include <QMap>
+#include <QHash>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QUrl>
#include <QDesktopServices>
+#include <QTabWidget>
#include "ringbuffer.h"
#include "ui/capture_ui_utils.h"
@@ -244,20 +245,79 @@ void ExtcapOptionsDialog::updateWidgets()
/* find existing layout */
if (ui->verticalLayout->children().count() > 0)
{
- QGridLayout * layout = (QGridLayout *)ui->verticalLayout->itemAt(0);
- ui->verticalLayout->removeItem(layout);
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
+ QWidget * item = ui->verticalLayout->itemAt(0)->widget();
+ if ( item )
+ {
+ ui->verticalLayout->removeItem(ui->verticalLayout->itemAt(0));
+ delete item;
+ }
}
- QGridLayout * layout = new QGridLayout();
+ QHash<QString, QWidget *> layouts;
/* Load all extcap arguments */
loadArguments();
+ /* exit if no arguments have been found. This is a precaution, it should
+ * never happen, that this dialog get's called without any arguments */
+ if ( extcapArguments.count() == 0 )
+ {
+ ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
+ return;
+ }
+
+ QStringList groupKeys;
+ QString defaultKeyName(tr("Default"));
+ /* QMap sorts keys, therefore the groups are sorted by appearance */
+ QMap<int, QString> groups;
+
+ /* Look for all necessary tabs */
ExtcapArgumentList::iterator iter = extcapArguments.begin();
while ( iter != extcapArguments.end() )
{
argument = (ExtcapArgument *)(*iter);
+ QString groupKey = argument->group();
+ if ( groupKey.length() > 0 )
+ {
+ if ( ! groups.values().contains(groupKey) )
+ groups.insert(argument->argNr(), groupKey);
+ }
+ else if ( ! groups.keys().contains(0) )
+ {
+ groups.insert(0, defaultKeyName);
+ groupKey = defaultKeyName;
+ }
+
+ if ( ! layouts.keys().contains(groupKey) )
+ {
+ QWidget * tabWidget = new QWidget(this);
+ QGridLayout * tabLayout = new QGridLayout(tabWidget);
+ tabWidget->setLayout(tabLayout);
+
+ layouts.insert(groupKey, tabWidget);
+ }
+
+ ++iter;
+ }
+ groupKeys << groups.values();
+
+ /* Iterate over all arguments and do the following:
+ * 1. create the label for each element
+ * 2. create an editor for each element
+ * 3. add both to the layout for the tab widget
+ */
+ iter = extcapArguments.begin();
+ while ( iter != extcapArguments.end() )
+ {
+ argument = (ExtcapArgument *)(*iter);
+ QString groupKey = defaultKeyName;
+ if ( argument->group().length() > 0 )
+ groupKey = argument->group();
+
+ Q_ASSERT(layouts.keys().contains(groupKey));
+
+ QGridLayout * layout = ((QGridLayout *)layouts[groupKey]->layout());
lblWidget = argument->createLabel((QWidget *)this);
if ( lblWidget != NULL )
{
@@ -285,12 +345,34 @@ void ExtcapOptionsDialog::updateWidgets()
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(allowStart);
- ui->verticalLayout->addLayout(layout);
+ QWidget * mainWidget = Q_NULLPTR;
+
+ /* We should never display the dialog, if no settings are present */
+ Q_ASSERT(layouts.count() > 0);
+
+ if ( layouts.count() > 1 )
+ {
+ QTabWidget * tabs = new QTabWidget(this);
+ foreach ( QString key, groupKeys )
+ {
+ layouts[key]->layout()->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding));
+ tabs->addTab(layouts[key], key);
+ }
+
+ tabs->setCurrentIndex(0);
+ mainWidget = tabs;
+ }
+ else if ( layouts.count() == 1 )
+ mainWidget = layouts[layouts.keys().at(0)];
+
+ ui->verticalLayout->addWidget(mainWidget);
ui->verticalLayout->addSpacerItem(new QSpacerItem(20, 100, QSizePolicy::Minimum, QSizePolicy::Expanding));
}
else
{
- delete layout;
+ QList<QString> keys = layouts.keys();
+ foreach ( QString key, keys )
+ delete(layouts[key]);
}
}
@@ -382,45 +464,74 @@ void ExtcapOptionsDialog::resetValues()
{
ExtcapArgumentList::const_iterator iter;
QString value;
+ bool doStore = false;
- if (ui->verticalLayout->children().count() > 0)
+ int count = ui->verticalLayout->count();
+ if (count > 0)
{
- QGridLayout * layout = (QGridLayout *)ui->verticalLayout->findChild<QGridLayout *>();
+ QList<QLayout *> layouts;
+ if ( qobject_cast<QTabWidget *>(ui->verticalLayout->itemAt(0)->widget()) )
+ {
+ QTabWidget * tabs = qobject_cast<QTabWidget *>(ui->verticalLayout->itemAt(0)->widget());
+ for ( int cnt = 0; cnt < tabs->count(); cnt++ )
+ {
+ layouts.append(tabs->widget(cnt)->layout());
+ }
+ }
+ else
+ layouts.append(ui->verticalLayout->itemAt(0)->layout());
- for ( int row = 0; row < layout->rowCount(); row++ )
+ for ( int cnt = 0; cnt < layouts.count(); cnt++ )
{
- QWidget * child = layout->itemAtPosition(row, 1)->widget();
+ QGridLayout * layout = qobject_cast<QGridLayout *>(layouts.at(cnt));
+ if ( ! layout )
+ continue;
- if ( child )
+ for ( int row = 0; row < layout->rowCount(); row++ )
{
- /* Don't need labels, the edit widget contains the extcapargument property value */
- ExtcapArgument * arg = 0;
- QVariant prop = child->property(QString("extcap").toLocal8Bit());
+ QWidget * child = Q_NULLPTR;
+ if ( layout->itemAtPosition(row, 1) )
+ child = qobject_cast<QWidget *>(layout->itemAtPosition(row, 1)->widget());
- if ( prop.isValid() )
+ if ( child )
{
- arg = VariantPointer<ExtcapArgument>::asPtr(prop);
+ /* Don't need labels, the edit widget contains the extcapargument property value */
+ ExtcapArgument * arg = 0;
+ QVariant prop = child->property(QString("extcap").toLocal8Bit());
- /* value<> can fail */
- if (arg)
+ if ( prop.isValid() )
{
- arg->resetValue();
+ arg = VariantPointer<ExtcapArgument>::asPtr(prop);
- /* replacing the edit widget after resetting will lead to default value */
- layout->removeItem(layout->itemAtPosition(row, 1));
- QWidget * editWidget = arg->createEditor((QWidget *) this);
- if ( editWidget != NULL )
+ /* value<> can fail */
+ if (arg)
{
- editWidget->setProperty(QString("extcap").toLocal8Bit(), VariantPointer<ExtcapArgument>::asQVariant(arg));
- layout->addWidget(editWidget, row, 1, Qt::AlignVCenter);
+ arg->resetValue();
+
+ /* replacing the edit widget after resetting will lead to default value */
+ QWidget * newWidget = arg->createEditor((QWidget *) this);
+ if ( newWidget != NULL )
+ {
+ newWidget->setProperty(QString("extcap").toLocal8Bit(), VariantPointer<ExtcapArgument>::asQVariant(arg));
+ QLayoutItem * oldItem = layout->replaceWidget(child, newWidget);
+ if ( oldItem )
+ {
+ delete child;
+ delete oldItem;
+ }
+ }
+
+ doStore = true;
}
}
}
}
+
}
/* this stores all values to the preferences */
- storeValues();
+ if ( doStore )
+ storeValues();
}
}