forked from osmocom/wireshark
Qt+extcap: Add editable extcap selectors.
Add an "editselector" argument type, which lets the user override a predefined selection list with a custom value.pespin/osmux-wip
parent
52c130ced7
commit
2b4fcae31f
|
@ -71,6 +71,7 @@ Argument type for UI filtering for raw, or UI type for selector:
|
|||
long (may include scientific / special notation)
|
||||
float
|
||||
selector (display selector table, all values as strings)
|
||||
editselector (selector table which can be overridden, all values as strings)
|
||||
boolean (display checkbox)
|
||||
radio (display group of radio buttons with provided values, all values as strings)
|
||||
fileselect (display a dialog to select a file from the filesystem, value as string)
|
||||
|
|
|
@ -285,10 +285,11 @@ When _mustexist=false_ is used, the GUI shows the user a file dialog for saving
|
|||
arg {number=3}{call=--logfile}{display=Logfile}{tooltip=A file for log messages}{type=fileselect}{mustexist=false}
|
||||
----
|
||||
|
||||
_selector_, _radio_, _multicheck_::
|
||||
_selector_, __editselector__, _radio_, _multicheck_::
|
||||
Option fields where the user may choose from one or more options.
|
||||
If _parent_ is provided for the value items, the option fields for _multicheck_ and _selector_ are presented in a tree-like structure.
|
||||
_selector_ and _radio_ values must present a default value, which will be the value provided to the extcap binary for this argument
|
||||
_selector_ and _radio_ values must present a default value, which will be the value provided to the extcap binary for this argument.
|
||||
_editselector_ option fields let the user select from a list of items or enter a custom value.
|
||||
+
|
||||
[source,python]
|
||||
----
|
||||
|
|
|
@ -519,6 +519,8 @@ static extcap_arg *extcap_parse_arg_sentence(GList *args, extcap_token_sentence
|
|||
target_arg->arg_type = EXTCAP_ARG_BOOLFLAG;
|
||||
} else if (g_ascii_strcasecmp(param_value, "selector") == 0) {
|
||||
target_arg->arg_type = EXTCAP_ARG_SELECTOR;
|
||||
} else if (g_ascii_strcasecmp(param_value, "editselector") == 0) {
|
||||
target_arg->arg_type = EXTCAP_ARG_EDIT_SELECTOR;
|
||||
} else if (g_ascii_strcasecmp(param_value, "radio") == 0) {
|
||||
target_arg->arg_type = EXTCAP_ARG_RADIO;
|
||||
} else if (g_ascii_strcasecmp(param_value, "string") == 0) {
|
||||
|
|
|
@ -39,6 +39,7 @@ typedef enum {
|
|||
EXTCAP_ARG_PASSWORD,
|
||||
/* Complex GUI types which are populated with value sentences */
|
||||
EXTCAP_ARG_SELECTOR,
|
||||
EXTCAP_ARG_EDIT_SELECTOR,
|
||||
EXTCAP_ARG_RADIO,
|
||||
EXTCAP_ARG_MULTICHECK,
|
||||
EXTCAP_ARG_FILESELECT,
|
||||
|
|
|
@ -263,6 +263,49 @@ void ExtArgSelector::setDefaultValue()
|
|||
}
|
||||
|
||||
|
||||
ExtArgEditSelector::ExtArgEditSelector(extcap_arg * argument, QObject * parent) :
|
||||
ExtArgSelector(argument, parent) {}
|
||||
|
||||
QWidget * ExtArgEditSelector::createEditor(QWidget * parent)
|
||||
{
|
||||
QWidget *editor = ExtArgSelector::createEditor(parent);
|
||||
|
||||
boxSelection->setEditable(true);
|
||||
boxSelection->setInsertPolicy(QComboBox::NoInsert);
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
QString ExtArgEditSelector::value()
|
||||
{
|
||||
if (boxSelection == nullptr) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
return boxSelection->currentText();
|
||||
}
|
||||
|
||||
void ExtArgEditSelector::setDefaultValue()
|
||||
{
|
||||
ExtArgSelector::setDefaultValue();
|
||||
|
||||
if (boxSelection == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const char *prefval = (_argument->pref_valptr && strlen(*_argument->pref_valptr)) ? *_argument->pref_valptr : NULL;
|
||||
QString stored(prefval ? prefval : "");
|
||||
QVariant data = boxSelection->currentData();
|
||||
|
||||
if (data.toString() != stored) {
|
||||
// Apparently createEditor hasn't been called at this point.
|
||||
boxSelection->setEditable(true);
|
||||
boxSelection->setInsertPolicy(QComboBox::NoInsert);
|
||||
boxSelection->setEditText(stored);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
ExtArgRadio::ExtArgRadio(extcap_arg * argument, QObject * parent) :
|
||||
ExtcapArgument(argument, parent), selectorGroup(0), callStrings(0) {}
|
||||
|
@ -943,6 +986,8 @@ ExtcapArgument * ExtcapArgument::create(extcap_arg * argument, QObject *parent)
|
|||
result = new ExtArgBool(argument, parent);
|
||||
else if (argument->arg_type == EXTCAP_ARG_SELECTOR)
|
||||
result = new ExtArgSelector(argument, parent);
|
||||
else if (argument->arg_type == EXTCAP_ARG_EDIT_SELECTOR)
|
||||
result = new ExtArgEditSelector(argument, parent);
|
||||
else if (argument->arg_type == EXTCAP_ARG_RADIO)
|
||||
result = new ExtArgRadio(argument, parent);
|
||||
else if (argument->arg_type == EXTCAP_ARG_FILESELECT)
|
||||
|
|
|
@ -182,8 +182,7 @@ public:
|
|||
public Q_SLOTS:
|
||||
virtual void setDefaultValue();
|
||||
|
||||
private:
|
||||
|
||||
protected:
|
||||
QComboBox * boxSelection;
|
||||
|
||||
private Q_SLOTS:
|
||||
|
@ -192,6 +191,19 @@ private Q_SLOTS:
|
|||
};
|
||||
|
||||
|
||||
class ExtArgEditSelector : public ExtArgSelector
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ExtArgEditSelector(extcap_arg * argument, QObject *parent = Q_NULLPTR);
|
||||
virtual QWidget * createEditor(QWidget * parent);
|
||||
virtual QString value();
|
||||
|
||||
public Q_SLOTS:
|
||||
virtual void setDefaultValue();
|
||||
};
|
||||
|
||||
|
||||
class ExtArgRadio : public ExtcapArgument
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue