pluginIf: Add/Remove single entries from selector
Allow to add and remove single items from a selector list and also fixing the selection of items in a selector list Change-Id: I0c69ea97db6ca1a6932939f0df9049c6fb720f77 Reviewed-on: https://code.wireshark.org/review/20363 Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
parent
9eca0390e7
commit
85aa48cef2
|
@ -499,6 +499,18 @@ void ext_toolbar_update_data_by_index(ext_toolbar_t * entry, gpointer data, gpoi
|
|||
ext_toolbar_update_entry( EXT_TOOLBAR_UPDATE_DATABYINDEX, entry, data, idx, silent );
|
||||
}
|
||||
|
||||
void ext_toolbar_update_data_add_entry(ext_toolbar_t * entry, gpointer data, gpointer idx, gboolean silent)
|
||||
{
|
||||
if ( entry->item_type == EXT_TOOLBAR_SELECTOR )
|
||||
ext_toolbar_update_entry( EXT_TOOLBAR_UPDATE_DATA_ADD, entry, data, idx, silent );
|
||||
}
|
||||
|
||||
void ext_toolbar_update_data_remove_entry(ext_toolbar_t * entry, gpointer data, gpointer idx, gboolean silent)
|
||||
{
|
||||
if ( entry->item_type == EXT_TOOLBAR_SELECTOR )
|
||||
ext_toolbar_update_entry( EXT_TOOLBAR_UPDATE_DATA_REMOVE, entry, data, idx, silent );
|
||||
}
|
||||
|
||||
/* Implementation of GUI callback methods follows.
|
||||
* This is a necessity, as using modern UI systems, gui interfaces often operate
|
||||
* in different threads then the calling application. Even more so, if the calling
|
||||
|
|
|
@ -138,7 +138,9 @@ typedef enum
|
|||
{
|
||||
EXT_TOOLBAR_UPDATE_VALUE,
|
||||
EXT_TOOLBAR_UPDATE_DATA,
|
||||
EXT_TOOLBAR_UPDATE_DATABYINDEX
|
||||
EXT_TOOLBAR_UPDATE_DATABYINDEX,
|
||||
EXT_TOOLBAR_UPDATE_DATA_ADD,
|
||||
EXT_TOOLBAR_UPDATE_DATA_REMOVE
|
||||
} ext_toolbar_update_type_t;
|
||||
|
||||
typedef struct _ext_toolbar_update_t
|
||||
|
@ -319,16 +321,42 @@ WS_DLL_PUBLIC void ext_toolbar_update_data(ext_toolbar_t * entry, gpointer data,
|
|||
* This is used to update a single entry of a selector list, by giving it's value and a new display
|
||||
* entry
|
||||
*
|
||||
* @param entry the entry to be updated
|
||||
* @param entry the toolbar item to be updated
|
||||
* @param data the display data for the entry
|
||||
* @param value the value for the entry to be updated
|
||||
* @param idx the value for the entry to be updated
|
||||
* @param silent the update for the entry should not trigger additional actions
|
||||
*/
|
||||
WS_DLL_PUBLIC void ext_toolbar_update_data_by_index(ext_toolbar_t * entry, gpointer data, gpointer value, gboolean silent);
|
||||
WS_DLL_PUBLIC void ext_toolbar_update_data_by_index(ext_toolbar_t * entry, gpointer data, gpointer idx, gboolean silent);
|
||||
|
||||
/* Adds the entry data by index
|
||||
*
|
||||
* This is used to add a single entry to a selector list, by giving it's new value and a new display
|
||||
* entry. If the value already exists, the selector may choose to ignore the command
|
||||
*
|
||||
* @param entry the toolbar item to be updated
|
||||
* @param data the display data for the entry to be added
|
||||
* @param idx the value for the entry to be added
|
||||
* @param silent the adding of the entry should not trigger additional actions
|
||||
*/
|
||||
WS_DLL_PUBLIC void ext_toolbar_update_data_add_entry(ext_toolbar_t * entry, gpointer data, gpointer idx, gboolean silent);
|
||||
|
||||
/* Removes an entry data by index
|
||||
*
|
||||
* This is used to remove a single entry to a selector list, by giving it's value and a display
|
||||
* entry. If the value already exists, the selector may choose to ignore the command. Both value
|
||||
* and display must be given, as it is not established, how the entry is found in the selector list
|
||||
*
|
||||
* @param entry the toolbar item to be updated
|
||||
* @param data the display data for the entry to be removed
|
||||
* @param idx the value for the entry to be removed
|
||||
* @param silent the removal of the entry should not trigger additional actions
|
||||
*/
|
||||
WS_DLL_PUBLIC void ext_toolbar_update_data_remove_entry(ext_toolbar_t * entry, gpointer data, gpointer idx, gboolean silent);
|
||||
|
||||
/* Search for and return if found an entry from the toolbar with the given label */
|
||||
WS_DLL_PUBLIC ext_toolbar_t * ext_toolbar_entry_by_label(const ext_toolbar_t * toolbar, const gchar * label);
|
||||
|
||||
|
||||
/*
|
||||
* Structure definition for the plugin_if_get_ws_info function
|
||||
*/
|
||||
|
|
|
@ -244,6 +244,21 @@ void PluginIFDemo_Main::on_btnAddItem_clicked()
|
|||
return;
|
||||
|
||||
listModel->appendRow(new QStandardItem(content));
|
||||
|
||||
if ( ui->chkAddRemoveImmediate->checkState() == Qt::Checked )
|
||||
{
|
||||
ext_toolbar_t * item = ext_toolbar_entry_by_label(_toolbar, ui->cmbElements->currentText().toStdString().c_str());
|
||||
if ( ! item || item->item_type != EXT_TOOLBAR_SELECTOR )
|
||||
return;
|
||||
|
||||
bool silent = ui->chkSilent->checkState() == Qt::Checked ? true : false;
|
||||
|
||||
gchar * value = g_strdup(ui->txtNewItemValue->text().toUtf8().constData());
|
||||
gchar * display = g_strdup(ui->txtNewItemDisplay->text().toUtf8().constData());
|
||||
ext_toolbar_update_data_add_entry(item, display, value, silent);
|
||||
g_free(value);
|
||||
g_free(display);
|
||||
}
|
||||
}
|
||||
|
||||
void PluginIFDemo_Main::on_btnRemoveItem_clicked()
|
||||
|
@ -255,7 +270,28 @@ void PluginIFDemo_Main::on_btnRemoveItem_clicked()
|
|||
|
||||
QModelIndexList selIndeces = selModel-> selectedIndexes();
|
||||
foreach(QModelIndex idx, selIndeces)
|
||||
{
|
||||
if ( ui->chkAddRemoveImmediate->checkState() == Qt::Checked )
|
||||
{
|
||||
ext_toolbar_t * item = ext_toolbar_entry_by_label(_toolbar, ui->cmbElements->currentText().toStdString().c_str());
|
||||
if ( ! item || item->item_type != EXT_TOOLBAR_SELECTOR )
|
||||
return;
|
||||
|
||||
bool silent = ui->chkSilent->checkState() == Qt::Checked ? true : false;
|
||||
|
||||
QString content = listModel->data(idx).toString();
|
||||
int pos = content.indexOf(":");
|
||||
|
||||
gchar * value = g_strdup(content.left(pos).toUtf8().constData() );
|
||||
/* -2 because removal of : and space */
|
||||
gchar * display = g_strdup(content.right(content.size() - pos - 2).toUtf8().constData());
|
||||
ext_toolbar_update_data_remove_entry(item, display, value, silent);
|
||||
g_free(value);
|
||||
g_free(display);
|
||||
}
|
||||
|
||||
listModel->removeRow(idx.row());
|
||||
}
|
||||
}
|
||||
|
||||
void PluginIFDemo_Main::on_btnSendList_clicked()
|
||||
|
@ -306,6 +342,26 @@ void PluginIFDemo_Main::on_btnSendUpdateItem_clicked()
|
|||
(gpointer) displayValue.toStdString().c_str(), (gpointer) cmbIndexText.toStdString().c_str(), silent );
|
||||
}
|
||||
|
||||
void PluginIFDemo_Main::on_lstItems_clicked(const QModelIndex &idx)
|
||||
{
|
||||
if ( ! _toolbar || ! idx.isValid() )
|
||||
return;
|
||||
|
||||
ext_toolbar_t * item = ext_toolbar_entry_by_label(_toolbar, ui->cmbElements->currentText().toStdString().c_str());
|
||||
if ( ! item || item->item_type != EXT_TOOLBAR_SELECTOR )
|
||||
return;
|
||||
|
||||
bool silent = ui->chkSilent->checkState() == Qt::Checked ? true : false;
|
||||
|
||||
QString content = listModel->data(listModel->index(idx.row(), 0)).toString();
|
||||
int pos = content.indexOf(":");
|
||||
|
||||
gchar * idxData = g_strdup(content.left(pos).toUtf8().constData() );
|
||||
|
||||
ext_toolbar_update_value(item, idxData, silent);
|
||||
g_free(idxData);
|
||||
|
||||
}
|
||||
/*
|
||||
* Editor modelines
|
||||
*
|
||||
|
|
|
@ -101,6 +101,7 @@ private slots:
|
|||
void on_btnRemoveItem_clicked();
|
||||
void on_btnSendList_clicked();
|
||||
void on_cmbElements_currentTextChanged(const QString & newText);
|
||||
void on_lstItems_clicked(const QModelIndex &idx);
|
||||
|
||||
void logChanged(QString message);
|
||||
void closeDialog();
|
||||
|
|
|
@ -216,6 +216,33 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="chkAddRemoveImmediate">
|
||||
<property name="text">
|
||||
<string>Add and remove will immediately be send to interface</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="chkSendSelect">
|
||||
<property name="text">
|
||||
<string>Update interface with selection</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<item>
|
||||
|
|
|
@ -188,8 +188,6 @@ QWidget * AdditionalToolbarWidgetAction::createButton(ext_toolbar_t * item, QWid
|
|||
if ( ! item || item->type != EXT_TOOLBAR_ITEM || item->item_type != EXT_TOOLBAR_BUTTON )
|
||||
return 0;
|
||||
|
||||
QString defValue = item->defvalue;
|
||||
|
||||
QPushButton * button = new QPushButton(item->name, parent);
|
||||
button->setText(item->name);
|
||||
connect(button, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
|
||||
|
@ -327,36 +325,28 @@ toolbar_selector_cb(gpointer item, gpointer item_data, gpointer user_data)
|
|||
if ( update_entry->silent )
|
||||
oldState = comboBox->blockSignals(true);
|
||||
|
||||
QStandardItemModel * sourceModel = (QStandardItemModel *)comboBox->model();
|
||||
|
||||
if ( update_entry->type != EXT_TOOLBAR_UPDATE_DATA_REMOVE && ! update_entry->user_data )
|
||||
return;
|
||||
|
||||
if ( update_entry->type == EXT_TOOLBAR_UPDATE_VALUE )
|
||||
{
|
||||
QString data = QString((gchar *)update_entry->user_data);
|
||||
bool conv_ok = false;
|
||||
|
||||
int dataValue = data.toInt(&conv_ok, 10);
|
||||
if ( conv_ok && dataValue >= 0 && comboBox->model()->rowCount() < dataValue )
|
||||
comboBox->setCurrentIndex(dataValue);
|
||||
else
|
||||
for(int i = 0; i < sourceModel->rowCount(); i++)
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
comboBox->setCurrentText(data);
|
||||
#else
|
||||
for(int i = 0; i < comboBox->model()->rowCount(); i++)
|
||||
QStandardItem * dataValue = ((QStandardItemModel *)sourceModel)->item(i, 0);
|
||||
ext_toolbar_value_t * tbValue = VariantPointer<ext_toolbar_value_t>::asPtr(dataValue->data(Qt::UserRole));
|
||||
if ( tbValue && data.compare(QString(tbValue->value)) == 0 )
|
||||
{
|
||||
QStandardItem * dataValue = ((QStandardItemModel *)comboBox->model())->item(i, 0);
|
||||
ext_toolbar_value_t * tbValue = VariantPointer<ext_toolbar_value_t>::asPtr(dataValue->data());
|
||||
if ( data.compare(QString(tbValue->display)) )
|
||||
{
|
||||
comboBox->setCurrentIndex(i);
|
||||
break;
|
||||
}
|
||||
comboBox->setCurrentIndex(i);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if ( update_entry->type == EXT_TOOLBAR_UPDATE_DATA )
|
||||
{
|
||||
QStandardItemModel * sourceModel = (QStandardItemModel *)comboBox->model();
|
||||
|
||||
GList * walker = (GList *)update_entry->user_data;
|
||||
if ( g_list_length(walker) == 0 )
|
||||
return;
|
||||
|
@ -374,24 +364,54 @@ toolbar_selector_cb(gpointer item, gpointer item_data, gpointer user_data)
|
|||
walker = g_list_next(walker);
|
||||
}
|
||||
}
|
||||
else if ( update_entry->type == EXT_TOOLBAR_UPDATE_DATABYINDEX )
|
||||
else if ( update_entry->type == EXT_TOOLBAR_UPDATE_DATABYINDEX ||
|
||||
update_entry->type == EXT_TOOLBAR_UPDATE_DATA_ADD ||
|
||||
update_entry->type == EXT_TOOLBAR_UPDATE_DATA_REMOVE )
|
||||
{
|
||||
QStandardItemModel * sourceModel = (QStandardItemModel *)comboBox->model();
|
||||
|
||||
if ( ! update_entry->user_data || ! update_entry->data_index )
|
||||
if ( ! update_entry->data_index )
|
||||
return;
|
||||
|
||||
gchar * idx = (gchar *)update_entry->data_index;
|
||||
gchar * display = (gchar *)update_entry->user_data;
|
||||
|
||||
for ( int i = 0; i < sourceModel->rowCount(); i++ )
|
||||
if ( update_entry->type == EXT_TOOLBAR_UPDATE_DATABYINDEX )
|
||||
{
|
||||
QStandardItem * item = sourceModel->item(i, 0);
|
||||
ext_toolbar_value_t * entry = VariantPointer<ext_toolbar_value_t>::asPtr(item->data(Qt::UserRole));
|
||||
if ( entry && g_strcmp0( entry->value, idx) == 0 )
|
||||
for ( int i = 0; i < sourceModel->rowCount(); i++ )
|
||||
{
|
||||
item->setText(display);
|
||||
break;
|
||||
QStandardItem * item = sourceModel->item(i, 0);
|
||||
ext_toolbar_value_t * entry = VariantPointer<ext_toolbar_value_t>::asPtr(item->data(Qt::UserRole));
|
||||
if ( entry && g_strcmp0( entry->value, idx) == 0 )
|
||||
{
|
||||
g_free(entry->display);
|
||||
entry->display = g_strdup(display);
|
||||
item->setData(VariantPointer<ext_toolbar_value_t>::asQVariant(entry), Qt::UserRole);
|
||||
item->setText(display);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( update_entry->type == EXT_TOOLBAR_UPDATE_DATA_ADD )
|
||||
{
|
||||
ext_toolbar_value_t * listvalue = g_new0(ext_toolbar_value_t, 1);
|
||||
listvalue->display = g_strdup(display);
|
||||
listvalue->value = g_strdup(idx);
|
||||
|
||||
QStandardItem * si = new QStandardItem(listvalue->display);
|
||||
si->setData(VariantPointer<ext_toolbar_value_t>::asQVariant(listvalue), Qt::UserRole);
|
||||
sourceModel->appendRow(si);
|
||||
}
|
||||
else if ( update_entry->type == EXT_TOOLBAR_UPDATE_DATA_REMOVE )
|
||||
{
|
||||
QList<QStandardItem *> entryList = sourceModel->findItems(display);
|
||||
/* Search for index if display did not find anything */
|
||||
if ( entryList.size() == 0 )
|
||||
entryList = sourceModel->findItems(idx);
|
||||
|
||||
foreach(QStandardItem *entry, entryList)
|
||||
{
|
||||
QModelIndex index = sourceModel->indexFromItem(entry);
|
||||
if ( index.isValid() )
|
||||
sourceModel->removeRow(index.row());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue