Add enum for EntryModel column.

This commit is contained in:
Florian Geyer 2013-04-07 21:17:08 +02:00
parent bf906a7867
commit 34c6b416b0
3 changed files with 19 additions and 11 deletions

View File

@ -122,27 +122,27 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
if (role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {
switch (index.column()) { switch (index.column()) {
case 0: case ParentGroup:
if (entry->group()) { if (entry->group()) {
return entry->group()->name(); return entry->group()->name();
} }
break; break;
case 1: case Title:
return entry->title(); return entry->title();
case 2: case Username:
return entry->username(); return entry->username();
case 3: case Url:
return entry->url(); return entry->url();
} }
} }
else if (role == Qt::DecorationRole) { else if (role == Qt::DecorationRole) {
switch (index.column()) { switch (index.column()) {
case 0: case ParentGroup:
if (entry->group()) { if (entry->group()) {
return entry->group()->iconPixmap(); return entry->group()->iconPixmap();
} }
break; break;
case 1: case Title:
if (entry->isExpired()) { if (entry->isExpired()) {
return databaseIcons()->iconPixmap(DatabaseIcons::ExpiredIconIndex); return databaseIcons()->iconPixmap(DatabaseIcons::ExpiredIconIndex);
} }
@ -165,13 +165,13 @@ QVariant EntryModel::headerData(int section, Qt::Orientation orientation, int ro
{ {
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
switch (section) { switch (section) {
case 0: case ParentGroup:
return tr("Group"); return tr("Group");
case 1: case Title:
return tr("Title"); return tr("Title");
case 2: case Username:
return tr("Username"); return tr("Username");
case 3: case Url:
return tr("URL"); return tr("URL");
} }
} }

View File

@ -30,6 +30,14 @@ class EntryModel : public QAbstractTableModel
Q_OBJECT Q_OBJECT
public: public:
enum ModelColumn
{
ParentGroup = 0,
Title = 1,
Username = 2,
Url = 3
};
explicit EntryModel(QObject* parent = Q_NULLPTR); explicit EntryModel(QObject* parent = Q_NULLPTR);
Entry* entryFromIndex(const QModelIndex& index) const; Entry* entryFromIndex(const QModelIndex& index) const;
QModelIndex indexFromEntry(Entry* entry) const; QModelIndex indexFromEntry(Entry* entry) const;

View File

@ -70,7 +70,7 @@ void EntryView::emitEntryActivationSignal(const QModelIndex& index)
{ {
Entry* entry = entryFromIndex(index); Entry* entry = entryFromIndex(index);
if (m_sortModel->mapToSource(index).column() == 3) { if (m_sortModel->mapToSource(index).column() == EntryModel::Url) {
Q_EMIT openUrl(entry); Q_EMIT openUrl(entry);
} }
else { else {