From: san Date: Fri, 2 Jul 2010 11:43:36 +0000 (+0000) Subject: Modifications for KALLISTO project. X-Git-Tag: TG_For_Atlas_v1_3_2d~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e321f0fd19491e7bdf634cfcf9c521ac6be5272a;p=modules%2Fgui.git Modifications for KALLISTO project. --- diff --git a/src/ObjBrowser/OB_Browser.cxx b/src/ObjBrowser/OB_Browser.cxx index e2d0f0b73..1bf8769f7 100755 --- a/src/ObjBrowser/OB_Browser.cxx +++ b/src/ObjBrowser/OB_Browser.cxx @@ -116,7 +116,7 @@ void OB_Browser::ToolTip::maybeTip( const QPoint& pos ) The class OB_Browser implements public API of an object browser widget that can be used to display arbitrary application data in a hierarchical form. - It is based on Qt4 model/view architecture. + It is based on Qt4 model/view architecture. Object browser can be used with conjuction of any custom item model inherited from QAbstractItemModel class (see Qt 4 reference manual). @@ -143,7 +143,7 @@ OB_Browser::OB_Browser( QWidget* parent, QAbstractItemModel* model ) mySearchTool->setFrameStyle( QFrame::NoFrame | QFrame::Plain ); mySearchTool->setActivators( QtxSearchTool::StandardKey | QtxSearchTool::SlashKey ); mySearchTool->setSearcher( new QtxTreeViewSearcher( myView ) ); - + QVBoxLayout* main = new QVBoxLayout( this ); main->addWidget( myView ); main->addWidget( mySearchTool ); @@ -322,7 +322,7 @@ void OB_Browser::setAutoOpenLevel( const int levels ) \brief Expand all branches to the specified number of levels. If \a levels value is negative, then autoOpenLevel() value is used instead. - + \param levels number of levels to be expanded \sa autoOpenLevel() */ @@ -386,7 +386,7 @@ const QItemSelection OB_Browser::selection() const \brief Select/deselect specified model index. \param index model index to be selected/deselected \param on if \c true, the index will be selected, otherwise - deselected - \param keepSelection if \c true (default) the previous selection is kept, + \param keepSelection if \c true (default) the previous selection is kept, otherwise it is first cleared */ void OB_Browser::select( const QModelIndex& index, const bool on, const bool keepSelection ) @@ -405,7 +405,7 @@ void OB_Browser::select( const QModelIndex& index, const bool on, const bool kee \brief Select/deselect specified model indices. \param indexes model indices to be selected/deselected \param on if \c true, the indices will be selected, otherwise - deselected - \param keepSelection if \c true (default) the previous selection is kept, + \param keepSelection if \c true (default) the previous selection is kept, otherwise it is first cleared */ void OB_Browser::select( const QModelIndexList& indexes, const bool on, const bool keepSelection ) @@ -452,6 +452,15 @@ void OB_Browser::setOpen( const QModelIndex& index, const bool open ) myView->setExpanded( index, open ); // hasChildren() ??? } +/*! + \brief Expand the all parent items of item specifed by the \index. + \param index model index to be opened +*/ +void OB_Browser::expandTo( const QModelIndex& index ) +{ + myView->expandTo( index ); +} + /*! \brief Adjust first column width to its contents. */ @@ -821,7 +830,7 @@ QtxTreeView* OB_Browser::treeView() const void OB_Browser::contextMenuEvent( QContextMenuEvent* e ) { QMenu* popup = new QMenu(); - + createPopupMenu( popup ); Qtx::simplifySeparators( popup ); @@ -836,8 +845,8 @@ void OB_Browser::contextMenuEvent( QContextMenuEvent* e ) \return latest updating time */ unsigned long OB_Browser::getModifiedTime() const -{ - return myModifiedTime; +{ + return myModifiedTime; } /*! @@ -850,7 +859,7 @@ void OB_Browser::setModified() /*! \brief Called when "Expand all" popup menu command is activated. - + Expands all selected items recursively. */ void OB_Browser::onExpandAll() @@ -865,7 +874,7 @@ void OB_Browser::onExpandAll() /*! \brief Called when "Collapse all" popup menu command is activated. - + Collapse all selected items recursively. */ void OB_Browser::onCollapseAll() @@ -982,13 +991,13 @@ void OB_Browser::createPopupMenu( QMenu* menu ) QModelIndexList indexes = selectedIndexes(); bool closed = false, opened = false; - - for ( QModelIndexList::Iterator it = indexes.begin(); + + for ( QModelIndexList::Iterator it = indexes.begin(); it != indexes.end() && !closed; ++it ) { closed = hasCollased( *it ); } - for ( QModelIndexList::Iterator it = indexes.begin(); + for ( QModelIndexList::Iterator it = indexes.begin(); it != indexes.end() && !opened; ++it ) { opened = hasExpanded( *it ); } diff --git a/src/ObjBrowser/OB_Browser.h b/src/ObjBrowser/OB_Browser.h index 289b5ce6a..a66fb1fa0 100755 --- a/src/ObjBrowser/OB_Browser.h +++ b/src/ObjBrowser/OB_Browser.h @@ -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 @@ -67,7 +67,7 @@ public: QtxSearchTool* searchTool() const; bool isSearchToolEnabled() const; void setSearchToolEnabled( const bool ); - + int autoOpenLevel() const; void setAutoOpenLevel( const int ); void openLevels( const int = -1 ); @@ -85,6 +85,8 @@ public: bool isOpen( const QModelIndex& ) const; virtual void setOpen( const QModelIndex& theObject, const bool theOpen = true ); + void expandTo( const QModelIndex& ); + void adjustWidth(); void adjustFirstColumnWidth(); void adjustColumnsWidth(); @@ -102,7 +104,7 @@ public: unsigned long getModifiedTime() const; void setModified(); - + // san - moved to SUIT_TreeModel //OB_Updater* getUpdater() const; //virtual void setUpdater( OB_Updater* theUpdate = 0 ); @@ -120,7 +122,7 @@ private slots: //void onDestroyed( SUIT_DataObject* ); //void onDoubleClicked ( QListViewItem* ); //void onDropped( QPtrList, QListViewItem*, int ); - + protected: //void adjustWidth( QListViewItem* ); //virtual void updateText(); diff --git a/src/Qtx/QtxResourceMgr.cxx b/src/Qtx/QtxResourceMgr.cxx index 80812a2f1..2640b7ce5 100644 --- a/src/Qtx/QtxResourceMgr.cxx +++ b/src/Qtx/QtxResourceMgr.cxx @@ -387,11 +387,19 @@ QTranslator* QtxResourceMgr::Resources::loadTranslator( const QString& sect, con { QTranslator* trans = new QtxTranslator( 0 ); QString fname = fileName( sect, prefix, name ); + if ( fname.isEmpty() ) + return 0; + if ( !trans->load( Qtx::file( fname, false ), Qtx::dir( fname ) ) ) { + qDebug( "Can't to load translation file '%s'", (const char*)fname.toLatin1() ); delete trans; trans = 0; } + else { + qDebug( "Translation file '%s' is loaded successfully", (const char*)fname.toLatin1() ); + } + return trans; } @@ -681,7 +689,7 @@ bool QtxResourceMgr::XmlFormat::load( const QString& fname, QMap& logicalIndices, +void QtxTreeView::Header::setSortIndicators( const QVector& logicalIndices, const QVector& orders ) { mySortSections = logicalIndices; @@ -205,12 +205,12 @@ void QtxTreeView::Header::setSortIndicators( const QVector& logicalIndices, \param orders Out parameter, orders[i] contains the current sort order for section logicalIndices[i] \internal */ -void QtxTreeView::Header::sortIndicators( QVector& logicalIndices, +void QtxTreeView::Header::sortIndicators( QVector& logicalIndices, QVector& orders ) const { logicalIndices.clear(); orders.clear(); - + if ( isSortIndicatorShown() ){ logicalIndices.push_back( sortIndicatorSection() ); orders.push_back ( sortIndicatorOrder () ); @@ -334,7 +334,7 @@ void QtxTreeView::Header::paintSection( QPainter* painter, const QRect& rect, in style()->drawItemText( painter, //rect, QRect( rect.left(), rect.top(), rect.width() - 2, rect.height() ), - Qt::AlignRight, + Qt::AlignRight, opt.palette, ( opt.state & QStyle::State_Enabled ), QString( "%1" ).arg( ++sortIndex ), @@ -414,7 +414,7 @@ void QtxTreeView::Header::contextMenuEvent( QContextMenuEvent* e ) else if ( qVariantCanConvert( iconData ) ) icon = qVariantValue( iconData ); } - if ( ( !lab.isEmpty() || !icon.isNull() ) && + if ( ( !lab.isEmpty() || !icon.isNull() ) && appropriate.isValid() ? appropriate.toBool() : true ) { QAction* a = menu.addAction( icon, lab ); a->setCheckable( true ); @@ -453,7 +453,7 @@ void QtxTreeView::Header::contextMenuEvent( QContextMenuEvent* e ) \brief Tree view class with possibility to display columns popup menu. The QtxTreeView class represents a customized tree view class. In addition to the - base functionality inherited from the QTreeView class, clicking at the tree view + base functionality inherited from the QTreeView class, clicking at the tree view header with the right mouse button displays the popup menu allowing the user to show/hide specified columns. @@ -462,7 +462,7 @@ void QtxTreeView::Header::contextMenuEvent( QContextMenuEvent* e ) the data model (see QAbstractItemModel class). The custom model should implement headerData() method and return \c true for the Qtx::AppropriateRole role for those columns which should be available in the popup menu and \c false for the columns - which should not be added to it. + which should not be added to it. */ /*! @@ -495,7 +495,7 @@ QtxTreeView::~QtxTreeView() /*! \brief Expand all branches for specified number of levels. - + If \c levels < 0, all branches are expanded (the same results can be achieved with expandAll() method). @@ -509,7 +509,7 @@ void QtxTreeView::expandLevels( const int levels ) /*! \brief Collapse all branches for specified number of levels. - + If \c levels < 0, all branches are collapsed (the same results can be achieved with collapseAll() method). @@ -543,6 +543,23 @@ void QtxTreeView::collapseAll( const QModelIndex& index ) setOpened( index, -1, false ); } +/*! + \brief Expand the all parent items of item specifed by the \index. + \param index model index to be opened + \sa expandAll() +*/ +void QtxTreeView::expandTo( const QModelIndex& index ) +{ + if ( !index.isValid() ) + return; + + QModelIndex idx = index.parent(); + while ( idx.isValid() ) { + expand( idx ); + idx = idx.parent(); + } +} + /* \brief Enable/disable "Sorting" popup menu command for the header. \param enableSortMenu if \c true, enable "Sorting" menu command @@ -605,7 +622,7 @@ void QtxTreeView::resizeColumnToEncloseContents( int column ) void QtxTreeView::setSortingEnabled( const bool enable ) { Header* h = dynamic_cast( header() ); - if ( h ) + if ( h ) h->setSortingEnabled( enable ); } @@ -622,7 +639,7 @@ bool QtxTreeView::sortingEnabled() const /*! \brief Enables multi-column sorting. - As soon as multi-column sorting is enabled, the user can click + As soon as multi-column sorting is enabled, the user can click several header sections in required order while holding key so as to sort the contents of the tree view on a basis of these columns' values. The column clicked first has maximum sort priority, the column clicked last has minimum sort priority. @@ -673,13 +690,13 @@ void QtxTreeView::onHeaderClicked() /*! \brief Called when the selection is changed. - + Emits selectionChanged() signal. - + \param selected new selection \param deselected previous selection */ -void QtxTreeView::selectionChanged( const QItemSelection& selected, +void QtxTreeView::selectionChanged( const QItemSelection& selected, const QItemSelection& deselected ) { QTreeView::selectionChanged( selected, deselected ); diff --git a/src/Qtx/QtxTreeView.h b/src/Qtx/QtxTreeView.h index 412b5ae7a..be47a4ab2 100644 --- a/src/Qtx/QtxTreeView.h +++ b/src/Qtx/QtxTreeView.h @@ -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 @@ -61,11 +61,13 @@ public: void setMultiSortEnabled( const bool ); bool multiSortEnabled() const; + void expandTo( const QModelIndex& ); + protected slots: void onHeaderClicked(); void rowsAboutToBeRemoved( const QModelIndex&, int, int ); void selectionChanged( const QItemSelection&, const QItemSelection& ); - + protected: void setOpened( const QModelIndex&, const int, bool ); virtual void drawRow( QPainter*, const QStyleOptionViewItem&, diff --git a/src/SUIT/SUIT_DataBrowser.cxx b/src/SUIT/SUIT_DataBrowser.cxx index c392b10f0..e2bff47ce 100644 --- a/src/SUIT/SUIT_DataBrowser.cxx +++ b/src/SUIT/SUIT_DataBrowser.cxx @@ -1,30 +1,31 @@ // 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 // // File : SUIT_DataBrowser.cxx // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) -// +// #include "SUIT_DataBrowser.h" #include #include #include +#include /*! \class SUIT_DataBrowser @@ -85,7 +86,7 @@ SUIT_DataObject* SUIT_DataBrowser::root() const void SUIT_DataBrowser::setRoot( SUIT_DataObject* r ) { SUIT_ProxyModel* m = qobject_cast( model() ); - if ( m ) + if ( m ) m->setRoot( r ); } @@ -114,7 +115,7 @@ bool SUIT_DataBrowser::autoUpdate() const void SUIT_DataBrowser::setAutoUpdate( const bool on, const bool updateImmediately ) { SUIT_ProxyModel* m = qobject_cast( model() ); - if ( m ) + if ( m ) m->setAutoUpdate( on, updateImmediately ); } @@ -139,7 +140,7 @@ void SUIT_DataBrowser::updateTree( SUIT_DataObject* obj, const bool autoOpen ) } /*! - \brief Get current key accelerator used for the + \brief Get current key accelerator used for the object browser update operation. \return current key accelerator \sa setUpdateKey(), requestUpdate() @@ -150,7 +151,7 @@ int SUIT_DataBrowser::updateKey() const } /*! - \brief Assign the key accelerator to be used for the + \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. @@ -189,7 +190,7 @@ void SUIT_DataBrowser::getSelected( DataObjectList& lst ) const if ( m ) { QModelIndexList sel = selectedIndexes(); QModelIndex idx; - + foreach( idx, sel ) { SUIT_DataObject* obj = m->object( idx ); if ( obj ) @@ -238,6 +239,37 @@ void SUIT_DataBrowser::setSelected( const DataObjectList& lst, const bool append } } +/*! + \brief Expand the all parent items of item specifed by the \obj. + \param obj data object to be opened +*/ +void SUIT_DataBrowser::expandTo( const SUIT_DataObject* obj ) +{ + SUIT_ProxyModel* m = qobject_cast( model() ); + + if ( m ) { + QModelIndex index = m->index( obj ); + if ( index.isValid() ) + OB_Browser::expandTo( index ); + } +} + +/*! + \brief Scroll the contents of the object browser until the given data object \obj is visible. + The \hint parameter specifies where the object should be located after the operation. + \param obj data object to be visible +*/ +void SUIT_DataBrowser::scrollTo( const SUIT_DataObject* obj, QAbstractItemView::ScrollHint hint ) +{ + SUIT_ProxyModel* m = qobject_cast( model() ); + + if ( m ) { + QModelIndex index = m->index( obj ); + if ( index.isValid() ) + treeView()->scrollTo( index, hint ); + } +} + /*! \brief Add custom actions to the popup menu. \param menu popup menu @@ -264,7 +296,7 @@ void SUIT_DataBrowser::setAutoSizeFirstColumn( const bool on ) /*! \brief Set 'auto-size columns' flag value. - If this flag is set to \c true (by default is false), columns width except + 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 @@ -305,14 +337,14 @@ void SUIT_DataBrowser::init( SUIT_DataObject* root ) { 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 ) ), + connect( treeView(), SIGNAL( sortingEnabled( bool ) ), model(), SLOT( setSortingEnabled( bool ) ) ); - connect( treeView(), SIGNAL( doubleClicked( const QModelIndex& ) ), + connect( treeView(), SIGNAL( doubleClicked( const QModelIndex& ) ), this, SLOT( onDblClicked( const QModelIndex& ) ) ); - connect( treeView(), SIGNAL( expanded( const QModelIndex& ) ), + connect( treeView(), SIGNAL( expanded( const QModelIndex& ) ), this, SLOT( onExpanded( const QModelIndex& ) ) ); myShortcut = new QShortcut( Qt::Key_F5, this, SIGNAL( requestUpdate() ), SIGNAL( requestUpdate() ) ); @@ -353,7 +385,7 @@ void SUIT_DataBrowser::onModelUpdated() /*! \brief Called when item is double-clicked in the tree view \internal - + Emits signal doubleClicked( SUIT_DataObject* ); */ void SUIT_DataBrowser::onDblClicked( const QModelIndex& index ) diff --git a/src/SUIT/SUIT_DataBrowser.h b/src/SUIT/SUIT_DataBrowser.h index 75584bfaa..5544e7f10 100644 --- a/src/SUIT/SUIT_DataBrowser.h +++ b/src/SUIT/SUIT_DataBrowser.h @@ -1,24 +1,24 @@ // 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 // // File : SUIT_DataBrowser.h // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) -// +// #ifndef SUIT_DATABROWSER_H #define SUIT_DATABROWSER_H @@ -26,8 +26,11 @@ #include "SUIT.h" #include "SUIT_PopupClient.h" #include "SUIT_DataObject.h" + #include +#include + class QShortcut; class SUIT_EXPORT SUIT_DataBrowser : public OB_Browser, public SUIT_PopupClient @@ -58,6 +61,9 @@ public: void setSelected( const SUIT_DataObject*, const bool = false ); void setSelected( const DataObjectList&, const bool = false ); + void expandTo( const SUIT_DataObject* ); + void scrollTo( const SUIT_DataObject*, QAbstractItemView::ScrollHint = QAbstractItemView::EnsureVisible ); + virtual void contextMenuPopup( QMenu* ); void setAutoSizeFirstColumn( const bool on ); diff --git a/src/SUIT/SUIT_DataObject.cxx b/src/SUIT/SUIT_DataObject.cxx index 8d96d85ab..d7b8e6654 100755 --- a/src/SUIT/SUIT_DataObject.cxx +++ b/src/SUIT/SUIT_DataObject.cxx @@ -831,6 +831,14 @@ void SUIT_DataObject::dump( const int indent ) const (*it)->dump( indent + 2 ); } +/*! + \brief Notify the data model about data object changes. +*/ +void SUIT_DataObject::dataChanged() +{ + signal()->emitChanged( this ); +} + /*! \class SUIT_DataObject::Signal \brief Watcher class, responsible for the emitting signals on behalf of @@ -890,6 +898,16 @@ void SUIT_DataObject::Signal::emitCreated( SUIT_DataObject* object ) emit created( object ); } +/*! + \brief Emit signal about data object changes. + \param object data object being changed +*/ +void SUIT_DataObject::Signal::emitChanged( SUIT_DataObject* object ) +{ + if ( object ) + emit changed( object ); +} + /*! \brief Emit signal about data object destroying. \param object data object being destroyed diff --git a/src/SUIT/SUIT_DataObject.h b/src/SUIT/SUIT_DataObject.h index 40916cf03..53a821269 100755 --- a/src/SUIT/SUIT_DataObject.h +++ b/src/SUIT/SUIT_DataObject.h @@ -135,6 +135,9 @@ public: void dump( const int indent = 2 ) const; // dump to cout +protected: + void dataChanged(); + private: SUIT_DataObject* myParent; bool myOpen; @@ -158,6 +161,7 @@ public: private: void emitCreated( SUIT_DataObject* ); + void emitChanged( SUIT_DataObject* ); void emitDestroyed( SUIT_DataObject* ); void emitInserted( SUIT_DataObject*, SUIT_DataObject* ); void emitRemoved( SUIT_DataObject*, SUIT_DataObject* ); @@ -166,9 +170,10 @@ private: signals: void created( SUIT_DataObject* ); + void changed( SUIT_DataObject* ); void destroyed( SUIT_DataObject* ); - void inserted( SUIT_DataObject*, SUIT_DataObject* ); void removed( SUIT_DataObject*, SUIT_DataObject* ); + void inserted( SUIT_DataObject*, SUIT_DataObject* ); friend class SUIT_DataObject; diff --git a/src/SUIT/SUIT_TreeModel.cxx b/src/SUIT/SUIT_TreeModel.cxx index 4cfd7e81a..70f59a390 100755 --- a/src/SUIT/SUIT_TreeModel.cxx +++ b/src/SUIT/SUIT_TreeModel.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 @@ -48,7 +48,7 @@ public: QList children() const; TreeItem* nextSibling() const; TreeItem* prevSibling() const; - + private: TreeItem* myParent; QList myChildren; @@ -62,7 +62,7 @@ private: \param parent parent item \param after tree item after each this one should be inserted */ -SUIT_TreeModel::TreeItem::TreeItem( SUIT_DataObject* obj, +SUIT_TreeModel::TreeItem::TreeItem( SUIT_DataObject* obj, SUIT_TreeModel::TreeItem* parent, SUIT_TreeModel::TreeItem* after ) : myParent( parent ), @@ -95,7 +95,7 @@ SUIT_TreeModel::TreeItem::~TreeItem() \param child child item being inserted \param after tree item after each \a child should be inserted */ -void SUIT_TreeModel::TreeItem::insertChild( SUIT_TreeModel::TreeItem* child, +void SUIT_TreeModel::TreeItem::insertChild( SUIT_TreeModel::TreeItem* child, SUIT_TreeModel::TreeItem* after ) { if ( !child ) @@ -200,7 +200,7 @@ SUIT_TreeModel::TreeItem* SUIT_TreeModel::TreeItem::prevSibling() const /*! \class SUIT_TreeModel::TreeSync - \brief Functor class for synchronizing data tree and tree model + \brief Functor class for synchronizing data tree and tree model when the data tree is changed outside the model. \internal */ @@ -237,7 +237,7 @@ SUIT_TreeModel::TreeSync::TreeSync( SUIT_TreeModel* model ) \brief Check if item corresponds to the specified data object. \internal \param obj data object - \param item tree item + \param item tree item \return \c true if item corresponds to the data object */ bool SUIT_TreeModel::TreeSync::isEqual( const ObjPtr& obj, const ItemPtr& item ) const @@ -276,7 +276,7 @@ SUIT_TreeModel::ItemPtr SUIT_TreeModel::TreeSync::nullTrg() const \return created item */ SUIT_TreeModel::ItemPtr SUIT_TreeModel::TreeSync::createItem( const ObjPtr& obj, - const ItemPtr& parent, + const ItemPtr& parent, const ItemPtr& after ) const { ItemPtr item = myModel ? myModel->createItem( obj, parent, after ) : 0; @@ -297,7 +297,7 @@ void SUIT_TreeModel::TreeSync::updateItem( const ObjPtr& obj, const ItemPtr& ite { if( obj ) obj->update(); - if ( item && needUpdate( item ) ) + if ( item && needUpdate( item ) ) myModel->updateItem( item ); } @@ -335,7 +335,7 @@ QList SUIT_TreeModel::TreeSync::children( const ObjPtr& QList SUIT_TreeModel::TreeSync::children( const ItemPtr& item ) const { QList ch; - if ( item ) + if ( item ) ch = item->children(); return ch; } @@ -373,12 +373,12 @@ bool SUIT_TreeModel::TreeSync::needUpdate( const ItemPtr& item ) const // 1. check text /* update = ( item->text( 0 ) != obj->name() ) || myBrowser->needToUpdateTexts( item ); - if ( !update ) { + if ( !update ) { // 2. check pixmap (compare serialNumber()-s) QPixmap objPix = obj->icon(); const QPixmap* itemPix = item->pixmap( 0 ); - update = ( objPix.isNull() && ( itemPix && !itemPix->isNull() ) ) || - ( !objPix.isNull() && ( !itemPix || itemPix->isNull() ) ); + update = ( objPix.isNull() && ( itemPix && !itemPix->isNull() ) ) || + ( !objPix.isNull() && ( !itemPix || itemPix->isNull() ) ); if ( !update && !objPix.isNull() && itemPix && !itemPix->isNull() ) { int aIconW = objPix.width(); if( aIconW > 20 ) { @@ -400,8 +400,8 @@ bool SUIT_TreeModel::TreeSync::needUpdate( const ItemPtr& item ) const \brief Implementation of the model/view API based on the tree of SUIT_DataObject class instances. - The SUIT_TreeModel class does not support insertion/removal of rows. It is synchronized - automatically with the tree of data objects used by SUIT-based applications to + The SUIT_TreeModel class does not support insertion/removal of rows. It is synchronized + automatically with the tree of data objects used by SUIT-based applications to expose their data in a hierarchical form to the user. */ @@ -506,86 +506,86 @@ QVariant SUIT_TreeModel::data( const QModelIndex& index, int role ) const switch ( role ) { case DisplayRole: // data object text for the specified column - val = obj->text( index.column() ); + val = obj->text( index.column() ); break; case DecorationRole: // data object icon for the specified column - val = obj->icon( index.column() ); + val = obj->icon( index.column() ); break; case ToolTipRole: // data object tooltip for the specified column - val = obj->toolTip( index.column() ); + val = obj->toolTip( index.column() ); break; case StatusTipRole: // data object status tip for the specified column - val = obj->statusTip( index.column() ); + val = obj->statusTip( index.column() ); break; case WhatsThisRole: // data object what's this info for the specified column - val = obj->whatsThis( index.column() ); + val = obj->whatsThis( index.column() ); break; case FontRole: // data object font for the specified column - val = obj->font( index.column() ); + val = obj->font( index.column() ); break; case TextAlignmentRole: // data object text alignment for the specified column - val = obj->alignment( index.column() ); + val = obj->alignment( index.column() ); break; case BackgroundRole: // data background color for the specified column c = obj->color( SUIT_DataObject::Background, index.column() ); // NOTE by san: Zero alpha is treated as fully transparent, therefore no background // is drawn at all (that is, the base color will appear instead of the custom backround). - // However, maximum alpha (each QColor has alpha == 1.0f by default) might be also unacceptable - // since it disables blending effects that might be used by a custom style. + // However, maximum alpha (each QColor has alpha == 1.0f by default) might be also unacceptable + // since it disables blending effects that might be used by a custom style. // Thus applications should choose color's alpha themselves to get required visual result. if ( !c.isValid() ){ // default value, should be fully transparent c = QApplication::palette().color( QPalette::Base ); c.setAlpha( 0 ); } - val = c; + val = c; break; case ForegroundRole: // data foreground (text) color for the specified column c = obj->color( SUIT_DataObject::Foreground, index.column() ); if ( !c.isValid() ) // default value c = QApplication::palette().color( QPalette::Foreground ); - val = c; + val = c; break; case BaseColorRole: // editor background color for the specified column c = obj->color( SUIT_DataObject::Base, index.column() ); if ( !c.isValid() ) // default value c = QApplication::palette().color( QPalette::Base ); - val = c; + val = c; break; case TextColorRole: // editor foreground (text) color for the specified column c = obj->color( SUIT_DataObject::Text, index.column() ); if ( !c.isValid() ) // default value c = QApplication::palette().color( QPalette::Text ); - val = c; + val = c; break; case HighlightRole: // adta object highlighted background color for the specified column c = obj->color( SUIT_DataObject::Highlight, index.column() ); if ( !c.isValid() ) // default value c = QApplication::palette().color( QPalette::Highlight ); - val = c; + val = c; break; case HighlightedTextRole: // data object highlighted foreground (text) color for the specified column c = obj->color( SUIT_DataObject::HighlightedText, index.column() ); if ( !c.isValid() ) // default value c = QApplication::palette().color( QPalette::HighlightedText ); - val = c; + val = c; break; case CheckStateRole: // data object checked state for the specified column // NOTE! three-state check is not supported currently if ( obj->isCheckable( index.column() ) ) - val = obj->isOn( index.column() ) ? Qt::Checked : Qt::Unchecked; + val = obj->isOn( index.column() ) ? Qt::Checked : Qt::Unchecked; break; case SizeHintRole: // data size hint @@ -606,7 +606,7 @@ QVariant SUIT_TreeModel::data( const QModelIndex& index, int role ) const \return \c true if data is set \sa data() */ -bool SUIT_TreeModel::setData( const QModelIndex& index, +bool SUIT_TreeModel::setData( const QModelIndex& index, const QVariant& value, int role ) { if ( index.isValid() && value.isValid() ) { @@ -699,7 +699,7 @@ QVariant SUIT_TreeModel::headerData( int column, Qt::Orientation orientation, \param parent parent model index \return model index */ -QModelIndex SUIT_TreeModel::index( int row, int column, +QModelIndex SUIT_TreeModel::index( int row, int column, const QModelIndex& parent ) const { if ( hasIndex( row, column, parent ) ) { @@ -924,8 +924,8 @@ void SUIT_TreeModel::updateTree( SUIT_DataObject* obj ) else if ( obj->root() != root() ) return; - synchronize( obj, - treeItem( obj ), + synchronize( obj, + treeItem( obj ), SUIT_TreeModel::TreeSync( this ) ); emit modelUpdated(); } @@ -999,7 +999,7 @@ SUIT_DataObject* SUIT_TreeModel::object( const SUIT_TreeModel::TreeItem* item ) { if ( item == rootItem() ) return root(); - + SUIT_DataObject* obj = item ? item->dataObject() : 0; return myItems.contains( obj ) ? obj : 0; } @@ -1012,7 +1012,7 @@ SUIT_DataObject* SUIT_TreeModel::object( const SUIT_TreeModel::TreeItem* item ) \return created tree item or 0 if item could not be created */ SUIT_TreeModel::TreeItem* SUIT_TreeModel::createItem( SUIT_DataObject* obj, - SUIT_TreeModel::TreeItem* parent, + SUIT_TreeModel::TreeItem* parent, SUIT_TreeModel::TreeItem* after ) { if ( !obj ) @@ -1041,11 +1041,11 @@ void SUIT_TreeModel::updateItem( SUIT_TreeModel::TreeItem* item ) { if ( !item ) return; - + SUIT_DataObject* obj = object( item ); if ( !obj ) return; - + // update all columns corresponding to the given data object QModelIndex firstIdx = index( obj, 0 ); QModelIndex lastIdx = index( obj, obj->columnCount() - 1 ); @@ -1068,13 +1068,13 @@ void SUIT_TreeModel::removeItem( SUIT_TreeModel::TreeItem* item ) removeItem( item->child( 0 ) ); SUIT_DataObject* obj = object( item ); - + // Warning! obj can be deleted at this point! SUIT_DataObject* parentObj = object( item->parent() ); QModelIndex parentIdx = index( parentObj, 0 ); int row = item->position(); - + beginRemoveRows( parentIdx, row, row ); myItems.remove( obj ); @@ -1099,6 +1099,17 @@ void SUIT_TreeModel::onInserted( SUIT_DataObject* /*object*/, SUIT_DataObject* p updateTree( parent ); } +/*! + \brief Called when the data object is changed. + \param object data object being changed +*/ +void SUIT_TreeModel::onChanged( SUIT_DataObject* obj ) +{ + QModelIndex idx = index( obj ); + if ( idx.isValid() ) + emit dataChanged( idx, idx ); +} + /*! \brief Called when the data object is removed from the tree. \param object data object being removed @@ -1317,7 +1328,7 @@ SUIT_TreeModel* SUIT_ProxyModel::treeModel() const This class can be used to render the SUIT_DataObject-based item in the widgets like QTreeView and others. - Refer to the Qt 4 documentation, model/view architecture + Refer to the Qt 4 documentation, model/view architecture section for more details). */ @@ -1339,7 +1350,7 @@ SUIT_ItemDelegate::SUIT_ItemDelegate( QObject* parent ) \param option painting option \param index model index being rendered */ -void SUIT_ItemDelegate::paint( QPainter* painter, +void SUIT_ItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { diff --git a/src/SUIT/SUIT_TreeModel.h b/src/SUIT/SUIT_TreeModel.h index 32eec7923..960a5db02 100755 --- a/src/SUIT/SUIT_TreeModel.h +++ b/src/SUIT/SUIT_TreeModel.h @@ -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 @@ -49,7 +49,7 @@ private: class TreeSync; typedef SUIT_DataObject* ObjPtr; typedef SUIT_TreeModel::TreeItem* ItemPtr; - + public: //! Data role typedef enum { @@ -109,7 +109,7 @@ public slots: virtual void updateTree( SUIT_DataObject* = 0 ); signals: - void modelUpdated(); + void modelUpdated(); private: void initialize(); @@ -120,18 +120,19 @@ private: SUIT_DataObject* object( const TreeItem* ) const; TreeItem* createItem( SUIT_DataObject*, - TreeItem* = 0, + TreeItem* = 0, TreeItem* = 0 ); void updateItem( TreeItem* ); void removeItem( TreeItem* ); private slots: + void onChanged( SUIT_DataObject* ); void onInserted( SUIT_DataObject*, SUIT_DataObject* ); void onRemoved( SUIT_DataObject*, SUIT_DataObject* ); private: typedef QMap ItemMap; - + SUIT_DataObject* myRoot; TreeItem* myRootItem; ItemMap myItems; @@ -162,7 +163,7 @@ public: bool autoUpdate() const; void setAutoUpdate( const bool, const bool = true ); - + QAbstractItemDelegate* delegate() const; public slots: @@ -182,7 +183,7 @@ class SUIT_EXPORT SUIT_ItemDelegate : public QItemDelegate public: SUIT_ItemDelegate( QObject* = 0 ); - + virtual void paint( QPainter*, const QStyleOptionViewItem&, const QModelIndex& ) const; };