• 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
  • document
  • versionview
versiontablemodel.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 2008 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 "versiontablemodel.h"
24 
25 // Kasten core
26 #include <versionable.h>
27 #include <abstractmodel.h>
28 // KDE
29 #include <KLocale>
30 #include <KIcon>
31 
32 
33 namespace Kasten2
34 {
35 
36 VersionTableModel::VersionTableModel( AbstractModel* model, If::Versionable* versionControl, QObject* parent )
37  : QAbstractTableModel( parent ),
38  mModel( model ),
39  mVersionControl( versionControl ),
40  mVersionIndex( versionControl ? versionControl->versionIndex() : 0 )
41 {
42  if( mModel )
43  {
44  connect( mModel, SIGNAL(revertedToVersionIndex(int)), SLOT(onRevertedToVersionIndex(int)) );
45  connect( mModel, SIGNAL(headVersionChanged(int)), SLOT(onHeadVersionChanged(int)) );
46  connect( mModel, SIGNAL(headVersionDataChanged(Kasten2::DocumentVersionData)),
47  SLOT(onHeadVersionDataChanged(Kasten2::DocumentVersionData)) );
48  }
49 }
50 
51 void VersionTableModel::setModel( AbstractModel* model, If::Versionable* versionControl )
52 {
53  if( mModel ) mModel->disconnect( this );
54 
55  mModel = model;
56  mVersionControl = versionControl;
57 
58  if( mModel )
59  {
60  connect( mModel, SIGNAL(revertedToVersionIndex(int)), SLOT(onRevertedToVersionIndex(int)) );
61  connect( mModel, SIGNAL(headVersionChanged(int)), SLOT(onHeadVersionChanged(int)) );
62  connect( mModel, SIGNAL(headVersionDataChanged(Kasten2::DocumentVersionData)),
63  SLOT(onHeadVersionDataChanged(Kasten2::DocumentVersionData)) );
64  }
65  mVersionIndex = versionControl ? versionControl->versionIndex() : 0;
66 
67  reset();
68 }
69 
70 int VersionTableModel::rowCount( const QModelIndex &parent ) const
71 {
72  return (! parent.isValid() && mVersionControl ) ? mVersionControl->versionCount() : 0;
73 }
74 
75 int VersionTableModel::columnCount( const QModelIndex &parent ) const
76 {
77  return (! parent.isValid()) ? NoOfColumnIds : 0;
78 }
79 
80 QVariant VersionTableModel::data( const QModelIndex &index, int role ) const
81 {
82  QVariant result;
83  if( role == Qt::DisplayRole )
84  {
85  const int versionIndex = index.row();
86  const DocumentVersionData version = mVersionControl->versionData( versionIndex );
87 
88  const int tableColumn = index.column();
89  switch( tableColumn )
90  {
91  case IdColumnId:
92  {
93  result = version.id();
94  break;
95  }
96  case ChangeDescriptionColumnId:
97  result = version.changeComment();
98  break;
99  default:
100  ;
101  }
102  }
103  else if( role == Qt::DecorationRole )
104  {
105  const int tableColumn = index.column();
106  if( tableColumn == CurrentColumnId )
107  {
108  const int versionIndex = index.row();
109  if( mVersionControl->versionIndex() == versionIndex )
110  result = KIcon( QLatin1String("arrow-right") );
111  }
112  }
113 
114  return result;
115 }
116 
117 QVariant VersionTableModel::headerData( int section, Qt::Orientation orientation, int role ) const
118 {
119  QVariant result;
120 
121  if( role == Qt::DisplayRole )
122  {
123  const QString titel =
124  section == IdColumnId ? i18nc("@title:column Id of the version", "Id") :
125  section == ChangeDescriptionColumnId ? i18nc("@title:column description of the change", "Changes") :
126  QString();
127  result = titel;
128  }
129  else if( role == Qt::ToolTipRole )
130  {
131  const QString titel =
132  section == IdColumnId ? i18nc("@info:tooltip","Id of the version") :
133  section == ChangeDescriptionColumnId ? i18nc("@info:tooltip","Description of what changed") :
134  QString();
135  result = titel;
136  }
137  else
138  result = QAbstractTableModel::headerData( section, orientation, role );
139 
140  return result;
141 }
142 
143 void VersionTableModel::onRevertedToVersionIndex( int versionIndex )
144 {
145  if( mVersionIndex == versionIndex )
146  return;
147 
148  const int oldVersionIndex = mVersionIndex;
149  mVersionIndex = versionIndex;
150 
151  emit dataChanged( index(versionIndex,CurrentColumnId), index(versionIndex,CurrentColumnId) );
152  emit dataChanged( index(oldVersionIndex,CurrentColumnId), index(oldVersionIndex,CurrentColumnId) );
153 }
154 
155 void VersionTableModel::onHeadVersionChanged( int newHeadVersionIndex )
156 {
157  mVersionIndex = newHeadVersionIndex;
158  // TODO: try to understand how this whould be done with {begin,end}{Insert,Remove}Columns
159  reset();
160 }
161 
162 void VersionTableModel::onHeadVersionDataChanged( const DocumentVersionData &versionData )
163 {
164  Q_UNUSED( versionData )
165  const int headVersionIndex = mVersionControl->versionCount() - 1;
166  emit dataChanged( index(headVersionIndex,CurrentColumnId), index(headVersionIndex,ChangeDescriptionColumnId) );
167 }
168 
169 VersionTableModel::~VersionTableModel() {}
170 
171 }
abstractmodel.h
Kasten2::If::Versionable::versionData
virtual DocumentVersionData versionData(int versionIndex) const =0
Kasten2::If::Versionable
Definition: libs/kasten/core/document/versionable.h:68
Kasten2::VersionTableModel::columnCount
virtual int columnCount(const QModelIndex &parent) const
Definition: versiontablemodel.cpp:75
QObject
Kasten2::DocumentVersionData::id
DocumentVersionId id() const
Definition: documentversiondata.cpp:33
Kasten2::If::Versionable::versionIndex
virtual int versionIndex() const =0
Kasten2::If::Versionable::versionCount
virtual int versionCount() const =0
Kasten2::DocumentVersionData::changeComment
QString changeComment() const
Definition: documentversiondata.cpp:35
Kasten2::VersionTableModel::ChangeDescriptionColumnId
Definition: versiontablemodel.h:50
Kasten2::VersionTableModel
Definition: versiontablemodel.h:41
Kasten2::VersionTableModel::rowCount
virtual int rowCount(const QModelIndex &parent) const
Definition: versiontablemodel.cpp:70
Kasten2::VersionTableModel::setModel
void setModel(AbstractModel *model, If::Versionable *versionControl)
Definition: versiontablemodel.cpp:51
Kasten2::VersionTableModel::CurrentColumnId
Definition: versiontablemodel.h:48
Kasten2::VersionTableModel::data
virtual QVariant data(const QModelIndex &index, int role) const
Definition: versiontablemodel.cpp:80
Kasten2::AbstractModel
Definition: abstractmodel.h:40
Kasten2::DocumentVersionData
Definition: documentversiondata.h:36
Kasten2::VersionTableModel::IdColumnId
Definition: versiontablemodel.h:49
versiontablemodel.h
Kasten2::VersionTableModel::NoOfColumnIds
Definition: versiontablemodel.h:51
Kasten2::VersionTableModel::VersionTableModel
VersionTableModel(AbstractModel *model, If::Versionable *versionControl, QObject *parent=0)
Definition: versiontablemodel.cpp:36
QAbstractTableModel
Kasten2::VersionTableModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
Definition: versiontablemodel.cpp:117
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:09 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