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 
00039 class CTK_WIDGETS_EXPORT ctkAddRemoveComboBox : public QWidget
00040 {
00041   Q_OBJECT
00042   Q_PROPERTY(QString emptyText READ emptyText WRITE setEmptyText)
00043   Q_PROPERTY(bool addEnabled READ addEnabled WRITE setAddEnabled)
00044   Q_PROPERTY(bool removeEnabled READ removeEnabled WRITE setRemoveEnabled)
00045   Q_PROPERTY(bool editEnabled READ editEnabled WRITE setEditEnabled)
00046   
00047 public:
00049   typedef QWidget Superclass;
00050   
00052   explicit ctkAddRemoveComboBox(QWidget* parent = 0);
00053   virtual ~ctkAddRemoveComboBox(){}
00054   virtual void printAdditionalInfo();
00055   
00058   void setEmptyText(const QString& text); 
00059   QString emptyText()const;
00060   
00063   void setComboBoxEnabled(bool enable);
00064   bool comboBoxEnabled()const; 
00065   
00068   void setAddEnabled(bool enable);
00069   bool addEnabled()const; 
00070   
00073   void setRemoveEnabled(bool enable);
00074   bool removeEnabled()const;
00075   
00078   void setEditEnabled(bool enable); 
00079   bool editEnabled()const;
00080   
00081   inline void addItem(const QString &text, const QVariant &userDataVariable = QVariant() )
00082     {this->insertItem(this->count(), text, userDataVariable);}
00083   inline void addItem(const QIcon &icon, const QString &text, const QVariant &userDataVariable = QVariant() )
00084     {this->insertItem(this->count(), icon, text, userDataVariable);}
00085   inline void addItems(const QStringList &texts )
00086     {this->insertItems(this->count(), texts);}
00087     
00088   void insertItem(int index, const QString &text, const QVariant &userDataVariable = QVariant() );
00089   void insertItem(int index, const QIcon &icon, const QString &text, const QVariant &userDataVariable = QVariant() );
00090   void insertItems(int index, const QStringList &texts);  
00091   
00094   int count()const;
00095   bool empty()const;
00096     
00100   int findText(const QString& text, Qt::MatchFlags flags = Qt::MatchExactly | Qt::MatchCaseSensitive ) const;
00101   int findData(const QVariant & data, int role = Qt::UserRole, Qt::MatchFlags flags = Qt::MatchExactly | Qt::MatchCaseSensitive ) const;
00102 
00104   QString   itemText(int index) const;
00105   QVariant  itemData(int index, int role = Qt::UserRole) const;
00106 
00107   void setItemText(int index, const QString& text);
00108   void setItemData(int index, const QVariant& data, int role = Qt::UserRole);
00109 
00112   int       currentIndex() const;
00113   inline QString  currentText() const
00114     {return this->itemText(this->currentIndex());}
00115   inline QVariant currentData(int role = Qt::UserRole) const
00116     {return this->itemData(this->currentIndex(), role);}
00117 
00120   void removeItem(int index);
00121   inline void removeCurrentItem()
00122     {this->removeItem(this->currentIndex());}
00123 
00126   void clear();
00127 
00128 signals:
00129   void currentIndexChanged(int index);
00130   void activated(int index);
00131 
00134   void itemAdded(int index);
00135   
00137   void itemAboutToBeRemoved(int index);
00138   void itemRemoved(int index);
00139     
00140 public slots:
00143   void setCurrentIndex(int index);
00144 
00145 protected slots:
00147   virtual void onAdd();
00148   virtual void onRemove();
00149   virtual void onEdit();
00150 
00151 protected:
00152   void setComboBox(QComboBox* comboBox);
00153   QModelIndex rootModelIndex()const;
00154   void setRootModelIndex(const QModelIndex& root);
00155   int modelColumn()const;
00156   QAbstractItemModel* model()const;
00157 
00158 private slots:
00159   //void onRowsAboutToBeInserted(const QModelIndex & parent, int start, int end );
00160   void onRowsAboutToBeRemoved(const QModelIndex & parent, int start, int end);
00161   void onRowsInserted(const QModelIndex & parent, int start, int end);
00162   void onRowsRemoved(const QModelIndex & parent, int start, int end);
00163 
00164 private:
00165   CTK_DECLARE_PRIVATE(ctkAddRemoveComboBox);
00166 };
00167 
00168 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated on 21 May 2010 for CTK by  doxygen 1.6.1