diff options
author | Michael Mann <mmann78@netscape.net> | 2018-01-06 21:40:19 -0500 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2018-01-08 09:08:42 +0000 |
commit | c53412f7db226b99e6e747364ff75e7788ed3575 (patch) | |
tree | 4ca737e2dc97fced6a838ca057453f3635101e13 /ui/qt | |
parent | 985f7d023e1461b5e58b37b4e207b3665278df51 (diff) |
Bugfix the sort order of protocols in Preference dialog.
Sort properly by module title.
Also consolidate some of the searching in PrefModuleTreeView.
Change-Id: I5312581c63f8626de08bd9f03613219b34bf968a
Reviewed-on: https://code.wireshark.org/review/25176
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui/qt')
-rw-r--r-- | ui/qt/models/pref_models.cpp | 47 | ||||
-rw-r--r-- | ui/qt/models/pref_models.h | 1 | ||||
-rw-r--r-- | ui/qt/widgets/pref_module_view.cpp | 53 | ||||
-rw-r--r-- | ui/qt/widgets/pref_module_view.h | 2 |
4 files changed, 51 insertions, 52 deletions
diff --git a/ui/qt/models/pref_models.cpp b/ui/qt/models/pref_models.cpp index 5c37035ab4..c5046614d8 100644 --- a/ui/qt/models/pref_models.cpp +++ b/ui/qt/models/pref_models.cpp @@ -109,6 +109,13 @@ QString PrefsItem::getModuleName() const return QString(module_->name); } +QString PrefsItem::getModuleTitle() const +{ + if ((module_ == NULL) && (pref_ == NULL)) + return name_; + + return QString(module_->title); +} void PrefsItem::setChanged(bool changed) { @@ -652,15 +659,7 @@ QVariant ModulePrefsModel::data(const QModelIndex &dataindex, int role) const switch ((ModulePrefsModelColumn)dataindex.column()) { case colName: - if (item->getPref() == NULL) { - if (item->getModule() == NULL) { - return item->getName(); - } - - return item->getModule()->title; - } - - return sourceModel()->data(sourceModel()->index(modelIndex.row(), PrefsModel::colName, modelIndex.parent()), role); + return item->getModuleTitle(); default: break; } @@ -715,21 +714,29 @@ int ModulePrefsModel::columnCount(const QModelIndex&) const bool ModulePrefsModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const { - //Force "Advanced" preferences to be at bottom of model - if (source_left.isValid() && !source_left.parent().isValid() && - source_right.isValid() && !source_right.parent().isValid()) { - PrefsItem* left_item = static_cast<PrefsItem*>(source_left.internalPointer()); - PrefsItem* right_item = static_cast<PrefsItem*>(source_right.internalPointer()); - if ((left_item != NULL) && (left_item->getName().compare(advancedPrefName_) == 0)) { - return false; + PrefsItem* left_item = static_cast<PrefsItem*>(source_left.internalPointer()); + PrefsItem* right_item = static_cast<PrefsItem*>(source_right.internalPointer()); + + if ((left_item != NULL) && (right_item != NULL)) { + QString left_name = left_item->getModuleTitle(), + right_name = right_item->getModuleTitle(); + + //Force "Advanced" preferences to be at bottom of model + if (source_left.isValid() && !source_left.parent().isValid() && + source_right.isValid() && !source_right.parent().isValid()) { + if (left_name.compare(advancedPrefName_) == 0) { + return false; + } + if (right_name.compare(advancedPrefName_) == 0) { + return true; + } } - if ((right_item != NULL) && (right_item->getName().compare(advancedPrefName_) == 0)) { + + if (left_name.compare(right_name, Qt::CaseInsensitive) < 0) return true; - } } - - return QSortFilterProxyModel::lessThan(source_left, source_right); + return false; } bool ModulePrefsModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const diff --git a/ui/qt/models/pref_models.h b/ui/qt/models/pref_models.h index 4914e61133..fb9e88e978 100644 --- a/ui/qt/models/pref_models.h +++ b/ui/qt/models/pref_models.h @@ -34,6 +34,7 @@ public: QString getPrefTypeName() const; module_t* getModule() const {return module_;} QString getModuleName() const; + QString getModuleTitle() const; void setChanged(bool changed = true); private: diff --git a/ui/qt/widgets/pref_module_view.cpp b/ui/qt/widgets/pref_module_view.cpp index 388839260d..dd0b04bbd4 100644 --- a/ui/qt/widgets/pref_module_view.cpp +++ b/ui/qt/widgets/pref_module_view.cpp @@ -46,51 +46,40 @@ void PrefModuleTreeView::setPane(const QString pane_name) //Look through appearance children if (!newIndex.isValid()) { - for (row = 0; row < model()->rowCount(appearanceIndex); row++) - { - modelIndex = model()->index(row, ModulePrefsModel::colName, appearanceIndex); - modelTreeName = model()->data(modelIndex, Qt::DisplayRole).toString(); - - if (modelTreeName.compare(pane_name) == 0) { - newIndex = modelIndex; - break; - } - } + newIndex = findModule(appearanceIndex, pane_name); } //Look through protocol children if (!newIndex.isValid()) { - for (row = 0; row < model()->rowCount(protocolIndex); row++) - { - modelIndex = model()->index(row, ModulePrefsModel::colName, protocolIndex); - PrefsItem* proto_pref = VariantPointer<PrefsItem>::asPtr(model()->data(modelIndex, Qt::UserRole)); - if (proto_pref != NULL) { - if (pane_name.compare(proto_pref->getModuleName()) == 0) { - newIndex = modelIndex; - break; - } - } - } + newIndex = findModule(protocolIndex, pane_name); } //Look through stat children if (!newIndex.isValid()) { - for (row = 0; row < model()->rowCount(protocolIndex); row++) - { - modelIndex = model()->index(row, ModulePrefsModel::colName, protocolIndex); - PrefsItem* stat_pref = VariantPointer<PrefsItem>::asPtr(model()->data(modelIndex, Qt::UserRole)); - if (stat_pref != NULL) { - if (pane_name.compare(stat_pref->getModuleName()) == 0) { - newIndex = modelIndex; - break; - } - } - } + newIndex = findModule(statIndex, pane_name); } setCurrentIndex(newIndex); } +QModelIndex PrefModuleTreeView::findModule(QModelIndex& parent, const QString& name) +{ + QModelIndex findIndex, modelIndex; + QString module_name; + + for (int row = 0; row < model()->rowCount(parent); row++) + { + modelIndex = model()->index(row, ModulePrefsModel::colName, parent); + module_name = model()->data(modelIndex, ModulePrefsModel::ModuleName).toString(); + if (name.compare(module_name) == 0) { + findIndex = modelIndex; + break; + } + } + + return findIndex; +} + void PrefModuleTreeView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) { diff --git a/ui/qt/widgets/pref_module_view.h b/ui/qt/widgets/pref_module_view.h index 8a1b871bfc..f88581117d 100644 --- a/ui/qt/widgets/pref_module_view.h +++ b/ui/qt/widgets/pref_module_view.h @@ -29,6 +29,8 @@ protected slots: void currentChanged(const QModelIndex ¤t, const QModelIndex &previous); private: + QModelIndex findModule(QModelIndex &parent, const QString& name); + //cache the translation of the module names we check frequently QString appearanceName_; }; |