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

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • libs
  • kasten
  • controllers
  • documentsystem
  • documentsbrowser
documentlistmodel.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Kasten Framework, made within the KDE community.
3 
4  Copyright 2009,2012 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "documentlistmodel.h"
24 
25 // lib
26 #include "documentstool.h"
27 // Kasten core
28 #include <abstractmodelsynchronizer.h>
29 #include <abstractdocument.h>
30 // KDE
31 #include <KLocale>
32 #include <KIcon>
33 #include <unistd.h>
34 
35 
36 namespace Kasten2
37 {
38 
39 DocumentListModel::DocumentListModel( DocumentsTool* documentsTool, QObject* parent )
40  : QAbstractTableModel( parent ),
41  mDocumentsTool( documentsTool )
42 {
43  connect( mDocumentsTool, SIGNAL(documentsAdded(QList<Kasten2::AbstractDocument*>)),
44  SLOT(onDocumentsAdded(QList<Kasten2::AbstractDocument*>)) );
45  connect( mDocumentsTool, SIGNAL(documentsClosing(QList<Kasten2::AbstractDocument*>)),
46  SLOT(onDocumentsClosing(QList<Kasten2::AbstractDocument*>)) );
47  connect( mDocumentsTool, SIGNAL(focussedDocumentChanged(Kasten2::AbstractDocument*)),
48  SLOT(onFocussedDocumentChanged(Kasten2::AbstractDocument*)) );
49 }
50 
51 int DocumentListModel::rowCount( const QModelIndex& parent ) const
52 {
53  return (! parent.isValid()) ? mDocumentsTool->documents().size() : 0;
54 }
55 
56 int DocumentListModel::columnCount( const QModelIndex& parent ) const
57 {
58  return (! parent.isValid()) ? NoOfColumnIds : 0;
59 }
60 
61 QVariant DocumentListModel::data( const QModelIndex& index, int role ) const
62 {
63  QVariant result;
64 
65  if( role == Qt::DisplayRole )
66  {
67  const int documentIndex = index.row();
68  const AbstractDocument* document = mDocumentsTool->documents().at( documentIndex );
69 
70  const int tableColumn = index.column();
71  switch( tableColumn )
72  {
73  case TitleColumnId:
74  result = document->title();
75  break;
76  default:
77  ;
78  }
79  }
80  else if( role == Qt::DecorationRole )
81  {
82  const int documentIndex = index.row();
83  const AbstractDocument* document = mDocumentsTool->documents().at( documentIndex );
84  const AbstractModelSynchronizer* synchronizer = document ? document->synchronizer() : 0;
85 
86  const int tableColumn = index.column();
87  switch( tableColumn )
88  {
89  case CurrentColumnId:
90  if( document == mDocumentsTool->focussedDocument() )
91  result = KIcon( QLatin1String("arrow-right") );
92  break;
93  case LocalStateColumnId:
94  if( synchronizer && synchronizer->localSyncState() == LocalHasChanges )
95  result = KIcon( QLatin1String("document-save") );
96  break;
97  case RemoteStateColumnId:
98  // TODO: use static map, syncState int -> iconname
99  if( ! synchronizer )
100  result = KIcon( QLatin1String("document-new") );
101  else
102  {
103  const RemoteSyncState remoteSyncState = synchronizer->remoteSyncState();
104  if( remoteSyncState == RemoteHasChanges )
105  result = KIcon( QLatin1String("document-save") );
106  else if( remoteSyncState == RemoteDeleted )
107  result = KIcon( QLatin1String("edit-delete") );
108  else if( remoteSyncState == RemoteUnknown )
109  result = KIcon( QLatin1String("flag-yellow") );
110  else if( remoteSyncState == RemoteUnreachable )
111  result = KIcon( QLatin1String("network-disconnect") );
112  }
113  break;
114  default:
115  ;
116  }
117  }
118 
119  return result;
120 }
121 
122 QVariant DocumentListModel::headerData( int section, Qt::Orientation orientation, int role ) const
123 {
124  QVariant result;
125 
126  if( role == Qt::DisplayRole )
127  {
128  const QString titel =
129 // section == LocalStateColumnId ? i18nc("@title:column Id of the version", "Id") :
130  section == TitleColumnId ? i18nc("@title:column description of the change", "Title") :
131  QString();
132  result = titel;
133  }
134  else if( role == Qt::ToolTipRole )
135  {
136  const QString titel =
137 // section == LocalStateColumnId ? i18nc("@info:tooltip","Id of the version") :
138  section == TitleColumnId ? i18nc("@info:tooltip","Title of the document") :
139  QString();
140  result = titel;
141  }
142  else
143  result = QAbstractTableModel::headerData( section, orientation, role );
144 
145  return result;
146 }
147 
148 void DocumentListModel::onFocussedDocumentChanged( AbstractDocument* document )
149 {
150 Q_UNUSED( document )
151 
152  reset();
153 // TODO: store current focused document, then only emit for changed
154 #if 0
155  const int oldVersionIndex = mVersionIndex;
156  mVersionIndex = versionIndex;
157 
158  emit dataChanged( index(versionIndex,CurrentColumnId), index(versionIndex,CurrentColumnId) );
159  emit dataChanged( index(oldVersionIndex,CurrentColumnId), index(oldVersionIndex,CurrentColumnId) );
160 #endif
161 }
162 
163 void DocumentListModel::onDocumentsAdded( const QList<Kasten2::AbstractDocument*>& documents )
164 {
165  foreach( AbstractDocument* document, documents )
166  {
167  connect( document, SIGNAL(synchronizerChanged(Kasten2::AbstractModelSynchronizer*)),
168  SLOT(onSynchronizerChanged(Kasten2::AbstractModelSynchronizer*)) );
169  AbstractModelSynchronizer* synchronizer = document->synchronizer();
170  if( synchronizer )
171  {
172  connect( synchronizer, SIGNAL(localSyncStateChanged(Kasten2::LocalSyncState)),
173  SLOT(onSyncStatesChanged()) );
174  connect( synchronizer, SIGNAL(remoteSyncStateChanged(Kasten2::RemoteSyncState)),
175  SLOT(onSyncStatesChanged()) );
176  }
177  }
178  // TODO: try to understand how this whould be done with {begin,end}{Insert,Remove}Columns
179  reset();
180 }
181 
182 void DocumentListModel::onDocumentsClosing( const QList<Kasten2::AbstractDocument*>& documents )
183 {
184 Q_UNUSED( documents )
185  // TODO: try to understand how this whould be done with {begin,end}{Insert,Remove}Columns
186  reset();
187 }
188 
189 
190 void DocumentListModel::onSynchronizerChanged( AbstractModelSynchronizer* synchronizer )
191 {
192  // TODO: what about the old synchronizer? assume it is deleted and that way disconnects?
193  if( synchronizer )
194  {
195  connect( synchronizer, SIGNAL(localSyncStateChanged(Kasten2::LocalSyncState)),
196  SLOT(onSyncStatesChanged()) );
197  connect( synchronizer, SIGNAL(remoteSyncStateChanged(Kasten2::RemoteSyncState)),
198  SLOT(onSyncStatesChanged()) );
199  }
200  // TODO: try to understand how this whould be done with {begin,end}{Insert,Remove}Columns
201  reset();
202 }
203 
204 void DocumentListModel::onSyncStatesChanged()
205 {
206  // TODO: try to understand how this whould be done with {begin,end}{Insert,Remove}Columns
207  reset();
208 }
209 
210 
211 DocumentListModel::~DocumentListModel() {}
212 
213 }
Kasten2::RemoteUnreachable
unknown, e.g. because connection not available/lost
Definition: kastencore.h:47
Kasten2::LocalSyncState
LocalSyncState
Definition: kastencore.h:33
abstractdocument.h
Kasten2::DocumentListModel::NoOfColumnIds
Definition: documentlistmodel.h:49
Kasten2::AbstractModel::title
virtual QString title() const =0
Kasten2::DocumentsTool::documents
QList< AbstractDocument * > documents() const
Definition: documentstool.cpp:46
Kasten2::DocumentListModel::columnCount
virtual int columnCount(const QModelIndex &parent) const
Definition: documentlistmodel.cpp:56
Kasten2::DocumentListModel::LocalStateColumnId
Definition: documentlistmodel.h:46
Kasten2::DocumentListModel::RemoteStateColumnId
Definition: documentlistmodel.h:47
Kasten2::DocumentListModel::DocumentListModel
DocumentListModel(DocumentsTool *documentsTool, QObject *parent=0)
Definition: documentlistmodel.cpp:39
QObject
Kasten2::DocumentListModel::CurrentColumnId
Definition: documentlistmodel.h:45
Kasten2::RemoteDeleted
Definition: kastencore.h:43
Kasten2::RemoteSyncState
RemoteSyncState
Definition: kastencore.h:39
Kasten2::DocumentsTool
Definition: documentstool.h:38
Kasten2::DocumentListModel::TitleColumnId
Definition: documentlistmodel.h:48
Kasten2::AbstractModelSynchronizer::localSyncState
virtual LocalSyncState localSyncState() const =0
Kasten2::AbstractModelSynchronizer::remoteSyncState
virtual RemoteSyncState remoteSyncState() const =0
abstractmodelsynchronizer.h
Kasten2::RemoteUnknown
Definition: kastencore.h:45
documentstool.h
Kasten2::DocumentListModel::rowCount
virtual int rowCount(const QModelIndex &parent) const
Definition: documentlistmodel.cpp:51
Kasten2::DocumentsTool::focussedDocument
AbstractDocument * focussedDocument() const
Definition: documentstool.h:69
Kasten2::AbstractDocument
Definition: abstractdocument.h:43
Kasten2::RemoteHasChanges
Definition: kastencore.h:42
Kasten2::DocumentListModel::data
virtual QVariant data(const QModelIndex &index, int role) const
Definition: documentlistmodel.cpp:61
Kasten2::AbstractModelSynchronizer
possible actions:
Definition: abstractmodelsynchronizer.h:61
Kasten2::AbstractDocument::synchronizer
AbstractModelSynchronizer * synchronizer() const
Definition: abstractdocument.cpp:40
Kasten2::LocalHasChanges
Definition: kastencore.h:36
QAbstractTableModel
Kasten2::DocumentListModel::~DocumentListModel
virtual ~DocumentListModel()
Definition: documentlistmodel.cpp:211
documentlistmodel.h
QList< Kasten2::AbstractDocument * >
Kasten2::DocumentListModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
Definition: documentlistmodel.cpp:122
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

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

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

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