ParaView
pqProxySILModel.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: pqProxySILModel.h
5 
6  Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
7  All rights reserved.
8 
9  ParaView is a free software; you can redistribute it and/or modify it
10  under the terms of the ParaView license version 1.2.
11 
12  See License_v1.2.txt for the full ParaView license.
13  A copy of this license can be obtained by contacting
14  Kitware Inc.
15  28 Corporate Drive
16  Clifton Park, NY 12065
17  USA
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 ========================================================================*/
32 #ifndef pqProxySILModel_h
33 #define pqProxySILModel_h
34 
35 #include "pqComponentsModule.h"
36 #include "pqTimer.h"
37 #include <QAbstractProxyModel>
38 
39 #include <QPixmap>
40 
45 class PQCOMPONENTS_EXPORT pqProxySILModel : public QAbstractProxyModel
46 {
47  Q_OBJECT
48  typedef QAbstractProxyModel Superclass;
49  Q_PROPERTY(QList<QVariant> values READ values WRITE setValues)
50 
51 public:
52  pqProxySILModel(const QString& hierarchyName, QObject* parent=0);
53  ~pqProxySILModel();
54 
56 
57  virtual int rowCount(const QModelIndex &theParent=QModelIndex()) const
63  {
64  return this->sourceModel()->rowCount(this->mapToSource(theParent));
65  }
66 
72  virtual int columnCount(const QModelIndex &theParent=QModelIndex()) const
73  {
74  return this->sourceModel()->columnCount(this->mapToSource(theParent));
75  }
76 
82  virtual bool hasChildren(const QModelIndex &theParent=QModelIndex()) const
83  {
84  return this->sourceModel()->hasChildren(this->mapToSource(theParent));
85  }
86 
94  virtual QModelIndex index(int row, int column,
95  const QModelIndex &theParent=QModelIndex()) const
96  {
97  QModelIndex sourceIndex =
98  this->sourceModel()->index(row, column, this->mapToSource(theParent));
99  return this->mapFromSource(sourceIndex);
100  }
101 
107  virtual QModelIndex parent(const QModelIndex &theIndex) const
108  {
109  QModelIndex sourceIndex = this->sourceModel()->parent(this->mapToSource(theIndex));
110  return this->mapFromSource(sourceIndex);
111  }
112 
116  bool setData(const QModelIndex &theIndex, const QVariant& value,
117  int role = Qt::EditRole)
118  {
119  return this->sourceModel()->setData(this->mapToSource(theIndex), value, role);
120  }
122 
124  virtual QModelIndex mapFromSource(const QModelIndex& sourceIndex) const;
125  virtual QModelIndex mapToSource(const QModelIndex& proxyIndex) const;
126  virtual void setSourceModel(QAbstractItemModel *sourceModel);
127 
133  virtual QVariant headerData (int, Qt::Orientation, int role = Qt::DisplayRole ) const;
134 
136  virtual QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const;
137 
140  virtual Qt::ItemFlags flags(const QModelIndex &index) const;
141 
143  QList<QVariant> values() const;
144 
146  void setNoCheckBoxes(bool val);
147 
149  void setHeaderTitle(QString &title);
150 
151 public slots:
153  void setValues(const QList<QVariant>&);
154 
157  void toggleRootCheckState();
158 
159 signals:
160  void valuesChanged();
161 
162 protected slots:
163  void sourceDataChanged(const QModelIndex& idx1, const QModelIndex& idx2)
164  {
165  QModelIndex pidx1 = this->mapFromSource(idx1);
166  QModelIndex pidx2 = this->mapFromSource(idx2);
167  if (!pidx1.isValid() || !pidx2.isValid())
168  {
169  // index is root, that mean header data may have changed as well.
170  emit this->headerDataChanged(Qt::Horizontal, 0, 0);
171  }
172  emit this->dataChanged(pidx1, pidx2);
173  }
174 
175  void onCheckStatusChanged();
176 
177 private:
178  Q_DISABLE_COPY(pqProxySILModel)
179 
180  pqTimer DelayedValuesChangedSignalTimer;
181  QPixmap CheckboxPixmaps[3];
182  QString HierarchyName;
183  bool noCheckBoxes;
184  QString HeaderTitle;
185 };
186 
187 #endif
188 
189 
bool setData(const QModelIndex &theIndex, const QVariant &value, int role=Qt::EditRole)
Sets the role data for the item at index to value.
virtual bool hasChildren(const QModelIndex &theParent=QModelIndex()) const
Gets whether or not the given index has child items.
pqProxySILModel is a proxy model for pqSILModel.
virtual QModelIndex parent(const QModelIndex &theIndex) const
Gets the parent for a given index.
void sourceDataChanged(const QModelIndex &idx1, const QModelIndex &idx2)
virtual QModelIndex index(int row, int column, const QModelIndex &theParent=QModelIndex()) const
Gets a model index for a given location.
virtual int columnCount(const QModelIndex &theParent=QModelIndex()) const
Gets the number of columns for a given index.