• 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
  • viewprofiles
viewprofiletablemodel.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 2010,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 "viewprofiletablemodel.h"
24 
25 // Okteta Gui Kasten
26 #include <bytearrayviewprofilemanager.h>
27 // KDE
28 #include <KApplication>
29 #include <KColorScheme>
30 #include <KLocale>
31 #include <KIcon>
32 // Qt
33 #include <QtCore/QVector>
34 
35 
36 namespace Kasten2
37 {
38 
39 ViewProfileTableModel::ViewProfileTableModel( const ByteArrayViewProfileManager* viewProfileManager,
40  QObject* parent )
41  : QAbstractTableModel( parent )
42  , mViewProfileManager( viewProfileManager )
43 {
44  connect( viewProfileManager, SIGNAL(viewProfilesChanged(QList<Kasten2::ByteArrayViewProfile>)),
45  SLOT(onViewProfilesChanged()) );
46  connect( viewProfileManager, SIGNAL(viewProfilesRemoved(QList<Kasten2::ByteArrayViewProfile::Id>)),
47  SLOT(onViewProfilesChanged()) );
48  connect( viewProfileManager, SIGNAL(defaultViewProfileChanged(Kasten2::ByteArrayViewProfile::Id)),
49  SLOT(onDefaultIndexChanged()) );
50  connect( viewProfileManager, SIGNAL(viewProfilesLocked(QList<Kasten2::ByteArrayViewProfile::Id>)),
51  SLOT(onViewProfilesChanged()) );
52  connect( viewProfileManager, SIGNAL(viewProfilesUnlocked(QList<Kasten2::ByteArrayViewProfile::Id>)),
53  SLOT(onViewProfileLocksChanged(QList<Kasten2::ByteArrayViewProfile::Id>)) );
54 }
55 
56 int ViewProfileTableModel::rowCount( const QModelIndex &parent ) const
57 {
58  return (! parent.isValid() ) ? mViewProfileManager->viewProfilesCount() : 0;
59 }
60 
61 int ViewProfileTableModel::columnCount( const QModelIndex &parent ) const
62 {
63  return (! parent.isValid()) ? NoOfColumnIds : 0;
64 }
65 
66 QVariant ViewProfileTableModel::data( const QModelIndex &index, int role ) const
67 {
68  QVariant result;
69  switch( role )
70  {
71  case Qt::DisplayRole:
72  {
73  const int viewProfileIndex = index.row();
74 
75  const int tableColumn = index.column();
76  switch( tableColumn )
77  {
78  case NameColumnId:
79  {
80  result = mViewProfileManager->viewProfiles().at(viewProfileIndex).viewProfileTitle();
81  break;
82  }
83  default:
84  ;
85  }
86  break;
87  }
88  case Qt::DecorationRole:
89  {
90  const int tableColumn = index.column();
91  if( tableColumn == CurrentColumnId )
92  {
93  const int viewProfileIndex = index.row();
94  const ByteArrayViewProfile::Id viewProfileId =
95  mViewProfileManager->viewProfiles().at(viewProfileIndex).id();
96 
97  if( mViewProfileManager->defaultViewProfileId() == viewProfileId )
98  result = KIcon( QLatin1String("arrow-right") );
99  }
100  break;
101  }
102  case Qt::ForegroundRole:
103  {
104  const int viewProfileIndex = index.row();
105  const ByteArrayViewProfile::Id viewProfileId =
106  mViewProfileManager->viewProfiles().at(viewProfileIndex).id();
107 
108  if( mViewProfileManager->isViewProfileLocked(viewProfileId) )
109  {
110  const QPalette& palette = KApplication::kApplication()->palette();
111  const KColorScheme colorScheme( palette.currentColorGroup(), KColorScheme::View );
112  result = colorScheme.foreground( KColorScheme::InactiveText );
113  }
114  break;
115  }
116  }
117 
118  return result;
119 }
120 
121 ByteArrayViewProfile::Id
122 ViewProfileTableModel::viewProfileId( const QModelIndex& index ) const
123 {
124  const int viewProfileIndex = index.row();
125  const bool isValidIndex =
126  (0 <= viewProfileIndex) && (viewProfileIndex < mViewProfileManager->viewProfilesCount());
127 
128  return isValidIndex ? mViewProfileManager->viewProfiles().at(viewProfileIndex).id() : ByteArrayViewProfile::Id();
129 }
130 
131 int
132 ViewProfileTableModel::row( const ByteArrayViewProfile::Id& viewProfileId ) const
133 {
134  int result = -1;
135 
136  const QList<ByteArrayViewProfile> viewProfiles = mViewProfileManager->viewProfiles();
137  const int viewProfilesCount = viewProfiles.count();
138  for( int i = 0; i< viewProfilesCount; ++i )
139  {
140  if( viewProfileId == viewProfiles.at( i ).id() )
141  {
142  result = i;
143  break;
144  }
145  }
146 
147  return result;
148 }
149 
150 
151 void ViewProfileTableModel::onDefaultIndexChanged()
152 {
153  // simply reset the whole column, does not happen often and not worth to cache the old default
154  emit dataChanged( index(CurrentColumnId, 0),
155  index(CurrentColumnId, mViewProfileManager->viewProfiles().count()-1) );
156 }
157 
158 void ViewProfileTableModel::onViewProfilesChanged()
159 {
160  reset();
161 }
162 
163 void ViewProfileTableModel::onViewProfileLocksChanged(const QList<ByteArrayViewProfile::Id>& viewProfileIds )
164 {
165  const QList<ByteArrayViewProfile> viewProfiles = mViewProfileManager->viewProfiles();
166  const int viewProfilesCount = viewProfiles.count();
167  for( int i = 0; i< viewProfilesCount; ++i )
168  {
169  const ByteArrayViewProfile::Id viewProfileId = viewProfiles.at( i ).id();
170 
171  if( viewProfileIds.contains(viewProfileId) )
172  emit dataChanged( index(CurrentColumnId, i),
173  index(NameColumnId, i) );
174  }
175 }
176 
177 ViewProfileTableModel::~ViewProfileTableModel() {}
178 
179 }
Kasten2::ByteArrayViewProfileManager::viewProfilesCount
int viewProfilesCount() const
Definition: bytearrayviewprofilemanager.cpp:175
Kasten2::ByteArrayViewProfile::Id
QString Id
Definition: bytearrayviewprofile.h:42
viewprofiletablemodel.h
Kasten2::ViewProfileTableModel::mViewProfileManager
const ByteArrayViewProfileManager * mViewProfileManager
Definition: viewprofiletablemodel.h:71
Kasten2::ViewProfileTableModel::row
int row(const ByteArrayViewProfile::Id &viewProfileId) const
Definition: viewprofiletablemodel.cpp:132
Kasten2::ViewProfileTableModel::NameColumnId
Definition: viewprofiletablemodel.h:47
Kasten2::ViewProfileTableModel::NoOfColumnIds
Definition: viewprofiletablemodel.h:48
Kasten2::ViewProfileTableModel::onViewProfilesChanged
void onViewProfilesChanged()
Definition: viewprofiletablemodel.cpp:158
Kasten2::ByteArrayViewProfileManager::isViewProfileLocked
bool isViewProfileLocked(const ByteArrayViewProfile::Id &id) const
Definition: bytearrayviewprofilemanager.cpp:217
bytearrayviewprofilemanager.h
Kasten2::ViewProfileTableModel::columnCount
virtual int columnCount(const QModelIndex &parent) const
Definition: viewprofiletablemodel.cpp:61
QObject
Kasten2::ByteArrayViewProfileManager::viewProfiles
QList< ByteArrayViewProfile > viewProfiles() const
Definition: bytearrayviewprofilemanager.cpp:182
Kasten2::ViewProfileTableModel::CurrentColumnId
Definition: viewprofiletablemodel.h:46
Kasten2::ViewProfileTableModel::~ViewProfileTableModel
virtual ~ViewProfileTableModel()
Definition: viewprofiletablemodel.cpp:177
Kasten2::ViewProfileTableModel::viewProfileId
ByteArrayViewProfile::Id viewProfileId(const QModelIndex &index) const
Definition: viewprofiletablemodel.cpp:122
Kasten2::ViewProfileTableModel::onDefaultIndexChanged
void onDefaultIndexChanged()
Definition: viewprofiletablemodel.cpp:151
Kasten2::ByteArrayViewProfileManager::defaultViewProfileId
ByteArrayViewProfile::Id defaultViewProfileId() const
Definition: bytearrayviewprofilemanager.cpp:205
Kasten2::ViewProfileTableModel::ViewProfileTableModel
ViewProfileTableModel(const ByteArrayViewProfileManager *viewProfileManager, QObject *parent=0)
Definition: viewprofiletablemodel.cpp:39
Kasten2::viewProfileIds
static QList< ByteArrayViewProfile::Id > viewProfileIds(const QList< ByteArrayViewProfile > &viewProfiles)
Definition: bytearrayviewprofilemanager.cpp:58
Kasten2::ByteArrayViewProfileManager
Definition: bytearrayviewprofilemanager.h:65
Kasten2::ViewProfileTableModel::onViewProfileLocksChanged
void onViewProfileLocksChanged(const QList< Kasten2::ByteArrayViewProfile::Id > &viewProfileIds)
Definition: viewprofiletablemodel.cpp:163
Kasten2::ViewProfileTableModel::data
virtual QVariant data(const QModelIndex &index, int role) const
Definition: viewprofiletablemodel.cpp:66
Kasten2::ViewProfileTableModel::rowCount
virtual int rowCount(const QModelIndex &parent) const
Definition: viewprofiletablemodel.cpp:56
QAbstractTableModel
QList< Kasten2::ByteArrayViewProfile >
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