From fd6666fd3d45357f78d74c352a15bdd1fc8d3373 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 20 Dec 2007 12:06:17 +0000 Subject: [PATCH] *** empty log message *** --- src/Makefile.am | 2 +- src/ObjBrowser/Makefile.am | 4 +- src/ObjBrowser/OB_Browser.cxx | 21 ++- src/ObjBrowser/OB_Browser.h | 10 +- src/SUIT/Makefile.am | 7 +- src/SUIT/SUIT_DataBrowser.cxx | 274 ++++++++++++++++++++++++++++++++++ src/SUIT/SUIT_DataBrowser.h | 76 ++++++++++ 7 files changed, 371 insertions(+), 23 deletions(-) create mode 100644 src/SUIT/SUIT_DataBrowser.cxx create mode 100644 src/SUIT/SUIT_DataBrowser.h diff --git a/src/Makefile.am b/src/Makefile.am index 4df8d2367..b60a92454 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,7 +24,7 @@ # Module : SALOME # $Header$ -SUBDIRS = Qtx Style DDS QDS SUIT SUITApp STD CAF CAM LogWindow Prs ObjBrowser +SUBDIRS = Qtx Style DDS QDS ObjBrowser SUIT SUITApp STD CAF CAM LogWindow Prs if ENABLE_SALOMEOBJECT SUBDIRS += OBJECT diff --git a/src/ObjBrowser/Makefile.am b/src/ObjBrowser/Makefile.am index 4672b0132..609e842f9 100755 --- a/src/ObjBrowser/Makefile.am +++ b/src/ObjBrowser/Makefile.am @@ -53,7 +53,7 @@ nodist_libObjBrowser_la_SOURCES= $(MOC_FILES) nodist_salomeres_DATA = OB_msg_en.qm -libObjBrowser_la_CPPFLAGS=$(QT_INCLUDES) -I$(srcdir)/../SUIT -I$(srcdir)/../Qtx +libObjBrowser_la_CPPFLAGS=$(QT_INCLUDES) -I$(srcdir)/../Qtx libObjBrowser_la_LDFLAGS=$(QT_MT_LIBS) -libObjBrowser_la_LIBADD= ../Qtx/libqtx.la ../SUIT/libsuit.la +libObjBrowser_la_LIBADD= ../Qtx/libqtx.la diff --git a/src/ObjBrowser/OB_Browser.cxx b/src/ObjBrowser/OB_Browser.cxx index 4e20fb928..95733fe01 100755 --- a/src/ObjBrowser/OB_Browser.cxx +++ b/src/ObjBrowser/OB_Browser.cxx @@ -172,15 +172,6 @@ OB_Browser::~OB_Browser() //setUpdater( 0 ); } -/*! - \brief Get popup menu client type. - \return popup client type -*/ -QString OB_Browser::popupClientType() const -{ - return "ObjectBrowser"; -} - /*! \brief Get data model. \return data model @@ -771,7 +762,15 @@ QtxTreeView* OB_Browser::treeView() const */ void OB_Browser::contextMenuEvent( QContextMenuEvent* e ) { - contextMenuRequest( e ); + QMenu* popup = new QMenu(); + + createPopupMenu( popup ); + + Qtx::simplifySeparators( popup ); + + if ( !popup->actions().isEmpty() ) + popup->exec( e->globalPos() ); + delete popup; } /*! @@ -928,7 +927,7 @@ void OB_Browser::updateText( QListViewItem* item ) \brief Add custom actions to the popup menu. \param menu popup menu */ -void OB_Browser::contextMenuPopup( QMenu* menu ) +void OB_Browser::createPopupMenu( QMenu* menu ) { menu->addSeparator(); diff --git a/src/ObjBrowser/OB_Browser.h b/src/ObjBrowser/OB_Browser.h index 9c0ffa2bb..28dcc9fb3 100755 --- a/src/ObjBrowser/OB_Browser.h +++ b/src/ObjBrowser/OB_Browser.h @@ -25,8 +25,6 @@ #include "OB.h" -#include - #include #include #include @@ -39,10 +37,11 @@ class QAbstractItemModel; class QAbstractItemDelegate; class QToolTip; +class QMenu; class QtxTreeView; class OB_FindDlg; -class OB_EXPORT OB_Browser : public QWidget, public SUIT_PopupClient +class OB_EXPORT OB_Browser : public QWidget { Q_OBJECT @@ -53,8 +52,6 @@ public: OB_Browser( QWidget* = 0, QAbstractItemModel* = 0 ); virtual ~OB_Browser(); - virtual QString popupClientType() const; - QAbstractItemModel* model() const; void setModel( QAbstractItemModel* ); @@ -97,8 +94,6 @@ public: // TODO: QTreeView::resizeColumnToContents() can be used instead //virtual void setWidthMode( QListView::WidthMode ); - virtual void contextMenuPopup( QMenu* ); - unsigned long getModifiedTime() const; void setModified(); @@ -126,6 +121,7 @@ protected: //virtual void updateText(); virtual void contextMenuEvent( QContextMenuEvent* ); + virtual void createPopupMenu( QMenu* ); private: //typedef QMap ItemMap; diff --git a/src/SUIT/Makefile.am b/src/SUIT/Makefile.am index f64bf49a0..08ba0a6d9 100755 --- a/src/SUIT/Makefile.am +++ b/src/SUIT/Makefile.am @@ -30,6 +30,7 @@ salomeinclude_HEADERS= \ SUIT_Accel.h \ SUIT_ActionOperation.h \ SUIT_Application.h \ + SUIT_DataBrowser.h \ SUIT_DataObject.h \ SUIT_DataObjectIterator.h \ SUIT_DataObjectKey.h \ @@ -61,6 +62,7 @@ dist_libsuit_la_SOURCES= \ SUIT_Accel.cxx \ SUIT_ActionOperation.cxx \ SUIT_Application.cxx \ + SUIT_DataBrowser.cxx \ SUIT_DataObject.cxx \ SUIT_DataObjectIterator.cxx \ SUIT_DataObjectKey.cxx \ @@ -90,6 +92,7 @@ MOC_FILES= \ SUIT_Accel_moc.cxx \ SUIT_ActionOperation_moc.cxx \ SUIT_Application_moc.cxx \ + SUIT_DataBrowser_moc.cxx \ SUIT_DataObject_moc.cxx \ SUIT_Desktop_moc.cxx \ SUIT_FileDlg_moc.cxx \ @@ -110,6 +113,6 @@ nodist_libsuit_la_SOURCES=$(MOC_FILES) nodist_salomeres_DATA = \ SUIT_msg_en.qm -libsuit_la_CPPFLAGS=$(QT_INCLUDES) -I$(srcdir)/../Qtx +libsuit_la_CPPFLAGS=$(QT_INCLUDES) -I$(srcdir)/../Qtx -I$(srcdir)/../ObjBrowser libsuit_la_LDFLAGS=$(QT_MT_LIBS) -libsuit_la_LIBADD=../Qtx/libqtx.la +libsuit_la_LIBADD=../Qtx/libqtx.la ../ObjBrowser/libObjBrowser.la diff --git a/src/SUIT/SUIT_DataBrowser.cxx b/src/SUIT/SUIT_DataBrowser.cxx new file mode 100644 index 000000000..32c92c013 --- /dev/null +++ b/src/SUIT/SUIT_DataBrowser.cxx @@ -0,0 +1,274 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : SUIT_DataBrowser.cxx +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// + +#include "SUIT_DataBrowser.h" +#include +#include + +#include + +/*! + \class SUIT_DataBrowser + \brief Object browser customization. +*/ + +/*! + \brief Constructor. + \param parent parent widget +*/ +SUIT_DataBrowser::SUIT_DataBrowser( QWidget* parent ) +: OB_Browser( parent ) +{ + init( 0 ); +} + +/*! + \brief Constructor. + \param root root data object + \param parent parent widget +*/ +SUIT_DataBrowser::SUIT_DataBrowser( SUIT_DataObject* root, QWidget* parent ) +: OB_Browser( parent ) +{ + init( root ); +} + +/*! + \brief Destructor. +*/ +SUIT_DataBrowser::~SUIT_DataBrowser() +{ +} + +/*! + \brief Get popup menu client type. + \return popup client type +*/ +QString SUIT_DataBrowser::popupClientType() const +{ + return "ObjectBrowser"; +} + +/*! + \brief Get root object. + \return root object +*/ +SUIT_DataObject* SUIT_DataBrowser::root() const +{ + SUIT_ProxyModel* m = qobject_cast( model() ); + return m ? m->root() : 0; +} + +/*! + \brief Set root object. + \param r new root object +*/ +void SUIT_DataBrowser::setRoot( SUIT_DataObject* r ) +{ + SUIT_ProxyModel* m = qobject_cast( model() ); + if ( m ) + m->setRoot( r ); +} + +/*! + \brief Get 'auto-update tree' flag value. + \return 'auto-update tree' flag value + \sa setAutoUpdate(), updateTree() +*/ +bool SUIT_DataBrowser::autoUpdate() const +{ + SUIT_ProxyModel* m = qobject_cast( model() ); + return m ? m->autoUpdate() : false; +} + +/*! + \brief Set 'auto-update tree' flag value. + + If this flag is set to \c true (by default), the object browser is updated + automatically when data tree is changed. + + \param on 'auto-update tree' flag value + \sa autoUpdate(), updateTree() +*/ +void SUIT_DataBrowser::setAutoUpdate( const bool on ) +{ + SUIT_ProxyModel* m = qobject_cast( model() ); + if ( m ) + m->setAutoUpdate( on ); +} + +/*! + \brief Update object browser starting from the object \obj; + open all branches automatically if \a autoOpen is \c true. + \param obj starting object for updating + \param autoOpen if \c true automatically open branches +*/ +void SUIT_DataBrowser::updateTree( SUIT_DataObject* obj, const bool autoOpen ) +{ + SUIT_ProxyModel* m = qobject_cast( model() ); + if ( m ) { + m->updateTree( obj ); + openLevels(); + } +} + +/*! + \brief Get current key accelerator used for the + object browser update operation. + \return current key accelerator + \sa setUpdateKey(), requestUpdate() +*/ +int SUIT_DataBrowser::updateKey() const +{ + return myShortcut->key(); +} + +/*! + \brief Assign the key accelerator to be used for the + object browser update operation. + + By default, \c [F5] key is assigned for the update operation. + To disable the accelerator, pass 0 to this method. + + \param key new key accelerator + \sa updateKey(), requestUpdate() +*/ +void SUIT_DataBrowser::setUpdateKey( const int key ) +{ + myShortcut->setKey( key ); +} + +/*! + \brief Get list of selected data objects. + \return list of the currently selected data objects +*/ +DataObjectList SUIT_DataBrowser::getSelected() const +{ + DataObjectList lst; + getSelected( lst ); + return lst; +} + +/*! + \brief Get list of selected data objects. + \overload + \param lst list to be filled with the currently selected data objects +*/ +void SUIT_DataBrowser::getSelected( DataObjectList& lst ) const +{ + lst.clear(); + + SUIT_ProxyModel* m = qobject_cast( model() ); + + if ( m ) { + QModelIndexList sel = selectedIndexes(); + QModelIndex idx; + + foreach( idx, sel ) { + SUIT_DataObject* obj = m->object( idx ); + if ( obj ) + lst.append( obj ); + } + } +} + +/*! + \brief Set selected object. + \param obj data object to set selected + \param append if \c true, the object is added to the current selection; + otherwise the previous selection is first cleared +*/ +void SUIT_DataBrowser::setSelected( const SUIT_DataObject* obj, const bool append ) +{ + SUIT_ProxyModel* m = qobject_cast( model() ); + + if ( m ) { + QModelIndex index = m->index( obj ); + if ( index.isValid() ) + select( index, true, append ); + } +} + +/*! + \brief Set list of selected data objects. + \param lst list of the data object to set selected + \param append if \c true, the objects are added to the current selection; + otherwise the previous selection is first cleared +*/ +void SUIT_DataBrowser::setSelected( const DataObjectList& lst, const bool append ) +{ + SUIT_ProxyModel* m = qobject_cast( model() ); + + if ( m ) { + QModelIndexList indexes; + SUIT_DataObject* obj; + + foreach( obj, lst ) { + QModelIndex index = m->index( obj ); + if ( index.isValid() ) + indexes.append( index ); + } + select( indexes, true, append ); // if !indexes.isEmpty() ??? + } +} + +/*! + \brief Add custom actions to the popup menu. + \param menu popup menu +*/ +void SUIT_DataBrowser::contextMenuPopup( QMenu* menu ) +{ + createPopupMenu( menu ); +} + +/*! + \brief Process context menu request event. + \param e context menu event +*/ +void SUIT_DataBrowser::contextMenuEvent( QContextMenuEvent* e ) +{ + contextMenuRequest( e ); +} + +/*! + \brief Initialize object browser. + \param root root data object +*/ +void SUIT_DataBrowser::init( SUIT_DataObject* root ) +{ + setModel( new SUIT_ProxyModel( root, this ) ); + setItemDelegate( qobject_cast( model() )->delegate() ); + connect( treeView(), SIGNAL( sortingEnabled(bool ) ), + model(), SLOT( setSortingEnabled( bool ) ) ); + myShortcut = new QShortcut( Qt::Key_F5, this, SIGNAL( requestUpdate() ), SIGNAL( requestUpdate() ) ); +} + +/*! + \fn void SUIT_DataBrowser::requestUpdate(); + \brief The signal is emitted when the key accelerator + assigned for the update operation is pressed by the user. + + By default, \c [F5] key is assigned for the update operation. + The key accelerator can be changed with the setUpdateKey() method. + + \sa updateKey(), setUpdateKey() +*/ diff --git a/src/SUIT/SUIT_DataBrowser.h b/src/SUIT/SUIT_DataBrowser.h new file mode 100644 index 000000000..25794a685 --- /dev/null +++ b/src/SUIT/SUIT_DataBrowser.h @@ -0,0 +1,76 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : SUIT_DataBrowser.h +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// + +#ifndef SUIT_DATABROWSER_H +#define SUIT_DATABROWSER_H + +#include "SUIT.h" +#include "SUIT_PopupClient.h" +#include "SUIT_DataObject.h" +#include + +class QShortcut; + +class SUIT_EXPORT SUIT_DataBrowser : public OB_Browser, public SUIT_PopupClient +{ + Q_OBJECT + +public: + SUIT_DataBrowser( QWidget* = 0 ); + SUIT_DataBrowser( SUIT_DataObject*, QWidget* = 0 ); + ~SUIT_DataBrowser(); + + virtual QString popupClientType() const; + + SUIT_DataObject* root() const; + void setRoot( SUIT_DataObject* ); + + bool autoUpdate() const; + void setAutoUpdate( const bool ); + + void updateTree( SUIT_DataObject* = 0, const bool = true ); + + int updateKey() const; + void setUpdateKey( const int ); + + DataObjectList getSelected() const; + void getSelected( DataObjectList& ) const; + + void setSelected( const SUIT_DataObject*, const bool = false ); + void setSelected( const DataObjectList&, const bool = false ); + + virtual void contextMenuPopup( QMenu* ); + +protected: + virtual void contextMenuEvent( QContextMenuEvent* ); + +private: + void init( SUIT_DataObject* ); + +signals: + void requestUpdate(); + +private: + QShortcut* myShortcut; +}; + +#endif // SUIT_BROWSER_H -- 2.39.2