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>
This commit is contained in:
Michael Mann 2018-01-06 21:40:19 -05:00 committed by Anders Broman
parent 985f7d023e
commit c53412f7db
4 changed files with 51 additions and 52 deletions

View File

@ -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

View File

@ -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:

View File

@ -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 &current, const QModelIndex &previous)
{

View File

@ -29,6 +29,8 @@ protected slots:
void currentChanged(const QModelIndex &current, const QModelIndex &previous);
private:
QModelIndex findModule(QModelIndex &parent, const QString& name);
//cache the translation of the module names we check frequently
QString appearanceName_;
};