|
From: <cn...@us...> - 2020-10-28 00:32:59
|
Revision: 1084
http://sourceforge.net/p/seq/svn/1084
Author: cn187
Date: 2020-10-28 00:32:56 +0000 (Wed, 28 Oct 2020)
Log Message:
-----------
Replace Q3ListBox with QListWidget
Modified Paths:
--------------
showeq/branches/pre_6_0_beta/src/messagefilterdialog.cpp
showeq/branches/pre_6_0_beta/src/messagefilterdialog.h
Modified: showeq/branches/pre_6_0_beta/src/messagefilterdialog.cpp
===================================================================
--- showeq/branches/pre_6_0_beta/src/messagefilterdialog.cpp 2020-10-28 00:32:47 UTC (rev 1083)
+++ showeq/branches/pre_6_0_beta/src/messagefilterdialog.cpp 2020-10-28 00:32:56 UTC (rev 1084)
@@ -34,7 +34,7 @@
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
-#include <Q3ListBox>
+#include <QListWidget>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QVBoxLayout>
@@ -42,15 +42,13 @@
//----------------------------------------------------------------------
// MessageFilterListBoxText
-class MessageFilterListBoxText : public Q3ListBoxText
+class MessageFilterListBoxText : public QListWidgetItem
{
public:
- MessageFilterListBoxText(Q3ListBox * listbox,
+ MessageFilterListBoxText(QListWidget * listbox,
const QString & text = QString::null,
uint32_t data = 0);
- MessageFilterListBoxText(Q3ListBox * listbox, Q3ListBoxItem* after,
- const QString & text = QString::null,
- uint32_t data = 0);
+
virtual ~MessageFilterListBoxText();
uint32_t data() { return m_data; }
@@ -60,22 +58,14 @@
uint32_t m_data;
};
-MessageFilterListBoxText::MessageFilterListBoxText(Q3ListBox * listbox,
+MessageFilterListBoxText::MessageFilterListBoxText(QListWidget * listbox,
const QString & text,
uint32_t data)
- : Q3ListBoxText(listbox, text),
+ : QListWidgetItem(text, listbox),
m_data(data)
{
}
-MessageFilterListBoxText::MessageFilterListBoxText(Q3ListBox* listbox,
- Q3ListBoxItem* after,
- const QString& text,
- uint32_t data)
- : Q3ListBoxText(listbox, text, after),
- m_data(data)
-{
-}
MessageFilterListBoxText::~MessageFilterListBoxText()
{
@@ -115,12 +105,14 @@
QLabel* label = new QLabel("&Existing Filters", this);
column1Layout->addWidget(label, 1, Qt::AlignCenter);
- m_existingFilters = new Q3ListBox(this, "existingfilters");
+ m_existingFilters = new QListWidget(this);
column1Layout->addWidget(m_existingFilters, 10);
label->setBuddy(m_existingFilters);
- m_existingFilters->setSelectionMode(Q3ListBox::Single);
- connect(m_existingFilters, SIGNAL(selectionChanged(Q3ListBoxItem*)),
- this, SLOT(existingFilterSelectionChanged(Q3ListBoxItem*)));
+ m_existingFilters->setSelectionMode(QAbstractItemView::SingleSelection);
+ connect(m_existingFilters->selectionModel(),
+ SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
+ this,
+ SLOT(existingFilterSelectionChanged(const QItemSelection&, const QItemSelection&)));
m_new = new QPushButton("Ne&w", this);
column1Layout->addWidget(m_new, 1, Qt::AlignCenter);
@@ -144,11 +136,13 @@
connect(m_pattern, SIGNAL(textChanged(const QString&)),
this, SLOT(anyTextChanged(const QString&)));
- m_messageTypes = new Q3ListBox(m_filterGroup, "messagetypes");
+ m_messageTypes = new QListWidget(m_filterGroup);
newFilterLayout->addRow("&Message Types", m_messageTypes);
- m_messageTypes->setSelectionMode(Q3ListBox::Multi);
- connect(m_messageTypes, SIGNAL(selectionChanged()),
- this, SLOT(messageTypeSelectionChanged()));
+ m_messageTypes->setSelectionMode(QAbstractItemView::MultiSelection);
+ connect(m_messageTypes->selectionModel(),
+ SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
+ this,
+ SLOT(messageTypeSelectionChanged(const QItemSelection&, const QItemSelection&)));
m_delete = new QPushButton("&Delete", m_filterGroup);
m_delete->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
@@ -227,21 +221,21 @@
uint64_t types = 0;
// iterate over the message types
- for (Q3ListBoxItem* currentLBT = m_messageTypes->firstItem();
- currentLBT;
- currentLBT = currentLBT->next())
+ int numTypeRows = m_messageTypes->count();
+ for (int row = 0; row < numTypeRows; ++row)
{
- // if the item isn't selected, add in its type flag, and enable updates
- if (currentLBT->isSelected())
- {
- // get the message type of the selected item
- type = ((MessageFilterListBoxText*)currentLBT)->data();
+ MessageFilterListBoxText* item = (MessageFilterListBoxText*) m_messageTypes->item(row);
- // add its flag to the types
- types |= (uint64_t(1) << type);
- }
- }
+ if (item->isSelected())
+ {
+ // get the message type of the selected item
+ type = item->data();
+ // add its flag to the types
+ types |= (uint64_t(1) << type);
+ }
+ }
+
// create a message filter object
MessageFilter newFilter(m_name->text(), types, QRegExp(m_pattern->text()));
@@ -251,7 +245,7 @@
// add the new filter
m_currentFilterNum = m_filters->addFilter(newFilter);
-
+
// if it is a valid filter, make the new filter the current selection
if (m_currentFilterNum != 0xFF)
{
@@ -259,16 +253,17 @@
m_currentFilter = m_filters->filter(m_currentFilterNum);
// iterate over the existing filters
- for (Q3ListBoxItem* currentLBT = m_existingFilters->firstItem();
- currentLBT;
- currentLBT = currentLBT->next())
+ int numFiltRows = m_existingFilters->count();
+ for (int row = 0; row < numFiltRows; ++row)
{
+ MessageFilterListBoxText* item = (MessageFilterListBoxText*) m_existingFilters->item(row);
// find the current filter
- if (((MessageFilterListBoxText*)currentLBT)->data() == m_currentFilterNum)
+ if (item->data() == m_currentFilterNum)
{
- // make the current filter the selected filter
- m_existingFilters->setSelected(currentLBT, true);
- break;
+ // make the current filter the selected filter
+ item->setSelected(true);
+ m_existingFilters->setCurrentRow(row);
+ break;
}
}
}
@@ -285,12 +280,31 @@
void MessageFilterDialog::updateFilter()
{
- // delete the old filter
- if (m_currentFilter)
- m_filters->remFilter(*m_currentFilter);
+ //Note, this used to happen in the opposite order: delete then add.
+ //But in Qt4, removing the old filter triggers the list selection update,
+ //which causes the previous/next item to be selected, losing the updated
+ //values and instead duplicating the adjacent filter.
+ //
+ //Doing it this way avoids that problem, but as a result it causes the
+ //updated filter to jump to a different position in the list.
+ //
+ //TODO to properly fix this, either we need to do one or both of:
+ // 1) implement a proper "update" that update the existing filter and
+ // list item without removing the old one
+ // 2) Change the filter list to sort by something other than the filter index
+ // Name might be a good choice here.
+ //
+
+ const MessageFilter* oldFilter = m_currentFilter;
+
// add in a new filter
addFilter();
+
+ // delete the old filter
+ if (oldFilter)
+ m_filters->remFilter(*oldFilter);
+
}
void MessageFilterDialog::deleteFilter()
@@ -315,41 +329,53 @@
checkState();
}
-void MessageFilterDialog::messageTypeSelectionChanged()
+void MessageFilterDialog::messageTypeSelectionChanged(
+ const QItemSelection& selected, const QItemSelection& deselected)
{
// check the state whenever the message type selection changed
checkState();
}
-void MessageFilterDialog::existingFilterSelectionChanged(Q3ListBoxItem * item)
+void MessageFilterDialog::existingFilterSelectionChanged(
+ const QItemSelection& selected, const QItemSelection& deselected)
{
- if (item)
+
+ //
+ if (selected.count())
{
- // get the current filter number from the listbox item
- m_currentFilterNum = ((MessageFilterListBoxText*)item)->data();
-
- // get the specified filter
- m_currentFilter = m_filters->filter(m_currentFilterNum);
+ // the filter list only allows selecting one item at a time, so
+ // we can simply grab the first (and only) selection
+ int row = selected.indexes().first().row();
- // set the GroupBox's label
- m_filterGroup->setTitle(m_currentFilter->name() + " &Filter");
+ MessageFilterListBoxText* item = (MessageFilterListBoxText*)m_existingFilters->item(row);
- // setup all the filter values
- m_name->setText(m_currentFilter->name());
- m_pattern->setText(m_currentFilter->regexp().pattern());
+ // get the current filter number from the listbox item
+ m_currentFilterNum = item->data();
- // select all the message types
- uint64_t messageTypes = m_currentFilter->types();
- uint32_t messageType;
- for (Q3ListBoxItem* currentLBT = m_messageTypes->firstItem();
- currentLBT;
- currentLBT = currentLBT->next())
- {
- messageType = ((MessageFilterListBoxText*)currentLBT)->data();
- m_messageTypes->setSelected(currentLBT, ((uint64_t(1) << messageType) & messageTypes) != 0);
- }
+ // get the specified filter
+ m_currentFilter = m_filters->filter(m_currentFilterNum);
+
+ // set the GroupBox's label
+ m_filterGroup->setTitle(m_currentFilter->name() + " &Filter");
+
+ // setup all the filter values
+ m_name->setText(m_currentFilter->name());
+ m_pattern->setText(m_currentFilter->regexp().pattern());
+
+ // select all the message types
+ uint64_t messageTypes = m_currentFilter->types();
+ uint32_t messageType;
+ int numRows = m_messageTypes->count();
+ for (int row = 0; row < numRows; ++row)
+ {
+ MessageFilterListBoxText* item = (MessageFilterListBoxText*) m_messageTypes->item(row);
+
+ messageType = item->data();
+ item->setSelected(((uint64_t(1) << messageType) & messageTypes) != 0);
+ }
+
}
- else // no item selected, clear all filter setup
+ else
clearFilter();
// check the current state
@@ -359,19 +385,20 @@
void MessageFilterDialog::removedFilter(uint32_t mask, uint8_t filter)
{
// iterate over all the existing filters
- for (Q3ListBoxItem* currentLBT = m_existingFilters->firstItem();
- currentLBT;
- currentLBT = currentLBT->next())
+ int numRows = m_existingFilters->count();
+ for (int row = 0; row < numRows; ++row)
{
- // check if this is the removed filter
- if (((MessageFilterListBoxText*)currentLBT)->data() == filter)
- {
- // delete the removed filter's list box item
- delete currentLBT;
+ MessageFilterListBoxText* item = (MessageFilterListBoxText*)m_existingFilters->item(row);
- // nothing more to do
- break;
- }
+ // check if this is the removed filter
+ if (item->data() == filter)
+ {
+ // delete the removed filter's list box item
+ delete m_existingFilters->takeItem(row);
+
+ // nothing more to do
+ break;
+ }
}
}
@@ -381,25 +408,23 @@
if (m_existingFilters->count() == 0)
{
// add the new message filter
- new MessageFilterListBoxText(m_existingFilters, 0,
- filter.name(), filterid);
+ new MessageFilterListBoxText(m_existingFilters, filter.name(), filterid);
return;
}
// iterate over all the existing filters
- for (Q3ListBoxItem* currentLBT = m_existingFilters->firstItem();
- currentLBT;
- currentLBT = currentLBT->next())
+ int numFiltRows = m_existingFilters->count();
+ for (int row = 0; row < numFiltRows; ++row)
{
+ MessageFilterListBoxText* item = (MessageFilterListBoxText*)m_existingFilters->item(row);
// check if this is the removed filter
- if (((MessageFilterListBoxText*)currentLBT)->data() > filterid)
+ if (item->data() > filterid)
{
// add a new message filter at the appropriate location
// NOTE: This maintains list order during an item update
- new MessageFilterListBoxText(m_existingFilters, currentLBT->prev(),
- filter.name(), filterid);
-
+ m_existingFilters->insertItem(row,
+ new MessageFilterListBoxText(nullptr, filter.name(), filterid));
break;
}
else
@@ -406,10 +431,10 @@
{
//if we're at the end of the list and still haven't inserted, we need
//to do it, otherwise, it won't get added to the list.
- if (currentLBT->next() == 0)
+ if (row + 1 == numFiltRows)
{
- new MessageFilterListBoxText(m_existingFilters, currentLBT,
- filter.name(), filterid);
+ m_existingFilters->addItem(
+ new MessageFilterListBoxText(nullptr, filter.name(), filterid));
break;
}
}
@@ -437,7 +462,7 @@
{
uint32_t type;
uint64_t types = 0;
-
+
// buttons should only be enabled for valid message filter content
if (!m_name->text().isEmpty() &&
!m_pattern->text().isEmpty() &&
@@ -444,29 +469,29 @@
QRegExp(m_pattern->text()).isValid())
{
// iterate over all the message types
- for (Q3ListBoxItem* currentLBT = m_messageTypes->firstItem();
- currentLBT;
- currentLBT = currentLBT->next())
+ int numRows = m_messageTypes->count();
+ for (int row = 0; row < numRows; ++row)
{
- // is the current item selected
- if (currentLBT->isSelected())
- {
- // get the items message type
- type = ((MessageFilterListBoxText*)currentLBT)->data();
+ MessageFilterListBoxText* item = (MessageFilterListBoxText*)m_messageTypes->item(row);
+ // is the current item selected
+ if (item->isSelected())
+ {
+ // get the items message type
+ type = item->data();
- // add the message type into the message types
- types |= (uint64_t(1) << type);
+ // add the message type into the message types
+ types |= (uint64_t(1) << type);
- // found a selected item, fields are valid for update
- update = true;
- }
+ // found a selected item, fields are valid for update
+ update = true;
+ }
}
// only enable add if the filter is different from its predecessor
- if ((m_name->text() != m_currentFilter->name()) ||
- (m_pattern->text() != m_currentFilter->regexp().pattern()) ||
- (types != m_currentFilter->types()))
- add = true;
+ if ((m_name->text() != m_currentFilter->name()) ||
+ (m_pattern->text() != m_currentFilter->regexp().pattern()) ||
+ (types != m_currentFilter->types()))
+ add = true;
}
}
@@ -477,17 +502,17 @@
!m_pattern->text().isEmpty())
{
// iterate over all the message types
- for (Q3ListBoxItem* currentLBT = m_messageTypes->firstItem();
- currentLBT;
- currentLBT = currentLBT->next())
+ int numRows = m_messageTypes->count();
+ for (int row = 0; row < numRows; ++row)
{
- // if the item isn't selected, try the next item
- if (!currentLBT->isSelected())
- continue;
-
- // found a selected item, fields are valid for add
- add = true;
- break;
+ MessageFilterListBoxText* item = (MessageFilterListBoxText*)m_messageTypes->item(row);
+ // if the item isn't selected, try the next item
+ if (!item->isSelected())
+ continue;
+
+ // found a selected item, fields are valid for add
+ add = true;
+ break;
}
}
}
Modified: showeq/branches/pre_6_0_beta/src/messagefilterdialog.h
===================================================================
--- showeq/branches/pre_6_0_beta/src/messagefilterdialog.h 2020-10-28 00:32:47 UTC (rev 1083)
+++ showeq/branches/pre_6_0_beta/src/messagefilterdialog.h 2020-10-28 00:32:56 UTC (rev 1084)
@@ -37,9 +37,10 @@
class QLineEdit;
class QLabel;
class QPushButton;
-class Q3ListBox;
-class Q3ListBoxItem;
+class QListWidget;
+class QListWidgetItem;
class QGroupBox;
+class QItemSelection;
//----------------------------------------------------------------------
// MessageFilterDialog
@@ -59,8 +60,10 @@
protected slots:
void anyTextChanged(const QString& newText);
- void messageTypeSelectionChanged();
- void existingFilterSelectionChanged(Q3ListBoxItem * item);
+ void messageTypeSelectionChanged(const QItemSelection& selected,
+ const QItemSelection& deselected);
+ void existingFilterSelectionChanged(const QItemSelection& selected,
+ const QItemSelection& deselected);
void removedFilter(uint32_t mask, uint8_t filter);
void addedFilter(uint32_t mask, uint8_t filterid, const MessageFilter& filter);
@@ -69,12 +72,12 @@
void checkState();
MessageFilters* m_filters;
- Q3ListBox* m_existingFilters;
+ QListWidget* m_existingFilters;
QPushButton* m_new;
QGroupBox* m_filterGroup;
QLineEdit* m_name;
QLineEdit* m_pattern;
- Q3ListBox* m_messageTypes;
+ QListWidget* m_messageTypes;
QPushButton* m_add;
QPushButton* m_update;
QPushButton* m_delete;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|