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 
47 class PQCOMPONENTS_EXPORT pqProxySILModel : public QAbstractProxyModel
48 {
49  Q_OBJECT
50  typedef QAbstractProxyModel Superclass;
51  Q_PROPERTY(QList<QVariant> values READ values WRITE setValues)
52 
53 public:
54  pqProxySILModel(const QString& hierarchyName, QObject* parent = 0);
55  ~pqProxySILModel();
56 
68  virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const
69  {
70  return this->sourceModel()->rowCount(this->mapToSource(theParent));
71  }
72 
80  virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const
81  {
82  return this->sourceModel()->columnCount(this->mapToSource(theParent));
83  }
84 
92  virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const
93  {
94  return this->sourceModel()->hasChildren(this->mapToSource(theParent));
95  }
96 
106  virtual QModelIndex index(int row, int column, const QModelIndex& theParent = QModelIndex()) const
107  {
108  QModelIndex sourceIndex = this->sourceModel()->index(row, column, this->mapToSource(theParent));
109  return this->mapFromSource(sourceIndex);
110  }
111 
119  virtual QModelIndex parent(const QModelIndex& theIndex) const
120  {
121  QModelIndex sourceIndex = this->sourceModel()->parent(this->mapToSource(theIndex));
122  return this->mapFromSource(sourceIndex);
123  }
124 
130  bool setData(const QModelIndex& theIndex, const QVariant& value, int role = Qt::EditRole)
131  {
132  return this->sourceModel()->setData(this->mapToSource(theIndex), value, role);
133  }
135 
139  virtual QModelIndex mapFromSource(const QModelIndex& sourceIndex) const;
140  virtual QModelIndex mapToSource(const QModelIndex& proxyIndex) const;
141  virtual void setSourceModel(QAbstractItemModel* sourceModel);
142 
150  virtual QVariant headerData(int, Qt::Orientation, int role = Qt::DisplayRole) const;
151 
155  virtual QVariant data(const QModelIndex& proxyIndex, int role = Qt::DisplayRole) const;
156 
161  virtual Qt::ItemFlags flags(const QModelIndex& index) const;
162 
166  QList<QVariant> values() const;
167 
171  void setNoCheckBoxes(bool val);
172 
176  void setHeaderTitle(QString& title);
177 
178 public slots:
182  void setValues(const QList<QVariant>&);
183 
188  void toggleRootCheckState();
189 
190 signals:
191  void valuesChanged();
192 
193 protected slots:
194  void sourceDataChanged(const QModelIndex& idx1, const QModelIndex& idx2)
195  {
196  QModelIndex pidx1 = this->mapFromSource(idx1);
197  QModelIndex pidx2 = this->mapFromSource(idx2);
198  if (!pidx1.isValid() || !pidx2.isValid())
199  {
200  // index is root, that mean header data may have changed as well.
201  emit this->headerDataChanged(Qt::Horizontal, 0, 0);
202  }
203  emit this->dataChanged(pidx1, pidx2);
204  }
205 
206  void onCheckStatusChanged();
207 
208 private:
209  Q_DISABLE_COPY(pqProxySILModel)
210 
211  pqTimer DelayedValuesChangedSignalTimer;
212  QPixmap CheckboxPixmaps[3];
213  QString HierarchyName;
214  bool noCheckBoxes;
215  QString HeaderTitle;
216 };
217 
218 #endif
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.
virtual int rowCount(const QModelIndex &theParent=QModelIndex()) const
Gets the number of rows for a given index.
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.