QtComboCheckBox.qo.h

Go to the documentation of this file.
00001 //# QtComboCheckBox.qo.h: Extension of QComboBox to use QCheckBoxes.
00002 //# Copyright (C) 2009
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: $
00027 #ifndef QTCOMBOCHECKBOX_QO_H_
00028 #define QTCOMBOCHECKBOX_QO_H_
00029 
00030 #include <QComboBox>
00031 #include <QItemDelegate>
00032 
00033 namespace casa {
00034 
00035 // Subclass of QItemDelegate for use with QtComboCheckBox.
00036 // Based on http://da-crystal.net/GCMS/blog/checkboxlist-in-qt/
00037 class QtComboCheckBoxDelegate : public QItemDelegate {
00038 public:
00039     // Constructor which takes optional parent.
00040     QtComboCheckBoxDelegate(QObject* parent = NULL);
00041     
00042     // Destructor.
00043     ~QtComboCheckBoxDelegate();
00044 
00045     // Overrides QItemDelegate::paint().
00046     void paint(QPainter* painter, const QStyleOptionViewItem& option,
00047             const QModelIndex &index) const;
00048 
00049     // Overrides QItemDelegate::createEditor().
00050     QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
00051             const QModelIndex& index) const;
00052 
00053     // Overrides QItemDelegate::setEditorData().
00054     void setEditorData(QWidget* editor, const QModelIndex& index) const;
00055 
00056     // Overrides QItemDelegate::setModelData().
00057     void setModelData(QWidget* editor, QAbstractItemModel* model,
00058             const QModelIndex& index) const;
00059 };
00060 
00061 
00062 // Subclass of QComboBox that uses the item delegate above.
00063 // Based on http://da-crystal.net/GCMS/blog/checkboxlist-in-qt/
00064 class QtComboCheckBox : public QComboBox {
00065     Q_OBJECT
00066 
00067 public:
00068     // Constructor which takes optional parent.
00069     QtComboCheckBox(QWidget* parent = NULL);
00070 
00071     // Destructor.
00072     ~QtComboCheckBox();
00073 
00074     // Overrides QObject::eventFilter().
00075     bool eventFilter(QObject* object, QEvent* event);
00076 
00077     // Gets/Sets the display text.
00078     // <group>
00079     QString getDisplayText() const;
00080     void setDisplayText(const QString& text);
00081     // </group>
00082     
00083     // Gets/Sets whether the checkbox at the given index is toggled.
00084     // <group>
00085     bool indexIsToggled(int index) const;
00086     void toggleIndex(int index, bool toggled);
00087     // </group>    
00088     
00089 signals:
00090     // This signal is emitted when the user has finished changing the
00091     // checkboxes.
00092     void stateChanged();
00093     
00094 protected:
00095     // Overrides QWidget::paintEvent().
00096     void paintEvent(QPaintEvent* event);
00097 
00098 private:
00099     // Display text.
00100     QString itsDisplayText_;
00101 };
00102 
00103 }
00104 
00105 #endif /* QTCOMBOCHECKBOX_QO_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1