22 #include "etmviewstatesaver.h"
24 #include <QtCore/QModelIndex>
26 #include "entitytreemodel.h"
28 using namespace Akonadi;
30 ETMViewStateSaver::ETMViewStateSaver(QObject* parent)
31 : KViewStateSaver(parent)
35 QModelIndex ETMViewStateSaver::indexFromConfigString(
const QAbstractItemModel *model,
const QString& key)
const
37 if ( key.startsWith( QLatin1Char(
'x' ) ) )
44 if ( key.startsWith( QLatin1Char(
'c' ) ) ) {
46 if ( !idx.isValid() ) {
50 }
else if ( key.startsWith( QLatin1Char(
'i' ) ) ) {
52 if ( list.isEmpty() ) {
60 QString ETMViewStateSaver::indexToConfigString(
const QModelIndex& index)
const
62 if ( !index.isValid() ) {
63 return QLatin1String(
"x-1" );
67 return QString::fromLatin1(
"c%1" ).arg( c.
id() );
71 return QString::fromLatin1(
"i%1" ).arg(
id );
78 QStringList colStrings;
80 colStrings << QString::fromLatin1(
"c%1" ).arg( col.
id() );
82 restoreSelection( colStrings );
85 void ETMViewStateSaver::selectCollections(
const QList< Collection::Id >& list)
87 QStringList colStrings;
89 colStrings << QString::fromLatin1(
"c%1" ).arg( colId );
91 restoreSelection( colStrings );
94 void ETMViewStateSaver::selectItems(
const Akonadi::Item::List& list)
96 QStringList itemStrings;
97 foreach (
const Item &item, list ) {
98 itemStrings << QString::fromLatin1(
"i%1" ).arg( item.id() );
100 restoreSelection( itemStrings );
103 void ETMViewStateSaver::selectItems(
const QList< Item::Id >& list)
105 QStringList itemStrings;
106 foreach (
const Item::Id &itemId, list) {
107 itemStrings << QString::fromLatin1(
"i%1" ).arg( itemId );
109 restoreSelection( itemStrings );
Represents a collection of PIM items.
qint64 Id
Describes the unique id type.
Id id() const
Returns the unique identifier of the entity.
static QModelIndex modelIndexForCollection(const QAbstractItemModel *model, const Collection &collection)
Returns a QModelIndex in model which points to collection.
static QModelIndexList modelIndexesForItem(const QAbstractItemModel *model, const Item &item)
Returns a QModelIndex in model which points to item.
bool isValid() const
Returns whether the entity is valid.
QList< Collection > List
Describes a list of collections.