akonadi
etmviewstatesaver.cpp
00001 /* 00002 Copyright (C) 2010 Klarälvdalens Datakonsult AB, 00003 a KDAB Group company, info@kdab.net, 00004 author Stephen Kelly <stephen@kdab.com> 00005 00006 This library is free software; you can redistribute it and/or modify it 00007 under the terms of the GNU Library General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or (at your 00009 option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, but WITHOUT 00012 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00014 License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to the 00018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00019 02110-1301, USA. 00020 */ 00021 00022 #include "etmviewstatesaver.h" 00023 00024 #include <QtCore/QModelIndex> 00025 #include <QtGui/QItemSelection> 00026 #include <QtGui/QTreeView> 00027 00028 #include "entitytreemodel.h" 00029 00030 using namespace Akonadi; 00031 00032 ETMViewStateSaver::ETMViewStateSaver(QObject* parent) 00033 : KViewStateSaver(parent) 00034 { 00035 } 00036 00037 QModelIndex ETMViewStateSaver::indexFromConfigString(const QAbstractItemModel *model, const QString& key) const 00038 { 00039 if ( key.startsWith( QLatin1Char( 'x' ) ) ) 00040 return QModelIndex(); 00041 00042 Entity::Id id = key.mid( 1 ).toLongLong(); 00043 if ( id < 0 ) 00044 return QModelIndex(); 00045 00046 if ( key.startsWith( QLatin1Char( 'c' ) ) ) 00047 { 00048 QModelIndex idx = EntityTreeModel::modelIndexForCollection( model, Collection( id ) ); 00049 if ( !idx.isValid() ) 00050 { 00051 return QModelIndex(); 00052 } 00053 return idx; 00054 } 00055 else if ( key.startsWith( QLatin1Char( 'i' ) ) ) 00056 { 00057 QModelIndexList list = EntityTreeModel::modelIndexesForItem( model, Item( id ) ); 00058 if ( list.isEmpty() ) 00059 { 00060 return QModelIndex(); 00061 } 00062 return list.first(); 00063 } 00064 return QModelIndex(); 00065 } 00066 00067 QString ETMViewStateSaver::indexToConfigString(const QModelIndex& index) const 00068 { 00069 if ( !index.isValid() ) 00070 return QLatin1String( "x-1" ); 00071 const Collection c = index.data( EntityTreeModel::CollectionRole ).value<Collection>(); 00072 if ( c.isValid() ) 00073 return QString::fromLatin1( "c%1" ).arg( c.id() ); 00074 Entity::Id id = index.data( EntityTreeModel::ItemIdRole ).value<Entity::Id>(); 00075 if ( id >= 0 ) 00076 return QString::fromLatin1( "i%1" ).arg( id ); 00077 return QString(); 00078 } 00079 00080 void ETMViewStateSaver::selectCollections(const Akonadi::Collection::List& list) 00081 { 00082 QStringList colStrings; 00083 foreach(const Collection &col, list) 00084 colStrings << QString::fromLatin1( "c%1" ).arg( col.id() ); 00085 restoreSelection(colStrings); 00086 } 00087 00088 void ETMViewStateSaver::selectCollections(const QList< Collection::Id >& list) 00089 { 00090 QStringList colStrings; 00091 foreach(const Collection::Id &colId, list) 00092 colStrings << QString::fromLatin1( "c%1" ).arg( colId ); 00093 restoreSelection(colStrings); 00094 } 00095 00096 void ETMViewStateSaver::selectItems(const Akonadi::Item::List& list) 00097 { 00098 QStringList itemStrings; 00099 foreach(const Item &item, list) 00100 itemStrings << QString::fromLatin1( "i%1" ).arg( item.id() ); 00101 restoreSelection(itemStrings); 00102 } 00103 00104 void ETMViewStateSaver::selectItems(const QList< Item::Id >& list) 00105 { 00106 QStringList itemStrings; 00107 foreach(const Item::Id &itemId, list) 00108 itemStrings << QString::fromLatin1( "i%1" ).arg( itemId ); 00109 restoreSelection(itemStrings); 00110 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 22:18:33 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 22:18:33 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.