00001 // Copyright (C) 2007-2011 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 : OB_Browser.h 00024 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) 00025 // 00026 #ifndef OB_BROWSER_H 00027 #define OB_BROWSER_H 00028 00029 #include "OB.h" 00030 00031 #include <QWidget> 00032 #include <QMap> 00033 #include <QModelIndex> 00034 #include <QItemSelection> 00035 00036 #ifdef WIN32 00037 #pragma warning( disable:4251 ) 00038 #endif 00039 00040 class QAbstractItemModel; 00041 class QAbstractItemDelegate; 00042 class QToolTip; 00043 class QMenu; 00044 class QtxTreeView; 00045 class QtxSearchTool; 00046 00047 class OB_EXPORT OB_Browser : public QWidget 00048 { 00049 Q_OBJECT 00050 00051 // TODO: commented - to be removed or revised 00052 //class ToolTip; 00053 00054 public: 00055 OB_Browser( QWidget* = 0, QAbstractItemModel* = 0 ); 00056 virtual ~OB_Browser(); 00057 00058 QAbstractItemModel* model() const; 00059 void setModel( QAbstractItemModel* ); 00060 00061 QAbstractItemDelegate* itemDelegate() const; 00062 void setItemDelegate( QAbstractItemDelegate* ); 00063 00064 bool rootIsDecorated() const; 00065 void setRootIsDecorated( const bool ); 00066 00067 bool sortMenuEnabled() const; 00068 void setSortMenuEnabled( const bool ); 00069 00070 QtxSearchTool* searchTool() const; 00071 bool isSearchToolEnabled() const; 00072 void setSearchToolEnabled( const bool ); 00073 00074 int autoOpenLevel() const; 00075 void setAutoOpenLevel( const int ); 00076 void openLevels( const int = -1 ); 00077 00078 //bool isShowToolTips(); 00079 //void setShowToolTips( const bool theDisplay ); 00080 00081 int numberOfSelected() const; 00082 QModelIndexList selectedIndexes() const; 00083 const QItemSelection selection() const; 00084 00085 virtual void select( const QModelIndex&, const bool, const bool = true ); 00086 virtual void select( const QModelIndexList&, const bool, const bool = true ); 00087 00088 bool isOpen( const QModelIndex& ) const; 00089 virtual void setOpen( const QModelIndex& theObject, const bool theOpen = true ); 00090 00091 void adjustWidth(); 00092 void adjustFirstColumnWidth(); 00093 void adjustColumnsWidth(); 00094 00095 // san - To be revised or removed 00096 // QTreeView::indexAt() should be used 00097 //SUIT_DataObject* dataObjectAt( const QPoint& ) const; 00098 00099 // san - Removed 00100 //OB_Filter* filter() const; 00101 //void setFilter( OB_Filter* ); 00102 00103 // TODO: QTreeView::resizeColumnToContents() can be used instead 00104 //virtual void setWidthMode( QListView::WidthMode ); 00105 00106 unsigned long getModifiedTime() const; 00107 void setModified(); 00108 00109 // san - moved to SUIT_TreeModel 00110 //OB_Updater* getUpdater() const; 00111 //virtual void setUpdater( OB_Updater* theUpdate = 0 ); 00112 00113 QtxTreeView* treeView() const; 00114 00115 signals: 00116 void selectionChanged(); 00117 //void doubleClicked( SUIT_DataObject* ); 00118 //void dropped( DataObjectList, SUIT_DataObject*, int ); 00119 00120 private slots: 00121 void onExpandAll(); 00122 void onCollapseAll(); 00123 //void onDestroyed( SUIT_DataObject* ); 00124 //void onDoubleClicked ( QListViewItem* ); 00125 //void onDropped( QPtrList<QListViewItem>, QListViewItem*, int ); 00126 00127 protected: 00128 //void adjustWidth( QListViewItem* ); 00129 //virtual void updateText(); 00130 00131 virtual void contextMenuEvent( QContextMenuEvent* ); 00132 virtual void createPopupMenu( QMenu* ); 00133 00134 private: 00135 //typedef QMap<SUIT_DataObject*, QListViewItem*> ItemMap; 00136 //typedef SUIT_DataObjectKeyHandle DataObjectKey; 00137 //typedef QMap<SUIT_DataObject*, int> DataObjectMap; 00138 //typedef QMap<DataObjectKey, int> DataObjectKeyMap; 00139 00140 private: 00141 bool hasCollased( const QModelIndex& ) const; 00142 bool hasExpanded( const QModelIndex& ) const; 00143 00144 //void autoOpenBranches(); 00145 //void openBranch( QListViewItem*, const int ); 00146 00147 //void removeReferences( QListViewItem* ); 00148 //void removeConnections( SUIT_DataObject* ); 00149 //void createConnections( SUIT_DataObject* ); 00150 //void removeObject( SUIT_DataObject*, const bool = true ); 00151 00152 //void updateText( QListViewItem* ); 00153 //bool needToUpdateTexts( QListViewItem* ) const; 00154 00155 //DataObjectKey objectKey( QListViewItem* ) const; 00156 //DataObjectKey objectKey( SUIT_DataObject* ) const; 00157 00158 //QListViewItem* createTree( const SUIT_DataObject*, QListViewItem*, QListViewItem* = 0, const bool = false ); 00159 //QListViewItem* createItem( const SUIT_DataObject*, QListViewItem*, QListViewItem* = 0, const bool = false ); 00160 00161 //SUIT_DataObject* storeState( DataObjectMap&, DataObjectMap&, 00162 // DataObjectKeyMap&, DataObjectKeyMap&, DataObjectKey& ) const; 00163 //void restoreState( const DataObjectMap&, const DataObjectMap&, const SUIT_DataObject*, 00164 // const DataObjectKeyMap&, const DataObjectKeyMap&, const DataObjectKey& ); 00165 00166 private: 00167 QtxTreeView* myView; 00168 QtxSearchTool* mySearchTool; 00169 // TODO: decide what to do with tooltip 00170 //QToolTip* myTooltip; 00171 //QMap<int, int> myColumnIds; 00172 // TODO: decide what to do with tooltip 00173 //bool myShowToolTips; 00174 int myAutoOpenLevel; 00175 unsigned long myModifiedTime; 00176 00177 // TODO: decide what to do with tooltip 00178 //friend class OB_Browser::ToolTip; 00179 }; 00180 00181 #endif // OB_BROWSER_H