casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QtComboCheckBox.qo.h
Go to the documentation of this file.
1 //# QtComboCheckBox.qo.h: Extension of QComboBox to use QCheckBoxes.
2 //# Copyright (C) 2009
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: $
27 #ifndef QTCOMBOCHECKBOX_QO_H_
28 #define QTCOMBOCHECKBOX_QO_H_
29 
30 #include <QComboBox>
31 #include <QItemDelegate>
32 
33 namespace casa {
34 
35 // Subclass of QItemDelegate for use with QtComboCheckBox.
36 // Based on http://da-crystal.net/GCMS/blog/checkboxlist-in-qt/
37 class QtComboCheckBoxDelegate : public QItemDelegate {
38 public:
39  // Constructor which takes optional parent.
40  QtComboCheckBoxDelegate(QObject* parent = NULL);
41 
42  // Destructor.
44 
45  // Overrides QItemDelegate::paint().
46  void paint(QPainter* painter, const QStyleOptionViewItem& option,
47  const QModelIndex &index) const;
48 
49  // Overrides QItemDelegate::createEditor().
50  QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
51  const QModelIndex& index) const;
52 
53  // Overrides QItemDelegate::setEditorData().
54  void setEditorData(QWidget* editor, const QModelIndex& index) const;
55 
56  // Overrides QItemDelegate::setModelData().
57  void setModelData(QWidget* editor, QAbstractItemModel* model,
58  const QModelIndex& index) const;
59 };
60 
61 
62 // Subclass of QComboBox that uses the item delegate above.
63 // Based on http://da-crystal.net/GCMS/blog/checkboxlist-in-qt/
64 class QtComboCheckBox : public QComboBox {
65  Q_OBJECT
66 
67 public:
68  // Constructor which takes optional parent.
69  QtComboCheckBox(QWidget* parent = NULL);
70 
71  // Destructor.
73 
74  // Overrides QObject::eventFilter().
75  bool eventFilter(QObject* object, QEvent* event);
76 
77  // Gets/Sets the display text.
78  // <group>
79  QString getDisplayText() const;
80  void setDisplayText(const QString& text);
81  // </group>
82 
83  // Gets/Sets whether the checkbox at the given index is toggled.
84  // <group>
85  bool indexIsToggled(int index) const;
86  void toggleIndex(int index, bool toggled);
87  // </group>
88 
89 signals:
90  // This signal is emitted when the user has finished changing the
91  // checkboxes.
92  void stateChanged();
93 
94 protected:
95  // Overrides QWidget::paintEvent().
96  void paintEvent(QPaintEvent* event);
97 
98 private:
99  // Display text.
101 };
102 
103 }
104 
105 #endif /* QTCOMBOCHECKBOX_QO_H_ */
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
Overrides QItemDelegate::createEditor().
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Overrides QItemDelegate::setModelData().
void setEditorData(QWidget *editor, const QModelIndex &index) const
Overrides QItemDelegate::setEditorData().
QString itsDisplayText_
Display text.
QtComboCheckBoxDelegate(QObject *parent=NULL)
Constructor which takes optional parent.
bool indexIsToggled(int index) const
Gets/Sets whether the checkbox at the given index is toggled.
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Overrides QItemDelegate::paint().
void setDisplayText(const QString &text)
~QtComboCheckBox()
Destructor.
bool eventFilter(QObject *object, QEvent *event)
Overrides QObject::eventFilter().
void paintEvent(QPaintEvent *event)
Overrides QWidget::paintEvent().
QString getDisplayText() const
Gets/Sets the display text.
Subclass of QComboBox that uses the item delegate above.
~QtComboCheckBoxDelegate()
Destructor.
void stateChanged()
This signal is emitted when the user has finished changing the checkboxes.
void toggleIndex(int index, bool toggled)
QtComboCheckBox(QWidget *parent=NULL)
Constructor which takes optional parent.
Subclass of QItemDelegate for use with QtComboCheckBox.