• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • akonadi
etmviewstatesaver.cpp
1 /*
2  Copyright (C) 2010 Klarälvdalens Datakonsult AB,
3  a KDAB Group company, info@kdab.net,
4  author Stephen Kelly <stephen@kdab.com>
5 
6  This library is free software; you can redistribute it and/or modify it
7  under the terms of the GNU Library General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or (at your
9  option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14  License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301, USA.
20 */
21 
22 #include "etmviewstatesaver.h"
23 
24 #include <QtCore/QModelIndex>
25 #include <QItemSelection>
26 #include <QTreeView>
27 
28 #include "entitytreemodel.h"
29 
30 using namespace Akonadi;
31 
32 ETMViewStateSaver::ETMViewStateSaver(QObject* parent)
33  : KViewStateSaver(parent)
34 {
35 }
36 
37 QModelIndex ETMViewStateSaver::indexFromConfigString(const QAbstractItemModel *model, const QString& key) const
38 {
39  if ( key.startsWith( QLatin1Char( 'x' ) ) )
40  return QModelIndex();
41 
42  Entity::Id id = key.mid( 1 ).toLongLong();
43  if ( id < 0 )
44  return QModelIndex();
45 
46  if ( key.startsWith( QLatin1Char( 'c' ) ) ) {
47  QModelIndex idx = EntityTreeModel::modelIndexForCollection( model, Collection( id ) );
48  if ( !idx.isValid() ) {
49  return QModelIndex();
50  }
51  return idx;
52  } else if ( key.startsWith( QLatin1Char( 'i' ) ) ) {
53  QModelIndexList list = EntityTreeModel::modelIndexesForItem( model, Item( id ) );
54  if ( list.isEmpty() ) {
55  return QModelIndex();
56  }
57  return list.first();
58  }
59  return QModelIndex();
60 }
61 
62 QString ETMViewStateSaver::indexToConfigString(const QModelIndex& index) const
63 {
64  if ( !index.isValid() ) {
65  return QLatin1String( "x-1" );
66  }
67  const Collection c = index.data( EntityTreeModel::CollectionRole ).value<Collection>();
68  if ( c.isValid() ) {
69  return QString::fromLatin1( "c%1" ).arg( c.id() );
70  }
71  Entity::Id id = index.data( EntityTreeModel::ItemIdRole ).value<Entity::Id>();
72  if ( id >= 0 ) {
73  return QString::fromLatin1( "i%1" ).arg( id );
74  }
75  return QString();
76 }
77 
78 void ETMViewStateSaver::selectCollections(const Akonadi::Collection::List& list)
79 {
80  QStringList colStrings;
81  foreach ( const Collection &col, list ) {
82  colStrings << QString::fromLatin1( "c%1" ).arg( col.id() );
83  }
84  restoreSelection( colStrings );
85 }
86 
87 void ETMViewStateSaver::selectCollections(const QList< Collection::Id >& list)
88 {
89  QStringList colStrings;
90  foreach ( const Collection::Id &colId, list ) {
91  colStrings << QString::fromLatin1( "c%1" ).arg( colId );
92  }
93  restoreSelection( colStrings );
94 }
95 
96 void ETMViewStateSaver::selectItems(const Akonadi::Item::List& list)
97 {
98  QStringList itemStrings;
99  foreach ( const Item &item, list ) {
100  itemStrings << QString::fromLatin1( "i%1" ).arg( item.id() );
101  }
102  restoreSelection( itemStrings );
103 }
104 
105 void ETMViewStateSaver::selectItems(const QList< Item::Id >& list)
106 {
107  QStringList itemStrings;
108  foreach (const Item::Id &itemId, list) {
109  itemStrings << QString::fromLatin1( "i%1" ).arg( itemId );
110  }
111  restoreSelection( itemStrings );
112 }
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::Entity::Id
qint64 Id
Describes the unique id type.
Definition: entity.h:65
Akonadi::EntityTreeModel::CollectionRole
The collection.
Definition: entitytreemodel.h:335
Akonadi::Entity::id
Id id() const
Returns the unique identifier of the entity.
Definition: entity.cpp:72
Akonadi::EntityTreeModel::modelIndexForCollection
static QModelIndex modelIndexForCollection(const QAbstractItemModel *model, const Collection &collection)
Returns a QModelIndex in model which points to collection.
Definition: entitytreemodel.cpp:1192
Akonadi::EntityTreeModel::modelIndexesForItem
static QModelIndexList modelIndexesForItem(const QAbstractItemModel *model, const Item &item)
Returns a QModelIndex in model which points to item.
Definition: entitytreemodel.cpp:1201
Akonadi::Entity::isValid
bool isValid() const
Returns whether the entity is valid.
Definition: entity.cpp:97
Akonadi::Collection::List
QList< Collection > List
Describes a list of collections.
Definition: collection.h:81
Akonadi::EntityTreeModel::ItemIdRole
The item id.
Definition: entitytreemodel.h:330
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal