• 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
  • kasten
  • controllers
  • view
  • bookmarks
bookmarklistmodel.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 "bookmarklistmodel.h"
24 
25 // lib
26 #include "bookmarkstool.h"
27 // Okteta core
28 #include <bookmark.h>
29 // KDE
30 #include <KLocale>
31 #include <KIcon>
32 
33 
34 namespace Kasten2
35 {
36 
37 BookmarkListModel::BookmarkListModel( BookmarksTool* tool, QObject* parent )
38  : QAbstractTableModel( parent ),
39  mTool( tool )
40 {
41  mPrintFunction = Okteta::OffsetFormat::printFunction( (Okteta::OffsetFormat::Format)tool->offsetCoding() );
42 
43  connect( mTool, SIGNAL(hasBookmarksChanged(bool)),
44  SLOT(onHasBookmarksChanged(bool)) );
45  connect( mTool, SIGNAL(bookmarksAdded(QList<Okteta::Bookmark>)),
46  SLOT(onBookmarksChanged()) );
47  connect( mTool, SIGNAL(bookmarksRemoved(QList<Okteta::Bookmark>)),
48  SLOT(onBookmarksChanged()) );
49  connect( mTool, SIGNAL(bookmarksModified(QList<int>)),
50  SLOT(onBookmarksChanged(QList<int>)) );
51  connect( mTool, SIGNAL(offsetCodingChanged(int)),
52  SLOT(onOffsetCodingChanged(int)) );
53 }
54 
55 int BookmarkListModel::rowCount( const QModelIndex& parent ) const
56 {
57  return (! parent.isValid()) ? mTool->bookmarksCount() : 0;
58 }
59 
60 int BookmarkListModel::columnCount( const QModelIndex& parent ) const
61 {
62  return (! parent.isValid()) ? NoOfColumnIds : 0;
63 }
64 
65 QVariant BookmarkListModel::data( const QModelIndex& index, int role ) const
66 {
67  QVariant result;
68 
69  switch( role )
70  {
71  case Qt::DisplayRole:
72  {
73  const int bookmarkIndex = index.row();
74 
75  const Okteta::Bookmark& bookmark = mTool->bookmarkAt( bookmarkIndex );
76 
77  const int tableColumn = index.column();
78  switch( tableColumn )
79  {
80  case OffsetColumnId:
81  {
82  mPrintFunction( mCodedOffset, bookmark.offset() );
83 
84  result = QString::fromLatin1( mCodedOffset );
85  break;
86  }
87  case TitleColumnId:
88  result = bookmark.name();
89  break;
90  default:
91  ;
92  }
93  }
94  case Qt::EditRole:
95  {
96  const int bookmarkIndex = index.row();
97 
98  const int column = index.column();
99  if( column == TitleColumnId )
100  {
101  const Okteta::Bookmark& bookmark = mTool->bookmarkAt( bookmarkIndex );
102  result = bookmark.name();
103  }
104  break;
105  }
106  default:
107  break;
108  }
109 
110  return result;
111 }
112 
113 Qt::ItemFlags BookmarkListModel::flags( const QModelIndex& index ) const
114 {
115  Qt::ItemFlags result = QAbstractTableModel::flags( index );
116  const int column = index.column();
117  if( column == TitleColumnId )
118  result |= Qt::ItemIsEditable;
119 
120  return result;
121 }
122 
123 QVariant BookmarkListModel::headerData( int section, Qt::Orientation orientation, int role ) const
124 {
125  QVariant result;
126 
127  if( role == Qt::DisplayRole )
128  {
129  const QString titel =
130  section == OffsetColumnId ? i18nc("@title:column offset of the bookmark", "Offset") :
131  section == TitleColumnId ? i18nc("@title:column title of the bookmark", "Title") :
132  QString();
133  result = titel;
134  }
135  else
136  result = QAbstractTableModel::headerData( section, orientation, role );
137 
138  return result;
139 }
140 
141 bool BookmarkListModel::setData( const QModelIndex& index, const QVariant& value, int role )
142 {
143  bool result;
144 
145  if( role == Qt::EditRole )
146  {
147  const int bookmarkIndex = index.row();
148 
149  const int column = index.column();
150  if( column == TitleColumnId )
151  {
152  mTool->setBookmarkName( bookmarkIndex, value.toString() );
153 // emit dataChanged( index, index );
154  result = true;
155  }
156  else
157  result = false;
158  }
159  else
160  result = QAbstractItemModel::setData( index, value, role );
161 
162  return result;
163 }
164 
165 const Okteta::Bookmark& BookmarkListModel::bookmark( const QModelIndex& index ) const
166 {
167  const int bookmarkIndex = index.row();
168  return mTool->bookmarkAt( bookmarkIndex );
169 }
170 
171 QModelIndex BookmarkListModel::index( const Okteta::Bookmark& bookmark, int column ) const
172 {
173  QModelIndex result;
174 
175  const int indexOfBookmark = mTool->indexOf( bookmark );
176  if( indexOfBookmark != -1 )
177  result = createIndex( indexOfBookmark, column );
178 
179  return result;
180 }
181 
182 
183 void BookmarkListModel::onHasBookmarksChanged( bool hasBookmarks )
184 {
185 Q_UNUSED( hasBookmarks )
186 
187  reset();
188 }
189 
190 void BookmarkListModel::onBookmarksChanged()
191 {
192  reset();
193 }
194 
195 void BookmarkListModel::onBookmarksChanged( const QList<int>& bookmarkIndizes )
196 {
197  foreach( int row, bookmarkIndizes )
198  emit dataChanged( index(row,OffsetColumnId), index(row,TitleColumnId) );
199 }
200 
201 void BookmarkListModel::onOffsetCodingChanged( int offsetCoding )
202 {
203  mPrintFunction = Okteta::OffsetFormat::printFunction( (Okteta::OffsetFormat::Format)offsetCoding );
204  reset();
205 }
206 
207 
208 #if 0
209 void BookmarkListModel::onRevertedToVersionIndex( int versionIndex )
210 {
211  if( mVersionIndex == versionIndex )
212  return;
213 
214  const int oldVersionIndex = mVersionIndex;
215  mVersionIndex = versionIndex;
216 
217  emit dataChanged( index(versionIndex,CurrentColumnId), index(versionIndex,CurrentColumnId) );
218  emit dataChanged( index(oldVersionIndex,CurrentColumnId), index(oldVersionIndex,CurrentColumnId) );
219 }
220 
221 void BookmarkListModel::onHeadVersionDataChanged( const DocumentVersionData &versionData )
222 {
223  Q_UNUSED( versionData )
224  const int headVersionIndex = mVersionControl->versionCount() - 1;
225  emit dataChanged( index(headVersionIndex,CurrentColumnId), index(headVersionIndex,ChangeDescriptionColumnId) );
226 }
227 #endif
228 BookmarkListModel::~BookmarkListModel() {}
229 
230 }
bookmarklistmodel.h
bookmark.h
Kasten2::BookmarkListModel
Definition: bookmarklistmodel.h:43
Okteta::Bookmark::offset
Address offset() const
Definition: bookmark.h:66
Kasten2::BookmarkListModel::setData
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
Definition: bookmarklistmodel.cpp:141
Kasten2::BookmarkListModel::data
virtual QVariant data(const QModelIndex &index, int role) const
Definition: bookmarklistmodel.cpp:65
Okteta::Bookmark
Definition: bookmark.h:38
Okteta::Bookmark::name
QString name() const
Definition: bookmark.h:67
Kasten2::BookmarksTool::indexOf
int indexOf(const Okteta::Bookmark &bookmark) const
Definition: bookmarkstool.cpp:58
Okteta::OffsetFormat::Format
Format
Definition: offsetformat.h:43
Kasten2::BookmarkListModel::index
QModelIndex index(const Okteta::Bookmark &bookmark, int column=BookmarkListModel::TitleColumnId) const
Definition: bookmarklistmodel.cpp:171
Kasten2::BookmarksTool::bookmarkAt
const Okteta::Bookmark & bookmarkAt(unsigned int index) const
Definition: bookmarkstool.cpp:57
QObject
Kasten2::BookmarkListModel::flags
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Definition: bookmarklistmodel.cpp:113
Okteta::OffsetFormat::printFunction
static print printFunction(int i)
Definition: offsetformat.h:73
Kasten2::BookmarkListModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
Definition: bookmarklistmodel.cpp:123
Kasten2::BookmarksTool
Definition: bookmarkstool.h:47
Kasten2::BookmarkListModel::BookmarkListModel
BookmarkListModel(BookmarksTool *tool, QObject *parent=0)
Definition: bookmarklistmodel.cpp:37
Kasten2::BookmarkListModel::NoOfColumnIds
Definition: bookmarklistmodel.h:52
Kasten2::BookmarkListModel::~BookmarkListModel
virtual ~BookmarkListModel()
Definition: bookmarklistmodel.cpp:228
Kasten2::BookmarkListModel::bookmark
const Okteta::Bookmark & bookmark(const QModelIndex &index) const
Definition: bookmarklistmodel.cpp:165
Kasten2::BookmarkListModel::rowCount
virtual int rowCount(const QModelIndex &parent) const
Definition: bookmarklistmodel.cpp:55
Kasten2::BookmarksTool::offsetCoding
int offsetCoding() const
Definition: bookmarkstool.cpp:76
Kasten2::BookmarksTool::bookmarksCount
unsigned int bookmarksCount() const
Definition: bookmarkstool.cpp:75
Kasten2::BookmarkListModel::TitleColumnId
Definition: bookmarklistmodel.h:51
bookmarkstool.h
Kasten2::BookmarkListModel::OffsetColumnId
Definition: bookmarklistmodel.h:50
Kasten2::BookmarksTool::setBookmarkName
void setBookmarkName(unsigned int bookmarkIndex, const QString &name)
Definition: bookmarkstool.cpp:174
QAbstractTableModel
QList
Definition: bookmarkable.h:29
Kasten2::BookmarkListModel::columnCount
virtual int columnCount(const QModelIndex &parent) const
Definition: bookmarklistmodel.cpp:60
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:07 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