aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/models
diff options
context:
space:
mode:
authorRoland Knall <rknall@gmail.com>2019-07-20 23:38:24 +0200
committerRoland Knall <rknall@gmail.com>2019-07-22 15:57:48 +0000
commit91ed69488f6bcd486ae0673c4af58f1257a671af (patch)
tree2223308e44c788f7620e5c7abcfc159fe8cd0711 /ui/qt/models
parent429082dd71a00e7eb67efb6c8c20d0b95c532da1 (diff)
Qt: Cleanup data() method and interface
Interface resembles the old interface Change-Id: I7301f8bb6e00d30c20d7e5fdc9252a6a1765ff97 Reviewed-on: https://code.wireshark.org/review/34054 Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
Diffstat (limited to 'ui/qt/models')
-rw-r--r--ui/qt/models/profile_model.cpp292
-rw-r--r--ui/qt/models/profile_model.h13
2 files changed, 172 insertions, 133 deletions
diff --git a/ui/qt/models/profile_model.cpp b/ui/qt/models/profile_model.cpp
index 441828359a..5e38c93dc4 100644
--- a/ui/qt/models/profile_model.cpp
+++ b/ui/qt/models/profile_model.cpp
@@ -188,10 +188,8 @@ profile_def * ProfileModel::guard(int row) const
return profiles_.at(row);
}
-QVariant ProfileModel::data(const QModelIndex &index, int role) const
+QVariant ProfileModel::dataDisplay(const QModelIndex &index) const
{
- QString msg;
-
if ( ! index.isValid() || profiles_.count() <= index.row() )
return QVariant();
@@ -199,140 +197,196 @@ QVariant ProfileModel::data(const QModelIndex &index, int role) const
if ( ! prof )
return QVariant();
- switch ( role )
+ switch (index.column())
{
- case Qt::DisplayRole:
- switch (index.column())
- {
- case COL_NAME:
- return QString(prof->name);
- case COL_TYPE:
- if ( prof->status == PROF_STAT_DEFAULT )
- return tr("Default");
- else if ( prof->is_global )
- return tr("System");
- else
- return tr("User");
- case COL_PATH:
- switch (prof->status)
- {
- case PROF_STAT_DEFAULT:
- if (!reset_default_)
- return get_persconffile_path("", FALSE);
- else
- return tr("Resetting to default");
- case PROF_STAT_EXISTS:
- {
- QString profile_path = prof->is_global ? get_global_profiles_dir() : get_profiles_dir();
- profile_path.append(QDir::separator()).append(prof->name);
- return profile_path;
- }
- case PROF_STAT_NEW:
- return tr("Created from default settings");
- case PROF_STAT_CHANGED:
- if (prof->reference)
- return QString("%1 %2").arg(tr("Renamed from: ")).arg(prof->reference);
- break;
- case PROF_STAT_COPY:
- if (prof->reference)
- return QString("%1 %2").arg(tr("Copied from: ")).arg(prof->reference);
- break;
- }
- break;
- default:
- break;
- }
+ case COL_NAME:
+ return QString(prof->name);
+ case COL_TYPE:
+ if ( prof->status == PROF_STAT_DEFAULT )
+ return tr("Default");
+ else if ( prof->is_global )
+ return tr("System");
+ else
+ return tr("User");
+ default:
break;
+ }
- case Qt::FontRole:
- {
- QFont font;
+ return QVariant();
+}
+
+QVariant ProfileModel::dataFontRole(const QModelIndex &index) const
+{
+ if ( ! index.isValid() || profiles_.count() <= index.row() )
+ return QVariant();
+
+ profile_def * prof = guard(index.row());
+ if ( ! prof )
+ return QVariant();
+
+ QFont font;
if ( prof->is_global )
- font.setItalic(true);
+ font.setItalic(true);
if ( set_profile_.compare(prof->name) == 0 && ! prof->is_global )
font.setBold(true);
- if ( prof->status == PROF_STAT_DEFAULT && reset_default_ )
- font.setStrikeOut(true);
+ if ( prof->status == PROF_STAT_DEFAULT && reset_default_ )
+ font.setStrikeOut(true);
- return font;
- }
+ return font;
+}
- case Qt::BackgroundColorRole:
- {
- if ( ! ProfileModel::checkNameValidity(QString(prof->name)) )
- return ColorUtils::fromColorT(&prefs.gui_text_invalid);
+QVariant ProfileModel::dataBackgroundRole(const QModelIndex &index) const
+{
+ if ( ! index.isValid() || profiles_.count() <= index.row() )
+ return QVariant();
+
+ profile_def * prof = guard(index.row());
+ if ( ! prof )
+ return QVariant();
- if ( prof->status == PROF_STAT_DEFAULT && reset_default_ )
- return ColorUtils::fromColorT(&prefs.gui_text_deprecated);
+ if ( ! ProfileModel::checkNameValidity(QString(prof->name)) )
+ return ColorUtils::fromColorT(&prefs.gui_text_invalid);
- QList<int> rows = const_cast<ProfileModel *>(this)->findAllByNameAndVisibility(QString(prof->name), prof->is_global);
- if ( rows.count() > 1 )
- return ColorUtils::fromColorT(&prefs.gui_text_invalid);
+ if ( prof->status == PROF_STAT_DEFAULT && reset_default_ )
+ return ColorUtils::fromColorT(&prefs.gui_text_deprecated);
- break;
- }
+ QList<int> rows = const_cast<ProfileModel *>(this)->findAllByNameAndVisibility(QString(prof->name), prof->is_global);
+ if ( rows.count() > 1 )
+ return ColorUtils::fromColorT(&prefs.gui_text_invalid);
- case Qt::ToolTipRole:
- switch (prof->status)
- {
- case PROF_STAT_DEFAULT:
- if (reset_default_)
- return tr("Will be reset to default values");
- break;
- case PROF_STAT_COPY:
- if (prof->reference) {
- QString reference = prof->reference;
- GList *fl_entry = entry(prof);
- if (fl_entry)
- {
- profile_def *profile = reinterpret_cast<profile_def *>(fl_entry->data);
- if (strcmp(prof->reference, profile->reference) == 0) {
- if (profile->status == PROF_STAT_CHANGED) {
- // Reference profile was renamed, use the new name
- reference = profile->name;
- break;
- }
+ return QVariant();
+}
+
+QVariant ProfileModel::dataToolTipRole(const QModelIndex &idx) const
+{
+ if ( ! idx.isValid() || profiles_.count() <= idx.row() )
+ return QVariant();
+
+ profile_def * prof = guard(idx.row());
+ if ( ! prof )
+ return QVariant();
+
+ QString msg;
+
+ switch (prof->status)
+ {
+ case PROF_STAT_DEFAULT:
+ if (reset_default_)
+ return tr("Will be reset to default values");
+ break;
+ case PROF_STAT_COPY:
+ if (prof->reference) {
+ QString reference = prof->reference;
+ GList *fl_entry = entry(prof);
+ if (fl_entry)
+ {
+ profile_def *profile = reinterpret_cast<profile_def *>(fl_entry->data);
+ if (strcmp(prof->reference, profile->reference) == 0) {
+ if (profile->status == PROF_STAT_CHANGED) {
+ // Reference profile was renamed, use the new name
+ reference = profile->name;
+ break;
}
}
+ }
- QString profile_info = tr("Created from %1").arg(reference);
- if (prof->from_global) {
- profile_info.append(QString(" %1").arg(tr("(system provided)")));
- } else if (!reference.isEmpty()) {
- profile_info.append(QString(" %1").arg(tr("(deleted)")));
- }
- return profile_info;
+ QString profile_info = tr("Created from %1").arg(reference);
+ if (prof->from_global) {
+ profile_info.append(QString(" %1").arg(tr("(system provided)")));
+ } else if (!reference.isEmpty()) {
+ profile_info.append(QString(" %1").arg(tr("(deleted)")));
}
- break;
- case PROF_STAT_NEW:
- return tr("Created from default settings");
- default:
- break;
+ return profile_info;
}
+ break;
+ case PROF_STAT_NEW:
+ return tr("Created from default settings");
+ default:
+ break;
+ }
+
+ if ( ! ProfileModel::checkNameValidity(QString(prof->name), &msg) )
+ return msg;
+
+ if (prof->is_global)
+ return tr("This is a system provided profile.");
+ if ( prof->status == PROF_STAT_DEFAULT && reset_default_ )
+ return tr("The profile will be reset to default values.");
+
+ return QVariant();
+}
- if ( ! ProfileModel::checkNameValidity(QString(prof->name), &msg) )
- return msg;
+QVariant ProfileModel::dataPath(const QModelIndex &index) const
+{
+ if ( ! index.isValid() || profiles_.count() <= index.row() )
+ return QVariant();
- if (prof->is_global)
- return tr("This is a system provided profile.");
- if ( prof->status == PROF_STAT_DEFAULT && reset_default_ )
- return tr("The profile will be reset to default values.");
+ profile_def * prof = guard(index.row());
+ if ( ! prof )
+ return QVariant();
+ switch (prof->status)
+ {
+ case PROF_STAT_DEFAULT:
+ if (!reset_default_)
+ return get_persconffile_path("", FALSE);
+ else
+ return tr("Resetting to default");
+ case PROF_STAT_EXISTS:
+ {
+ QString profile_path = prof->is_global ? get_global_profiles_dir() : get_profiles_dir();
+ profile_path.append(QDir::separator()).append(prof->name);
+ return profile_path;
+ }
+ case PROF_STAT_NEW:
+ return tr("Created from default settings");
+ case PROF_STAT_CHANGED:
+ if (prof->reference)
+ return QString("%1 %2").arg(tr("Renamed from: ")).arg(prof->reference);
break;
+ case PROF_STAT_COPY:
+ if (prof->reference)
+ return QString("%1 %2").arg(tr("Copied from: ")).arg(prof->reference);
+ break;
+ }
+
+ return QVariant();
+}
+QVariant ProfileModel::data(const QModelIndex &index, int role) const
+{
+ QString msg;
+
+ if ( ! index.isValid() || profiles_.count() <= index.row() )
+ return QVariant();
+
+ profile_def * prof = guard(index.row());
+ if ( ! prof )
+ return QVariant();
+
+ switch ( role )
+ {
+ case Qt::DisplayRole:
+ return dataDisplay(index);
+ break;
+ case Qt::FontRole:
+ return dataFontRole(index);
+ break;
+ case Qt::BackgroundColorRole:
+ return dataBackgroundRole(index);
+ break;
+ case Qt::ToolTipRole:
+ return dataToolTipRole(index);
+ break;
case ProfileModel::DATA_STATUS:
return qVariantFromValue(prof->status);
-
case ProfileModel::DATA_IS_DEFAULT:
return qVariantFromValue(prof->status == PROF_STAT_DEFAULT);
-
-
case ProfileModel::DATA_IS_GLOBAL:
return qVariantFromValue(prof->is_global);
-
case ProfileModel::DATA_IS_SELECTED:
{
QModelIndex selected = activeProfile();
@@ -347,6 +401,10 @@ QVariant ProfileModel::data(const QModelIndex &index, int role) const
}
return qVariantFromValue(false);
}
+ break;
+ case ProfileModel::DATA_PATH:
+ return dataPath(index);
+ break;
case ProfileModel::DATA_PATH_IS_NOT_DESCRIPTION:
if ( prof->status == PROF_STAT_NEW || prof->status == PROF_STAT_COPY
@@ -360,26 +418,6 @@ QVariant ProfileModel::data(const QModelIndex &index, int role) const
break;
}
-#if 0
- if (pd_ui_->profileTreeView->topLevelItemCount() > 0) {
- profile_def *profile;
- for (int i = 0; i < pd_ui_->profileTreeView->topLevelItemCount(); i++) {
- item = pd_ui_->profileTreeView->topLevelItem(i);
- profile = (profile_def *) VariantPointer<GList>::asPtr(item->data(0, Qt::UserRole))->data;
- if (current_profile && !current_profile->is_global && profile != current_profile && strcmp(profile->name, current_profile->name) == 0) {
- item->setToolTip(0, tr("A profile already exists with this name."));
- item->setBackground(0, ColorUtils::fromColorT(&prefs.gui_text_invalid));
- if (current_profile->status != PROF_STAT_DEFAULT &&
- current_profile->status != PROF_STAT_EXISTS)
- {
- pd_ui_->infoLabel->setText(tr("A profile already exists with this name"));
- }
- enable_ok = false;
- }
- }
- }
-#endif
-
return QVariant();
}
@@ -393,8 +431,6 @@ QVariant ProfileModel::headerData(int section, Qt::Orientation orientation, int
return tr("Profile");
case COL_TYPE:
return tr("Type");
- case COL_PATH:
- return tr("Path");
default:
break;
}
diff --git a/ui/qt/models/profile_model.h b/ui/qt/models/profile_model.h
index bb2f6ecd99..42aeaa748a 100644
--- a/ui/qt/models/profile_model.h
+++ b/ui/qt/models/profile_model.h
@@ -57,7 +57,6 @@ public:
enum {
COL_NAME,
COL_TYPE,
- COL_PATH,
_LAST_ENTRY
} columns_;
@@ -66,10 +65,8 @@ public:
DATA_IS_DEFAULT,
DATA_IS_GLOBAL,
DATA_IS_SELECTED,
- DATA_PATH_IS_NOT_DESCRIPTION,
- DATA_COL_NAME,
- DATA_COL_TYPE,
- DATA_COL_PATH
+ DATA_PATH,
+ DATA_PATH_IS_NOT_DESCRIPTION
} data_values_;
// QAbstractItemModel interface
@@ -118,6 +115,12 @@ private:
static bool acceptFile(QString fileName, int fileSize);
#endif
+ QVariant dataDisplay(const QModelIndex & idx) const;
+ QVariant dataFontRole(const QModelIndex & idx) const;
+ QVariant dataBackgroundRole(const QModelIndex & idx) const;
+ QVariant dataToolTipRole(const QModelIndex & idx) const;
+ QVariant dataPath(const QModelIndex & idx) const;
+
};
#endif