itom 2.2.1
K:/git-itom/sources/itom/itomWidgets/helper/checkableModelHelper.h
00001 /* ********************************************************************
00002     itom software
00003     URL: http://www.uni-stuttgart.de/ito
00004     Copyright (C) 2016, Institut fuer Technische Optik (ITO),
00005     Universitaet Stuttgart, Germany
00006 
00007     This file is part of itom and its software development toolkit (SDK).
00008 
00009     itom is free software; you can redistribute it and/or modify it
00010     under the terms of the GNU Library General Public Licence as published by
00011     the Free Software Foundation; either version 2 of the Licence, or (at
00012     your option) any later version.
00013    
00014     In addition, as a special exception, the Institut fuer Technische
00015     Optik (ITO) gives you certain additional rights.
00016     These rights are described in the ITO LGPL Exception version 1.0,
00017     which can be found in the file LGPL_EXCEPTION.txt in this package.
00018 
00019     itom is distributed in the hope that it will be useful, but
00020     WITHOUT ANY WARRANTY; without even the implied warranty of
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library
00022     General Public Licence for more details.
00023 
00024     You should have received a copy of the GNU Library General Public License
00025     along with itom. If not, see <http://www.gnu.org/licenses/>.
00026 
00027     This file is a port and modified version of the 
00028     Common framework (http://www.commontk.org)
00029 *********************************************************************** */
00030 
00031 #ifndef CHECKABLEMODELHELPER_H
00032 #define CHECKABLEMODELHELPER_H
00033 
00034 // Qt includes
00035 #include <QModelIndex>
00036 #include <QObject>
00037 class QAbstractItemModel;
00038 
00039 
00040 class CheckableModelHelperPrivate;
00041 
00045 class CheckableModelHelper : public QObject
00046 {
00047   Q_OBJECT;
00048   Q_PROPERTY(bool forceCheckability READ forceCheckability WRITE setForceCheckability);
00049   Q_PROPERTY(int propagateDepth READ propagateDepth WRITE setPropagateDepth);
00050   Q_PROPERTY(Qt::CheckState defaultCheckState READ defaultCheckState WRITE setDefaultCheckState);
00051 
00052 public:
00053   CheckableModelHelper(Qt::Orientation orientation, QObject *parent=0);
00054   virtual ~CheckableModelHelper();
00055 
00056   Qt::Orientation orientation()const;
00057 
00058 
00066   QAbstractItemModel *model()const;
00067   virtual void setModel(QAbstractItemModel *model);
00068 
00070   QModelIndex rootIndex()const;
00071   virtual void setRootIndex(const QModelIndex &index);
00072 
00077   bool isHeaderCheckable(int section)const;
00078   bool isCheckable(const QModelIndex& index)const;
00079 
00084   Qt::CheckState headerCheckState(int section)const;
00085   Qt::CheckState checkState(const QModelIndex&)const;
00086 
00091   bool headerCheckState(int section, Qt::CheckState& checkState )const;
00092   bool checkState(const QModelIndex&, Qt::CheckState& checkState )const;
00093 
00097   void setPropagateDepth(int depth);
00098   int  propagateDepth()const;
00099 
00101   void setForceCheckability(bool force);
00102   bool forceCheckability()const;
00103 
00104   Qt::CheckState defaultCheckState()const;
00105   void setDefaultCheckState(Qt::CheckState);
00106 
00107 public Q_SLOTS:
00108   void setCheckState(const QModelIndex& modelIndex, Qt::CheckState checkState);
00112   void setHeaderCheckState(int section, Qt::CheckState checkState);
00113 
00115   void toggleCheckState(const QModelIndex& modelIndex);
00116   void toggleHeaderCheckState(int section);
00117 
00118 private Q_SLOTS:
00119   void onHeaderDataChanged(Qt::Orientation orient, int first, int last);
00120 
00121   void onDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
00122   void updateHeadersFromItems();
00123   void onColumnsInserted(const QModelIndex& parent, int start, int end);
00124   void onRowsInserted(const QModelIndex& parent, int start, int end);
00125 
00126 protected:
00127   QScopedPointer<CheckableModelHelperPrivate> d_ptr;
00128 
00129 private:
00130   Q_DECLARE_PRIVATE(CheckableModelHelper);
00131   Q_DISABLE_COPY(CheckableModelHelper);
00132 };
00133 
00134 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties Friends