Back to index

salome-gui  6.5.0
SalomeApp_ListView.h
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File   : SalomeApp_ListView.h
00024 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
00025 //
00026 #ifndef SALOMEAPP_LISTVIEW_H
00027 #define SALOMEAPP_LISTVIEW_H
00028 
00029 //#include <QtxListView.h>
00030 
00031 #include <SUIT_PopupClient.h>
00032 
00033 #include <QTreeWidget>
00034 #include <QTreeWidgetItem>
00035 #include <QString>
00036 #include <QLineEdit>
00037 #include <QComboBox>
00038 
00039 class QToolButton; 
00040 
00041 class TColStd_ListOfInteger;
00042 class TColStd_ListOfReal;
00043 
00044 // enumeration for ListView updating mode
00045 enum UpdateType {
00046   utCancel        = -1,           // cancel updating
00047   utNone          =  0,           // needs no any update
00048   utUpdateItem,                   // update one item
00049   utUpdateParent,                 // update parent item too
00050   utUpdateViewer,                 // update all viewer
00051   utUpdateAll                     // strong update
00052 };
00053 
00054 class SalomeApp_ListViewItem;
00055 class SalomeApp_EntityEdit;
00056 
00061 class SalomeApp_ListView : public QTreeWidget/*QtxListView*/ , public SUIT_PopupClient  {
00062   
00063   Q_OBJECT
00064     
00065 public:
00066 // constructor  
00067   SalomeApp_ListView(QWidget *parent);
00068 // destructor  
00069   virtual ~SalomeApp_ListView();
00070 
00071 // updates list viewer
00072   virtual void updateViewer();
00073 // updtes currently selected item(s)
00074   virtual void updateSelected();
00075 
00076 // fills popup with items
00077   virtual QString popupClientType() const;
00078   virtual void    contextMenuPopup( QMenu* );
00079 
00080 // setting editing of items availbale/not available
00081   void enableEditing(bool theFlag);
00082 // says if editing is enabled
00083   bool isEnableEditing();
00084 // accepts user input by calling finishEditing(true)
00085   void accept();
00086 
00087 // clears view
00088   void clear();
00089 
00090 // event filter
00091   bool eventFilter(QObject* object, QEvent* event) ;
00092 
00093 // gets current tooltip for list view
00094 // returns valid rect in success
00095   QRect tip(QPoint aPos, QString& aText, QRect& dspRect, QFont& dspFnt) const;
00096 
00097 protected:
00098 // handler for resize event
00099   void resizeEvent(QResizeEvent* e);
00100 // handler for paint event
00101   void viewportPaintEvent(QPaintEvent* e);
00102 // finishes editing of entity
00103   virtual UpdateType finishEditing(bool ok);
00104 
00105 // returns true if mouse events are enabled
00106   bool isMouseEnabled();
00107 // enables/disables mouse events (excluding MouseMove)
00108   void enableMouse(bool enable);
00109   
00110 protected slots:
00111 // called when selection changed in list
00112   virtual void onSelectionChanged();
00113 // called when user finishes in editing of item
00114   void onEditOk();
00115 // called when user cancels item editing
00116   void onEditCancel();
00117 // called when columns sizes are changed
00118   void onHeaderSizeChange(int, int, int);
00119 
00120 protected:
00121   SalomeApp_EntityEdit*   myEdit;
00122   SalomeApp_ListViewItem* myEditedItem;
00123   bool                    myEditingEnabled;
00124   bool                    myMouseEnabled;
00125 };
00126 
00127 
00128 class SalomeApp_EditBox: public QLineEdit
00129 {
00130   Q_OBJECT
00131 
00132 public:
00133   SalomeApp_EditBox(QWidget* parent);
00134  
00135 protected:
00136   void keyPressEvent(QKeyEvent* e);
00137   
00138 signals:
00139   void escapePressed();
00140 };
00141 
00142 class SalomeApp_ComboBox: public QComboBox 
00143 {
00144   Q_OBJECT
00145 
00146 public:
00147   SalomeApp_ComboBox(bool rw, QWidget* parent = 0, const char* name = 0);
00148 
00149   int findItem(const QString& theText);
00150   void insertItem(const QString& theValue, int theIndex = -1);
00151   void insertList(const QStringList& theList);
00152   void insertItem(const int theValue);
00153   void insertList(const TColStd_ListOfInteger& theList);
00154   void insertItem(const double theValue);
00155   void insertList(const TColStd_ListOfReal& theList);
00156 };
00157 
00158 class SalomeApp_EntityEdit : public QWidget 
00159 {
00160   Q_OBJECT
00161 
00162 public:
00163   // enum for edit control type
00164   enum {
00165     etLineEdit,           // simple edit box
00166     etComboBox,           // non-editable combo box
00167     etComboEdit           // editable combo box
00168   };
00169   // enum for value type
00170   enum {
00171     vtString,             // string
00172     vtInteger,            // integer value
00173     vtDouble              // double value
00174   };
00175   // enum for insertion order
00176   enum {
00177     atBottom,
00178     atTop,
00179     atBeforeCurrent,
00180     atAfterCurrent
00181   };
00182   // enum for edit box buttons (Apply = Cancel)
00183   enum {
00184     btApply  = 0x0001,
00185     btCancel = 0x0002
00186   };
00187 
00188 public:
00189   SalomeApp_EntityEdit( QWidget* parent, 
00190                         int      controlType = etLineEdit, 
00191                         int      valueType   = vtString,
00192                         bool     butApply    = false, 
00193                         bool     butCancel   = false);
00194   ~SalomeApp_EntityEdit();
00195 
00196   void finishEditing();
00197   void clear();
00198   QString getText();
00199   void setText(const QString& theText );
00200   void insertItem( const QString& theValue, 
00201                    bool           theSetCurrent = false,
00202                    int            theOrder = atBottom );
00203   void insertList( const QStringList& theList, 
00204                    const int          theCurrent = -1 );
00205   void insertItem( const int theValue, 
00206                    bool  theSetCurrent = false );
00207   void insertList( const TColStd_ListOfInteger& theList, 
00208                    const int                    theCurrent = -1 );
00209   void insertItem( const double theValue, 
00210                    bool         theSetCurrent = false );
00211   void insertList( const TColStd_ListOfReal& theList, 
00212                    const int                 theCurrent = -1 );
00213   QWidget* getControl();
00214   void setFocus();
00215   void setValidator(const QValidator*);
00216   void showButtons(bool show);
00217   void setDuplicatesEnabled(bool enabled);
00218 
00219 protected:
00220   void keyPressEvent ( QKeyEvent * e);
00221 
00222 private slots:
00223   void onComboActivated(const QString&);
00224   void onTextChanged(const QString&);
00225   void onApply();
00226   void onCancel();
00227 signals:
00228   void returnPressed();
00229   void escapePressed();
00230 
00231 private:
00232   // Widgets
00233   SalomeApp_EditBox*   myEdit;
00234   SalomeApp_ComboBox*  myCombo;
00235   QToolButton*         myApplyBtn;
00236   QToolButton*         myCancelBtn;
00237   QString              myString;
00238 };
00239 
00240 class SalomeApp_ListViewItem : public QTreeWidgetItem
00241 {
00242 public:
00243   SalomeApp_ListViewItem( SalomeApp_ListView* );
00244   SalomeApp_ListViewItem( SalomeApp_ListView*, 
00245                           SalomeApp_ListViewItem* );
00246   SalomeApp_ListViewItem( SalomeApp_ListView*,
00247                           const QStringList&,
00248                           const bool = false );
00249   SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
00250                           const QStringList&,
00251                           const bool = false );
00252   SalomeApp_ListViewItem( SalomeApp_ListView*,
00253                           SalomeApp_ListViewItem*,
00254                           const QString&,
00255                           const bool = false );
00256   SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
00257                           SalomeApp_ListViewItem*,
00258                           const QString&,
00259                           const bool = false);
00260   SalomeApp_ListViewItem( SalomeApp_ListView*,
00261                           SalomeApp_ListViewItem*,
00262                           const QString& theName,
00263                           const QString& theValue, 
00264                           const bool = false);
00265   SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
00266                           SalomeApp_ListViewItem*,
00267                           const QString&,
00268                           const QString&, 
00269                           const bool = false);
00270   ~SalomeApp_ListViewItem();
00271 
00272   QString            fullName();
00273   void               openAllLevels();
00274   virtual void       updateAllLevels();
00275   bool               isEditable() const;
00276   void               setEditable(bool theEditable);
00277 
00278   // returns true if entitiy is accepted after editing
00279   bool               isAccepted() const;
00280   // set entity accepted or not after editing
00281   void               setAccepted(bool theAccepted);
00282 
00283   // returns name of entity (as default it is text in first column)
00284   virtual QString    getName() const;
00285   // sets name of entity (as default it is text in first column)
00286   virtual UpdateType setName(const QString& theName);
00287 
00288   // returns value of entity (as default it is text in second column)
00289   virtual QString    getValue() const;
00290   // sets value of entity (as default it is text in second column)
00291   virtual UpdateType setValue(const QString& theValue);
00292 
00293   // creates control for editing and fills it with values
00294   SalomeApp_EntityEdit*    startEditing();
00295   // fills widget with initial values (list or single value)
00296   virtual void       fillWidgetWithValues(SalomeApp_EntityEdit* theWidget);
00297   // finishes editing of entity
00298   virtual UpdateType finishEditing(SalomeApp_EntityEdit* theWidget);
00299 
00300   // returns type of edit control (0 - edit box, 1 - combo box, 2 - editable combo box)
00301   virtual int        getEditingType();
00302   // sets type of edit control (0 - edit box, 1 - combo box, 2 - editable combo box)
00303   virtual void       setEditingType(const int);
00304   // returns edited column
00305   virtual int        getEditedColumn();
00306   // returns type of edited value (string, int, double)
00307   virtual int        getValueType();
00308   // sets type of edited value (string, int, double)
00309   virtual void       setValueType(const int);
00310 
00311   // gets user type 
00312   virtual int        getUserType();
00313   // sets user type 
00314   virtual void       setUserType(const int);
00315 
00316   // returns buttons for editing widget
00317   virtual int        getButtons();
00318   // sets  buttons for editing widget
00319   virtual void       setButtons(const int);
00320   // returns text for tooltip
00321   QString            tipText();
00322   // calculates rectangle which should contain items tip
00323   QRect              tipRect();
00324   // calculates rect of item text in viewport coordinates
00325   QRect              textRect(const int column) const;
00326   // calculates full rect of item data in viewport coordinates
00327   QRect              itemRect(const int column) const;
00328 
00329 protected:
00330   // initialization
00331   void               init();
00332   int                depth() const;
00333 
00334 private:
00335   bool myEditable;
00336   bool myAccepted;
00337   int  myEditingType;
00338   int  myValueType;
00339   int  myButtons;
00340   int  myUserType; // user are welcome to put additional data here and use it in fillWidgetWithValues()
00341 };
00342 
00343 
00344 #endif