From c05ed8ec0b6cc2bb8492a2e2f82b0c11b461ba03 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 8 Oct 2008 12:17:45 +0000 Subject: [PATCH] Merge from BR_V5_DEV. --- src/SUIT/SUIT_DataBrowser.cxx | 110 +++++++++++++++++++++++++++++++- src/SUIT/SUIT_DataBrowser.h | 14 ++++ src/SUIT/SUIT_PreferenceMgr.cxx | 18 +++--- src/SUIT/SUIT_TreeModel.cxx | 13 +++- src/SUIT/SUIT_TreeModel.h | 6 ++ 5 files changed, 146 insertions(+), 15 deletions(-) diff --git a/src/SUIT/SUIT_DataBrowser.cxx b/src/SUIT/SUIT_DataBrowser.cxx index 9dd97b1fe..c392b10f0 100644 --- a/src/SUIT/SUIT_DataBrowser.cxx +++ b/src/SUIT/SUIT_DataBrowser.cxx @@ -130,6 +130,11 @@ void SUIT_DataBrowser::updateTree( SUIT_DataObject* obj, const bool autoOpen ) if ( m ) { m->updateTree( obj ); openLevels(); + + if (myAutoSizeFirstColumn) + adjustFirstColumnWidth(); + if (myAutoSizeColumns) + adjustColumnsWidth(); } } @@ -242,6 +247,34 @@ void SUIT_DataBrowser::contextMenuPopup( QMenu* menu ) createPopupMenu( menu ); } +/*! + \brief Set 'auto-size first column' flag value. + + If this flag is set to \c true (by default), the first column width is resized + to its contents. + + \param on 'auto-size first column' flag value + \sa setAutoSizeColumns() +*/ +void SUIT_DataBrowser::setAutoSizeFirstColumn( const bool on ) +{ + myAutoSizeFirstColumn = on; +} + +/*! + \brief Set 'auto-size columns' flag value. + + If this flag is set to \c true (by default is false), columns width except + the first column is resized to its contents. + + \param on 'auto-size columns' flag value + \sa setAutoSizeFirstColumn() +*/ +void SUIT_DataBrowser::setAutoSizeColumns( const bool on ) +{ + myAutoSizeColumns = on; +} + /*! \brief Process context menu request event. \param e context menu event @@ -251,17 +284,41 @@ void SUIT_DataBrowser::contextMenuEvent( QContextMenuEvent* e ) contextMenuRequest( e ); } +/*! + \brief Set 'resize on expand item' flag value. + + If this flag is set to \c true (by default is false), after + expanding an item columns will be resized to its contents. + + \param on 'resize on expand item' flag value +*/ +void SUIT_DataBrowser::setResizeOnExpandItem( const bool on ) +{ + myResizeOnExpandItem = on; +} + /*! \brief Initialize object browser. \param root root data object */ void SUIT_DataBrowser::init( SUIT_DataObject* root ) { - setModel( new SUIT_ProxyModel( root, this ) ); + SUIT_ProxyModel* m = new SUIT_ProxyModel( root, this ); + connect( m, SIGNAL( modelUpdated() ), this, SLOT( onModelUpdated() ) ); + + setModel( m ); setItemDelegate( qobject_cast( model() )->delegate() ); - connect( treeView(), SIGNAL( sortingEnabled(bool ) ), - model(), SLOT( setSortingEnabled( bool ) ) ); + connect( treeView(), SIGNAL( sortingEnabled( bool ) ), + model(), SLOT( setSortingEnabled( bool ) ) ); + connect( treeView(), SIGNAL( doubleClicked( const QModelIndex& ) ), + this, SLOT( onDblClicked( const QModelIndex& ) ) ); + connect( treeView(), SIGNAL( expanded( const QModelIndex& ) ), + this, SLOT( onExpanded( const QModelIndex& ) ) ); myShortcut = new QShortcut( Qt::Key_F5, this, SIGNAL( requestUpdate() ), SIGNAL( requestUpdate() ) ); + + myAutoSizeFirstColumn = true; + myAutoSizeColumns = false; + myResizeOnExpandItem = false; } /*! @@ -274,3 +331,50 @@ void SUIT_DataBrowser::init( SUIT_DataObject* root ) \sa updateKey(), setUpdateKey() */ + +/*! + \fn void SUIT_DataBrowser::doubleClicked( SUIT_DataObject* o ); + \brief This signal is emitted when a mouse button is double-clicked. + + The data object the mouse was double-clicked on is specified by \a o. + The signal is only emitted when the object is valid. + + \param o data object which is double-clicked +*/ + +/*! + \brief Update internal modification time just after data model update +*/ +void SUIT_DataBrowser::onModelUpdated() +{ + setModified(); +} + +/*! + \brief Called when item is double-clicked in the tree view + \internal + + Emits signal doubleClicked( SUIT_DataObject* ); +*/ +void SUIT_DataBrowser::onDblClicked( const QModelIndex& index ) +{ + SUIT_ProxyModel* m = qobject_cast( model() ); + + if ( m ) { + SUIT_DataObject* obj = m->object( index ); + if ( obj ) emit( doubleClicked( obj ) ); + } +} + +/*! + \brief Called when item specified by index is expanded. + \internal +*/ +void SUIT_DataBrowser::onExpanded( const QModelIndex& index ) +{ + if (myResizeOnExpandItem) { + adjustFirstColumnWidth(); + adjustColumnsWidth(); + } +} + diff --git a/src/SUIT/SUIT_DataBrowser.h b/src/SUIT/SUIT_DataBrowser.h index 6cb2b00d4..75584bfaa 100644 --- a/src/SUIT/SUIT_DataBrowser.h +++ b/src/SUIT/SUIT_DataBrowser.h @@ -60,6 +60,10 @@ public: virtual void contextMenuPopup( QMenu* ); + void setAutoSizeFirstColumn( const bool on ); + void setAutoSizeColumns( const bool on ); + void setResizeOnExpandItem( const bool on ); + protected: virtual void contextMenuEvent( QContextMenuEvent* ); @@ -68,9 +72,19 @@ private: signals: void requestUpdate(); + void doubleClicked( SUIT_DataObject* ); + +private slots: + void onModelUpdated(); + void onDblClicked( const QModelIndex& ); + void onExpanded( const QModelIndex& ); private: QShortcut* myShortcut; + + bool myAutoSizeFirstColumn; + bool myAutoSizeColumns; + bool myResizeOnExpandItem; }; #endif // SUIT_BROWSER_H diff --git a/src/SUIT/SUIT_PreferenceMgr.cxx b/src/SUIT/SUIT_PreferenceMgr.cxx index 0424de3ca..191eef251 100644 --- a/src/SUIT/SUIT_PreferenceMgr.cxx +++ b/src/SUIT/SUIT_PreferenceMgr.cxx @@ -1,17 +1,17 @@ // 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 +// 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 +// +// 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 +// 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 @@ -76,7 +76,7 @@ int SUIT_PreferenceMgr::addItem( const QString& title, const int pId, QtxPreferenceItem* item = parent->findItem( title, true ); - if ( item ) + if ( item && item->depth() < 4 ) return item->id(); if ( pId == -1 ) diff --git a/src/SUIT/SUIT_TreeModel.cxx b/src/SUIT/SUIT_TreeModel.cxx index b2c1e880a..147e87e16 100755 --- a/src/SUIT/SUIT_TreeModel.cxx +++ b/src/SUIT/SUIT_TreeModel.cxx @@ -144,7 +144,7 @@ SUIT_TreeModel::TreeItem* SUIT_TreeModel::TreeItem::parent() const */ int SUIT_TreeModel::TreeItem::position() const { - return myParent->myChildren.indexOf( (TreeItem*)this ); + return myParent ? myParent->myChildren.indexOf( (TreeItem*)this ) : -1; } /*! @@ -482,6 +482,7 @@ void SUIT_TreeModel::setRoot( SUIT_DataObject* r ) //initialize(); reset(); + emit modelUpdated(); } /*! @@ -920,6 +921,7 @@ void SUIT_TreeModel::updateTree( SUIT_DataObject* obj ) synchronize( obj, treeItem( obj ), SUIT_TreeModel::TreeSync( this ) ); + emit modelUpdated(); } /*! @@ -1120,7 +1122,9 @@ SUIT_ProxyModel::SUIT_ProxyModel( QObject* parent ) : QSortFilterProxyModel( parent ), mySortingEnabled( true ) { - setSourceModel( new SUIT_TreeModel( this ) ); + SUIT_TreeModel* model = new SUIT_TreeModel( this ); + connect( model, SIGNAL( modelUpdated() ), this, SIGNAL( modelUpdated() ) ); + setSourceModel( model ); } /*! @@ -1132,7 +1136,9 @@ SUIT_ProxyModel::SUIT_ProxyModel( SUIT_DataObject* root, QObject* parent ) : QSortFilterProxyModel( parent ), mySortingEnabled( true ) { - setSourceModel( new SUIT_TreeModel( root, this ) ); + SUIT_TreeModel* model = new SUIT_TreeModel( root, this ); + connect( model, SIGNAL( modelUpdated() ), this, SIGNAL( modelUpdated() ) ); + setSourceModel( model ); } /*! @@ -1144,6 +1150,7 @@ SUIT_ProxyModel::SUIT_ProxyModel( SUIT_TreeModel* model, QObject* parent ) : QSortFilterProxyModel( parent ), mySortingEnabled( true ) { + connect( model, SIGNAL( modelUpdated() ), this, SIGNAL( modelUpdated() ) ); setSourceModel( model ); } diff --git a/src/SUIT/SUIT_TreeModel.h b/src/SUIT/SUIT_TreeModel.h index e5ad92517..06c028383 100755 --- a/src/SUIT/SUIT_TreeModel.h +++ b/src/SUIT/SUIT_TreeModel.h @@ -108,6 +108,9 @@ public slots: virtual void updateTree( const QModelIndex& ); virtual void updateTree( SUIT_DataObject* = 0 ); +signals: + void modelUpdated(); + private: void initialize(); @@ -169,6 +172,9 @@ public slots: virtual void updateTree( SUIT_DataObject* = 0 ); void setSortingEnabled( bool ); +signals: + void modelUpdated(); + protected: virtual bool lessThan( const QModelIndex&, const QModelIndex& ) const; -- 2.39.2