ctkAddRemoveComboBox.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Library:   CTK
00004  
00005   Copyright (c) 2010  Kitware Inc.
00006 
00007   Licensed under the Apache License, Version 2.0 (the "License");
00008   you may not use this file except in compliance with the License.
00009   You may obtain a copy of the License at
00010 
00011       http://www.commontk.org/LICENSE
00012 
00013   Unless required by applicable law or agreed to in writing, software
00014   distributed under the License is distributed on an "AS IS" BASIS,
00015   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016   See the License for the specific language governing permissions and
00017   limitations under the License.
00018  
00019 =========================================================================*/
00020 
00021 #ifndef __ctkAddRemoveComboBox_h
00022 #define __ctkAddRemoveComboBox_h
00023 
00024 // Qt includes
00025 #include <QWidget>
00026 #include <QVariant>
00027 #include <QModelIndex>
00028 
00029 // CTK includes
00030 #include <ctkPimpl.h>
00031 
00032 #include "CTKWidgetsExport.h"
00033 
00034 class QComboBox;
00035 class ctkAddRemoveComboBoxPrivate;
00036 
00037 class CTK_WIDGETS_EXPORT ctkAddRemoveComboBox : public QWidget
00038 {
00039   Q_OBJECT
00040   Q_PROPERTY(QString emptyText READ emptyText WRITE setEmptyText)
00041   Q_PROPERTY(bool addEnabled READ addEnabled WRITE setAddEnabled)
00042   Q_PROPERTY(bool removeEnabled READ removeEnabled WRITE setRemoveEnabled)
00043   Q_PROPERTY(bool editEnabled READ editEnabled WRITE setEditEnabled)
00044   
00045 public:
00047   typedef QWidget Superclass;
00048   
00050   explicit ctkAddRemoveComboBox(QWidget* parent = 0);
00051   virtual ~ctkAddRemoveComboBox(){}
00052   virtual void printAdditionalInfo();
00053   
00056   void setEmptyText(const QString& text); 
00057   QString emptyText()const;
00058   
00061   void setComboBoxEnabled(bool enable);
00062   bool comboBoxEnabled()const; 
00063   
00066   void setAddEnabled(bool enable);
00067   bool addEnabled()const; 
00068   
00071   void setRemoveEnabled(bool enable);
00072   bool removeEnabled()const;
00073   
00076   void setEditEnabled(bool enable); 
00077   bool editEnabled()const;
00078   
00079   inline void addItem(const QString &text, const QVariant &userDataVariable = QVariant() )
00080     {this->insertItem(this->count(), text, userDataVariable);}
00081   inline void addItem(const QIcon &icon, const QString &text, const QVariant &userDataVariable = QVariant() )
00082     {this->insertItem(this->count(), icon, text, userDataVariable);}
00083   inline void addItems(const QStringList &texts )
00084     {this->insertItems(this->count(), texts);}
00085     
00086   void insertItem(int index, const QString &text, const QVariant &userDataVariable = QVariant() );
00087   void insertItem(int index, const QIcon &icon, const QString &text, const QVariant &userDataVariable = QVariant() );
00088   void insertItems(int index, const QStringList &texts);  
00089   
00092   int count()const;
00093   bool empty()const;
00094     
00098   int findText(const QString& text, Qt::MatchFlags flags = Qt::MatchExactly | Qt::MatchCaseSensitive ) const;
00099   int findData(const QVariant & data, int role = Qt::UserRole, Qt::MatchFlags flags = Qt::MatchExactly | Qt::MatchCaseSensitive ) const;
00100 
00102   QString   itemText(int index) const;
00103   QVariant  itemData(int index, int role = Qt::UserRole) const;
00104 
00105   void setItemText(int index, const QString& text);
00106   void setItemData(int index, const QVariant& data, int role = Qt::UserRole);
00107 
00110   int       currentIndex() const;
00111   inline QString  currentText() const
00112     {return this->itemText(this->currentIndex());}
00113   inline QVariant currentData(int role = Qt::UserRole) const
00114     {return this->itemData(this->currentIndex(), role);}
00115 
00118   void removeItem(int index);
00119   inline void removeCurrentItem()
00120     {this->removeItem(this->currentIndex());}
00121 
00124   void clear();
00125 
00126 signals:
00127   void currentIndexChanged(int index);
00128   void activated(int index);
00129 
00132   void itemAdded(int index);
00133   
00135   void itemAboutToBeRemoved(int index);
00136   void itemRemoved(int index);
00137     
00138 public slots:
00141   void setCurrentIndex(int index);
00142 
00143 protected slots:
00145   virtual void onAdd();
00146   virtual void onRemove();
00147   virtual void onEdit();
00148 
00149 protected:
00150   void setComboBox(QComboBox* comboBox);
00151   QModelIndex rootModelIndex()const;
00152   void setRootModelIndex(const QModelIndex& root);
00153   int modelColumn()const;
00154   QAbstractItemModel* model()const;
00155 
00156 private slots:
00157   //void onRowsAboutToBeInserted(const QModelIndex & parent, int start, int end );
00158   void onRowsAboutToBeRemoved(const QModelIndex & parent, int start, int end);
00159   void onRowsInserted(const QModelIndex & parent, int start, int end);
00160   void onRowsRemoved(const QModelIndex & parent, int start, int end);
00161 
00162 private:
00163   CTK_DECLARE_PRIVATE(ctkAddRemoveComboBox);
00164 };
00165 
00166 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines