• 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
  • poddecoder
podtablemodel.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Kasten module, made within the KDE community.
3 
4  Copyright 2008-2009 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 "podtablemodel.h"
24 
25 // lib
26 #include "poddecodertool.h"
27 // KDE
28 #include <KLocale>
29 #include <KApplication>
30 #include <KColorScheme>
31 
32 
33 namespace Kasten2
34 {
35 
36 PODTableModel::PODTableModel( PODDecoderTool* tool, QObject *parent )
37  : QAbstractTableModel( parent ),
38  mTool( tool ),
39  mEmptyNote( QLatin1Char('-') )
40 {
41  connect( mTool, SIGNAL(dataChanged()), SLOT(onDataChanged()) );
42 }
43 
44 void PODTableModel::onDataChanged()
45 {
46  emit dataChanged( index(0,ValueId), index(mTool->podCount()-1,ValueId) );
47 }
48 
49 int PODTableModel::rowCount( const QModelIndex& parent ) const
50 {
51  return (! parent.isValid()) ? mTool->podCount() : 0;
52 }
53 
54 int PODTableModel::columnCount( const QModelIndex& parent ) const
55 {
56  return (! parent.isValid()) ? NoOfColumnIds : 0;
57 }
58 
59 QVariant PODTableModel::data( const QModelIndex& index, int role ) const
60 {
61  QVariant result;
62  switch( role )
63  {
64  case Qt::DisplayRole:
65  {
66  const int podId = index.row();
67  const int column = index.column();
68  switch( column )
69  {
70  case NameId:
71  {
72  result = mTool->nameOfPOD( podId );
73  break;
74  }
75  case ValueId:
76  {
77  QVariant value = mTool->value( podId );
78  if( value.isNull() )
79  value = mEmptyNote;
80  result = value;
81  break;
82  }
83  default:
84  ;
85  }
86  break;
87  }
88  case Qt::EditRole:
89  {
90  const int column = index.column();
91  if( column == ValueId )
92  {
93  const int podId = index.row();
94  result = mTool->value( podId );
95  }
96  break;
97  }
98  case Qt::TextAlignmentRole:
99  {
100  const int column = index.column();
101  result = ( column==NameId ) ? Qt::AlignRight: Qt::AlignLeft;
102  break;
103  }
104  case Qt::ForegroundRole:
105  {
106  const int column = index.column();
107  if( column == ValueId )
108  {
109  const int podId = index.row();
110  const QVariant value = mTool->value( podId );
111 
112  if( value.isNull() )
113  {
114  const QPalette &palette = KApplication::kApplication()->palette();
115  const KColorScheme colorScheme( palette.currentColorGroup(), KColorScheme::View );
116  result = colorScheme.foreground( KColorScheme::InactiveText );
117  }
118  }
119  }
120  default:
121  break;
122  }
123 
124  return result;
125 }
126 
127 Qt::ItemFlags PODTableModel::flags( const QModelIndex& index ) const
128 {
129  Qt::ItemFlags result = QAbstractTableModel::flags( index );
130  const int column = index.column();
131  if( column == ValueId )
132  {
133  const int podId = index.row();
134  const QVariant value = mTool->value( podId );
135 
136  // TODO: this check does not match types with dynamic byte length, e.g. utf-8!
137  if( ! value.isNull() )
138  result |= Qt::ItemIsEditable;
139  }
140 
141  return result;
142 }
143 
144 QModelIndex PODTableModel::buddy( const QModelIndex& index ) const
145 {
146  QModelIndex result;
147 
148  const int column = index.column();
149  if( column == NameId )
150  {
151  const int row = index.row();
152  result = createIndex( row, ValueId );
153  }
154  else
155  result = index;
156 
157  return result;
158 }
159 
160 
161 QVariant PODTableModel::headerData( int section, Qt::Orientation orientation, int role ) const
162 {
163  QVariant result;
164 
165  if( role == Qt::DisplayRole )
166  {
167  const QString titel =
168  section == NameId ? i18nc("@title:column name of the datatype", "Type") :
169  section == ValueId ? i18nc("@title:column value of the bytes for the datatype", "Value") :
170  QString();
171  result = titel;
172  }
173  else if( role == Qt::ToolTipRole )
174  {
175  const QString titel =
176  section == NameId ?
177  i18nc("@info:tooltip for column Type", "The type of data") :
178  section == ValueId ?
179  i18nc("@info:tooltip for column Value", "The value of the bytes for the datatype") :
180  QString();
181  result = titel;
182  }
183  else
184  result = QAbstractTableModel::headerData( section, orientation, role );
185 
186  return result;
187 }
188 
189 bool PODTableModel::setData( const QModelIndex& index, const QVariant& data, int role )
190 {
191  bool result;
192 
193  if( index.isValid() && role == Qt::EditRole )
194  {
195  const int podId = index.row();
196 
197  mTool->setData( data, podId );
198 
199  result = true;
200  }
201  else
202  result = false;
203 
204  return result;
205 }
206 
207 PODTableModel::~PODTableModel() {}
208 
209 }
Kasten2::PODTableModel::NoOfColumnIds
Definition: podtablemodel.h:46
Kasten2::PODTableModel::NameId
Definition: podtablemodel.h:43
Kasten2::PODDecoderTool::nameOfPOD
QString nameOfPOD(int podId) const
Definition: poddecodertool.cpp:214
Kasten2::PODTableModel::buddy
virtual QModelIndex buddy(const QModelIndex &index) const
Definition: podtablemodel.cpp:144
Kasten2::PODTableModel::columnCount
virtual int columnCount(const QModelIndex &parent) const
Definition: podtablemodel.cpp:54
Kasten2::PODDecoderTool
Definition: poddecodertool.h:51
Kasten2::PODTableModel::setData
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
Definition: podtablemodel.cpp:189
QObject
Kasten2::PODTableModel::ValueId
Definition: podtablemodel.h:44
poddecodertool.h
Kasten2::PODTableModel::flags
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Definition: podtablemodel.cpp:127
Kasten2::PODDecoderTool::value
QVariant value(int podId) const
Definition: poddecodertool.cpp:220
Kasten2::PODTableModel::data
virtual QVariant data(const QModelIndex &index, int role) const
Definition: podtablemodel.cpp:59
Kasten2::PODDecoderTool::podCount
int podCount() const
Definition: poddecodertool.cpp:211
Kasten2::PODTableModel::PODTableModel
PODTableModel(PODDecoderTool *tool, QObject *parent=0)
Definition: podtablemodel.cpp:36
Kasten2::PODDecoderTool::setData
void setData(const QVariant &data, int podId)
Definition: poddecodertool.cpp:227
podtablemodel.h
Kasten2::PODTableModel::rowCount
virtual int rowCount(const QModelIndex &parent) const
Definition: podtablemodel.cpp:49
Kasten2::PODTableModel::~PODTableModel
virtual ~PODTableModel()
Definition: podtablemodel.cpp:207
QAbstractTableModel
Kasten2::PODTableModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
Definition: podtablemodel.cpp:161
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