casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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 //#include <casa/namespace.h>
00034 using namespace std;
00035 
00036 namespace casa {
00037 
00038 // Subclass of QItemDelegate for use with QtComboCheckBox.
00039 // Based on http://da-crystal.net/GCMS/blog/checkboxlist-in-qt/
00040 class QtComboCheckBoxDelegate : public QItemDelegate {
00041 public:
00042     // Constructor which takes optional parent.
00043     QtComboCheckBoxDelegate(QObject* parent = NULL);
00044     
00045     // Destructor.
00046     ~QtComboCheckBoxDelegate();
00047 
00048     // Overrides QItemDelegate::paint().
00049     void paint(QPainter* painter, const QStyleOptionViewItem& option,
00050             const QModelIndex &index) const;
00051 
00052     // Overrides QItemDelegate::createEditor().
00053     QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
00054             const QModelIndex& index) const;
00055 
00056     // Overrides QItemDelegate::setEditorData().
00057     void setEditorData(QWidget* editor, const QModelIndex& index) const;
00058 
00059     // Overrides QItemDelegate::setModelData().
00060     void setModelData(QWidget* editor, QAbstractItemModel* model,
00061             const QModelIndex& index) const;
00062 };
00063 
00064 
00065 // Subclass of QComboBox that uses the item delegate above.
00066 // Based on http://da-crystal.net/GCMS/blog/checkboxlist-in-qt/
00067 class QtComboCheckBox : public QComboBox {
00068     Q_OBJECT
00069 
00070 public:
00071     // Constructor which takes optional parent.
00072     QtComboCheckBox(QWidget* parent = NULL);
00073 
00074     // Destructor.
00075     ~QtComboCheckBox();
00076 
00077     // Overrides QObject::eventFilter().
00078     bool eventFilter(QObject* object, QEvent* event);
00079 
00080     // Gets/Sets the display text.
00081     // <group>
00082     QString getDisplayText() const;
00083     void setDisplayText(const QString& text);
00084     // </group>
00085     
00086     // Gets/Sets whether the checkbox at the given index is toggled.
00087     // <group>
00088     bool indexIsToggled(int index) const;
00089     void toggleIndex(int index, bool toggled);
00090     // </group>    
00091     
00092 signals:
00093     // This signal is emitted when the user has finished changing the
00094     // checkboxes.
00095     void stateChanged();
00096     
00097 protected:
00098     // Overrides QWidget::paintEvent().
00099     void paintEvent(QPaintEvent* event);
00100 
00101 private:
00102     // Display text.
00103     QString itsDisplayText_;
00104 };
00105 
00106 }
00107 
00108 #endif /* QTCOMBOCHECKBOX_QO_H_ */