CTK 0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkCheckableModelHelper.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Library: CTK
4
5 Copyright (c) Kitware Inc.
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0.txt
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18
19=========================================================================*/
20/*=========================================================================
21
22 Program: ParaView
23 Module: pqCheckableModelHelper.h
24
25 Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
26 All rights reserved.
27
28 ParaView is a free software; you can redistribute it and/or modify it
29 under the terms of the ParaView license version 1.2.
30
31 See http://www.paraview.org/paraview/project/license.html for the full ParaView license.
32 A copy of this license can be obtained by contacting
33 Kitware Inc.
34 28 Corporate Drive
35 Clifton Park, NY 12065
36 USA
37
38THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
41A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
42CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
43EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
44PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
45PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
46LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
47NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
48SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49
50=========================================================================*/
51
52#ifndef _ctkCheckableModelHelper_h
53#define _ctkCheckableModelHelper_h
54
55// Qt includes
56#include <QModelIndex>
57#include <QObject>
58class QAbstractItemModel;
59
60// CTK includes
61#include "ctkWidgetsExport.h"
62
63class ctkCheckableModelHelperPrivate;
64
68class CTK_WIDGETS_EXPORT ctkCheckableModelHelper : public QObject
69{
70 Q_OBJECT;
71 Q_PROPERTY(bool forceCheckability READ forceCheckability WRITE setForceCheckability);
72 Q_PROPERTY(int propagateDepth READ propagateDepth WRITE setPropagateDepth);
73 Q_PROPERTY(Qt::CheckState defaultCheckState READ defaultCheckState WRITE setDefaultCheckState);
74
75public:
76 ctkCheckableModelHelper(Qt::Orientation orientation, QObject *parent=0);
78
79 Qt::Orientation orientation()const;
80
81
89 QAbstractItemModel *model()const;
90 virtual void setModel(QAbstractItemModel *model);
91
93 QModelIndex rootIndex()const;
94 virtual void setRootIndex(const QModelIndex &index);
95
100 bool isHeaderCheckable(int section)const;
101 bool isCheckable(const QModelIndex& index)const;
102
107 Qt::CheckState headerCheckState(int section)const;
108 Qt::CheckState checkState(const QModelIndex&)const;
109
114 bool headerCheckState(int section, Qt::CheckState& checkState )const;
115 bool checkState(const QModelIndex&, Qt::CheckState& checkState )const;
116
120 void setPropagateDepth(int depth);
121 int propagateDepth()const;
122
124 void setForceCheckability(bool force);
125 bool forceCheckability()const;
126
127 Qt::CheckState defaultCheckState()const;
128 void setDefaultCheckState(Qt::CheckState);
129
130public Q_SLOTS:
131 void setCheckState(const QModelIndex& modelIndex, Qt::CheckState checkState);
135 void setHeaderCheckState(int section, Qt::CheckState checkState);
136
138 void toggleCheckState(const QModelIndex& modelIndex);
139 void toggleHeaderCheckState(int section);
140
141private Q_SLOTS:
142 void onHeaderDataChanged(Qt::Orientation orient, int first, int last);
143
144 void onDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
145 void updateHeadersFromItems();
146 void onColumnsInserted(const QModelIndex& parent, int start, int end);
147 void onRowsInserted(const QModelIndex& parent, int start, int end);
148
149protected:
150 QScopedPointer<ctkCheckableModelHelperPrivate> d_ptr;
151
152private:
153 Q_DECLARE_PRIVATE(ctkCheckableModelHelper);
154 Q_DISABLE_COPY(ctkCheckableModelHelper);
155};
156
157#endif
virtual ~ctkCheckableModelHelper()
void setHeaderCheckState(int section, Qt::CheckState checkState)
void setDefaultCheckState(Qt::CheckState)
int propagateDepth() const
void setCheckState(const QModelIndex &modelIndex, Qt::CheckState checkState)
bool isHeaderCheckable(int section) const
QAbstractItemModel * model() const
void toggleHeaderCheckState(int section)
void toggleCheckState(const QModelIndex &modelIndex)
Utility function to toggle the checkstate of an index.
Qt::CheckState defaultCheckState() const
bool forceCheckability() const
void setForceCheckability(bool force)
When true, the new items are automatically set to checkable.
QModelIndex rootIndex() const
Reimplemented for internal reasons.
Qt::Orientation orientation() const
void setPropagateDepth(int depth)
Qt::CheckState checkState(const QModelIndex &) const
bool isCheckable(const QModelIndex &index) const
QScopedPointer< ctkCheckableModelHelperPrivate > d_ptr
Qt::CheckState headerCheckState(int section) const
virtual void setRootIndex(const QModelIndex &index)
bool checkState(const QModelIndex &, Qt::CheckState &checkState) const
virtual void setModel(QAbstractItemModel *model)
bool headerCheckState(int section, Qt::CheckState &checkState) const
ctkCheckableModelHelper(Qt::Orientation orientation, QObject *parent=0)