From: asl Date: Fri, 17 Oct 2008 13:42:25 +0000 (+0000) Subject: improvements for OSCARGUI X-Git-Tag: V5_1_0a3~11 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ff433841f3bf7d5889e7ee94e929c3b2dd2c7271;p=modules%2Fgui.git improvements for OSCARGUI --- diff --git a/src/CAM/CAM_DataObject.cxx b/src/CAM/CAM_DataObject.cxx index 26ce74555..016ac84d2 100755 --- a/src/CAM/CAM_DataObject.cxx +++ b/src/CAM/CAM_DataObject.cxx @@ -128,17 +128,16 @@ QString CAM_ModuleObject::name() const /*! \brief Get data object icon for the specified column. - The parameter \a index specifies the column number - (to display, for example, in the tree view widget). + The parameter \a id specifies the column identificator - \param index column index + \param id column id \return object icon for the specified column */ -QPixmap CAM_ModuleObject::icon( const int index ) const +QPixmap CAM_ModuleObject::icon( const int id ) const { QPixmap p; // show icon only for the "Name" column - if ( index == NameIdx && dataModel() && dataModel()->module() ) + if ( id == NameId && dataModel() && dataModel()->module() ) p = dataModel()->module()->moduleIcon(); if ( !p.isNull() ) p = Qtx::scaleIcon( p, 16 ); @@ -148,13 +147,12 @@ QPixmap CAM_ModuleObject::icon( const int index ) const /*! \brief Get data object tooltip for the specified column. - The parameter \a index specifies the column number - (to display, for example, in the tree view widget). + The parameter \a id specifies the column identificator - \param index column index + \param id column id \return object tooltip for the specified column */ -QString CAM_ModuleObject::toolTip( const int /*index*/ ) const +QString CAM_ModuleObject::toolTip( const int /*id*/ ) const { // show the same tooltip for all columns QString tip; diff --git a/src/CAM/CAM_DataObject.h b/src/CAM/CAM_DataObject.h index 11bac528e..b211cefee 100755 --- a/src/CAM/CAM_DataObject.h +++ b/src/CAM/CAM_DataObject.h @@ -44,8 +44,8 @@ public: virtual ~CAM_ModuleObject(); virtual QString name() const; - QPixmap icon( const int = NameIdx ) const; - QString toolTip( const int = NameIdx ) const; + QPixmap icon( const int = NameId ) const; + QString toolTip( const int = NameId ) const; virtual CAM_DataModel* dataModel() const; virtual void setDataModel( CAM_DataModel* ); diff --git a/src/DDS/DDS_DicGroup.cxx b/src/DDS/DDS_DicGroup.cxx index 3bb337ad3..bc7dbc3ac 100644 --- a/src/DDS/DDS_DicGroup.cxx +++ b/src/DDS/DDS_DicGroup.cxx @@ -25,8 +25,6 @@ #include -#include - #include #include @@ -153,6 +151,8 @@ void DDS_DicGroup::FillDataMap( const LDOM_Element& theComponentData, const LDOM if ( !myUnitSystem.IsBound( aName ) ) myUnitSystem.Bind( aName, aLabel ); + + } } @@ -183,6 +183,16 @@ void DDS_DicGroup::FillDataMap( const LDOM_Element& theComponentData, const LDOM aDicItem->myComponent = this; aDicItem->FillDataMap( anID, aQuantity, theComponentData, theDocElement, unitSystems ); myDataMap.Add( anID, aDicItem ); + + bool exist = false; + for( int i=1, n=myKeys.Length(); i<=n && !exist; i++ ) + if( myKeys.Value( i )==anID ) + { + cout << "Doubled key:" << anID << endl; + exist = true; + } + if( !exist ) + myKeys.Append( anID ); } } @@ -203,3 +213,12 @@ Handle_DDS_DicItem DDS_DicGroup::GetDicItem( const TCollection_AsciiString& theI return aDicItem; } + +/*! + \brief Return all keys of the group + \param seq - string container to be filled with keys +*/ +void DDS_DicGroup::GetKeys( TColStd_SequenceOfAsciiString& seq ) const +{ + seq = myKeys; +} diff --git a/src/DDS/DDS_DicGroup.h b/src/DDS/DDS_DicGroup.h index a804776ea..a9bebf0f4 100644 --- a/src/DDS/DDS_DicGroup.h +++ b/src/DDS/DDS_DicGroup.h @@ -24,13 +24,10 @@ #include "DDS_DicItem.h" #include - -#include - +#include #include class LDOM_Element; -class TColStd_SequenceOfAsciiString; DEFINE_STANDARD_HANDLE(DDS_DicGroup, MMgt_TShared) @@ -40,6 +37,7 @@ public: DDS_DicGroup( const TCollection_AsciiString& ); TCollection_AsciiString GetName() const; + Standard_EXPORT void GetKeys( TColStd_SequenceOfAsciiString& ) const; Standard_EXPORT Handle(DDS_DicItem) GetDicItem( const TCollection_AsciiString& ) const; @@ -65,6 +63,7 @@ private: DDS_IndexedDataMapOfDicItems myDataMap; UnitSystemMap myUnitSystem; TCollection_AsciiString myActiveSystem; + TColStd_SequenceOfAsciiString myKeys; friend class DDS_Dictionary; diff --git a/src/DDS/DDS_DicItem.cxx b/src/DDS/DDS_DicItem.cxx index 12a942705..419946329 100644 --- a/src/DDS/DDS_DicItem.cxx +++ b/src/DDS/DDS_DicItem.cxx @@ -826,21 +826,41 @@ void DDS_DicItem::FillDataMap( TCollection_AsciiString theID, const LDOM_Element LDOM_Element anOpt = theDatum.GetChildByTagName( DDS_Dictionary::KeyWord( "OPTIONS" ) ); if ( !anOpt.isNull() ) { - LDOM_NodeList anOptions = anOpt.getElementsByTagName( DDS_Dictionary::KeyWord( "OPTION" ) ); + LDOM_NodeList anOptions = anOpt.GetAttributesList();//anOpt.getElementsByTagName( DDS_Dictionary::KeyWord( "OPTION" ) ); for ( Standard_Integer oi = 0; oi < anOptions.getLength(); oi++ ) { LDOM_Node node = anOptions.item( oi ); - if ( node.getNodeType() != LDOM_Node::ELEMENT_NODE ) - continue; - - LDOM_Element& elem = (LDOM_Element&)node; - TCollection_AsciiString name = elem.getAttribute( DDS_Dictionary::KeyWord( "OPTION_NAME" ) ); + LDOM_Node::NodeType t = node.getNodeType(); + TCollection_AsciiString name; TCollection_ExtendedString value; - const LDOM_Node aNode = elem.getFirstChild(); - LDOM_Text anOptTxt( (const LDOM_Text&)(aNode) ); - if ( !anOptTxt.isNull() ) - value = anOptTxt.getData(); + + if( t==LDOM_Node::ELEMENT_NODE ) + { + const LDOM_Element& elem = ( const LDOM_Element& )node; + name = elem.getAttribute( DDS_Dictionary::KeyWord( "OPTION_NAME" ) ); + + const LDOM_Node aNode = elem.getFirstChild(); + LDOM_Text anOptTxt( (const LDOM_Text&)(aNode) ); + if ( !anOptTxt.isNull() ) + value = anOptTxt.getData(); + } + else if( t==LDOM_Node::ATTRIBUTE_NODE ) + { + const LDOM_Attr& attr = ( const LDOM_Attr& )node; + name = ( Standard_CString )attr.getName().GetString(); + LDOMString v = attr.getValue(); + if( v.Type()==LDOMBasicString::LDOM_Integer ) + { + Standard_Integer ival; + v.GetInteger( ival ); + value = TCollection_ExtendedString( ival ); + } + else + value = ( Standard_CString )v.GetString(); + } + else + continue; if ( !name.IsEmpty() && value.Length() && !myOptions.IsBound( name ) ) myOptions.Bind( name, value ); diff --git a/src/DDS/DDS_Dictionary.cxx b/src/DDS/DDS_Dictionary.cxx index 25e6cdcb8..9baae9c7d 100644 --- a/src/DDS/DDS_Dictionary.cxx +++ b/src/DDS/DDS_Dictionary.cxx @@ -587,3 +587,18 @@ Standard_Real DDS_Dictionary::FromSI( const Standard_Real theValue, const Standa return aRetValue; } + +/*! + \brief Fill given string container \a seq with keys belonging to group with name \a theComponent + \param theComponent name of group whose keys should be stored in the container + \param seq returned string container with keys belonging to group; it is not cleared before filling +*/ +void DDS_Dictionary::GetKeys( const TCollection_AsciiString& theComponent, TColStd_SequenceOfAsciiString& seq ) const +{ + Handle( DDS_DicGroup ) aDicGroup; + if( myGroupMap.Contains( theComponent ) ) + aDicGroup = myGroupMap.FindFromKey( theComponent ); + + if( !aDicGroup.IsNull() ) + aDicGroup->GetKeys( seq ); +} diff --git a/src/DDS/DDS_Dictionary.h b/src/DDS/DDS_Dictionary.h index 9a5d5a886..2a264b482 100644 --- a/src/DDS/DDS_Dictionary.h +++ b/src/DDS/DDS_Dictionary.h @@ -37,6 +37,8 @@ public: // Return instance of data dictionary. Create instance if it is NULL. + Standard_EXPORT void GetKeys( const TCollection_AsciiString&, TColStd_SequenceOfAsciiString& ) const; + Standard_EXPORT Handle(DDS_DicItem) GetDicItem( const TCollection_AsciiString& ) const; Standard_EXPORT Handle(DDS_DicItem) GetDicItem( const TCollection_AsciiString&, const TCollection_AsciiString& ) const; diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index e69128175..4818feb39 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -1282,10 +1282,11 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType { viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() ); OCCViewer_Viewer* vm; + bool staticTrihedron = resMgr->booleanValue( "OCCViewer", "static_trihedron", true ); #ifndef DISABLE_SALOMEOBJECT vm = new SOCC_Viewer(); #else - vm = new OCCViewer_Viewer(); + vm = new OCCViewer_Viewer( true, staticTrihedron ); #endif vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) ); vm->setTrihedronSize( resMgr->doubleValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) ); diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index 2f929ae94..305246b40 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -141,6 +141,8 @@ public: virtual bool checkDataObject( LightApp_DataObject* theObj ); + virtual void updateDesktopTitle(); + signals: void studyOpened(); void studySaved(); @@ -182,8 +184,6 @@ protected: virtual void loadPreferences(); virtual void savePreferences(); - virtual void updateDesktopTitle(); - virtual QMap activateModuleActions() const; virtual void moduleActionSelected( const int ); diff --git a/src/LightApp/LightApp_DataModel.cxx b/src/LightApp/LightApp_DataModel.cxx index d78f3b3c1..5074d475f 100644 --- a/src/LightApp/LightApp_DataModel.cxx +++ b/src/LightApp/LightApp_DataModel.cxx @@ -27,6 +27,7 @@ #include "LightApp_Module.h" #include "LightApp_Application.h" +#include #include #include @@ -36,6 +37,9 @@ LightApp_DataModel::LightApp_DataModel( CAM_Module* theModule ) : CAM_DataModel( theModule ) { + myGroupId = 0; + if( module() ) + myGroupId = qHash( module()->name() ); } /*! @@ -169,3 +173,36 @@ bool LightApp_DataModel::isSaved() const { return true; } + +/*! + \return data model group id used for custom columns creation +*/ +int LightApp_DataModel::groupId() const +{ + return myGroupId; +} + +/*! + Register custom column in the object browser + \param browser - object browser where new column should be created + \param name - translated column name + \param custom_id - custom column identificator passed into data object's methods text(), icon() etc +*/ +void LightApp_DataModel::registerColumn( SUIT_DataBrowser* browser, const QString& name, const int custom_id ) +{ + SUIT_AbstractModel* m = dynamic_cast( browser ? browser->model() : 0 ); + if( m ) + m->registerColumn( groupId(), name, custom_id ); +} + +/*! + Remove registered custom column from the object browser + \param browser - object browser where new column should be created + \param name - translated column name +*/ +void LightApp_DataModel::unregisterColumn( SUIT_DataBrowser* browser, const QString& name ) +{ + SUIT_AbstractModel* m = dynamic_cast( browser ? browser->model() : 0 ); + if( m ) + m->unregisterColumn( groupId(), name ); +} diff --git a/src/LightApp/LightApp_DataModel.h b/src/LightApp/LightApp_DataModel.h index c2eb2d6e7..838270010 100644 --- a/src/LightApp/LightApp_DataModel.h +++ b/src/LightApp/LightApp_DataModel.h @@ -34,6 +34,7 @@ class LightApp_Module; class LightApp_Study; class LightApp_DataObject; +class SUIT_DataBrowser; /*! Description : Base class of data model @@ -58,6 +59,10 @@ public: LightApp_Module* getModule() const; + int groupId() const; + void registerColumn( SUIT_DataBrowser*, const QString&, const int ); + void unregisterColumn( SUIT_DataBrowser*, const QString& ); + signals: void opened(); void saved(); @@ -67,6 +72,9 @@ protected: LightApp_Study* getStudy() const; virtual void build(); virtual void updateWidgets(); + +private: + int myGroupId; }; #endif diff --git a/src/LightApp/LightApp_DataObject.cxx b/src/LightApp/LightApp_DataObject.cxx index 1f746533d..b0d858896 100644 --- a/src/LightApp/LightApp_DataObject.cxx +++ b/src/LightApp/LightApp_DataObject.cxx @@ -22,8 +22,8 @@ #include "LightApp_DataObject.h" #include "LightApp_Study.h" +#include "LightApp_DataModel.h" -#include #include #include @@ -115,38 +115,10 @@ LightApp_DataObject::~LightApp_DataObject() { } -/*! - \brief Get the number of the columns provided by the data tree. - \return number of the columns -*/ -int LightApp_DataObject::columnCount() const -{ - // add "Entry" column - return CAM_DataObject::columnCount() + 1; -} - -/*! - \brief Get column title. - \param index column index - \return title of the specified column -*/ -QString LightApp_DataObject::columnTitle( const int index ) const -{ - // add "Entry" column - return index == EntryIdx ? QObject::tr( "ENTRY_COLUMN" ) - : CAM_DataObject::columnTitle( index ); -} - -/*! - \brief Check if the column should appear in the tree view header popup menu - (to show/hide the column). - \param index column index - \return \c true if the column can be shown/hidden -*/ -bool LightApp_DataObject::appropriate( const int index ) const +int LightApp_DataObject::groupId() const { - // add "Entry" column - return index == EntryIdx ? true : CAM_DataObject::appropriate( index ); + LightApp_DataModel* m = dynamic_cast( dataModel() ); + return m ? m->groupId() : CAM_DataObject::groupId(); } /*! @@ -175,18 +147,17 @@ SUIT_DataObjectKey* LightApp_DataObject::key() const /*! \brief Get object text data for the specified column. - Column with \a index = 0 (NameIdx) is supposed to be used + Column with \a id = 0 (NameId) is supposed to be used to get the object name. - Column with \a index = 1 (EntryIdx) is supposed to be used + Column with \a id = 1 (EntryId) is supposed to be used to get the object entry. - \param index column index + \param id column id \return object text data */ -QString LightApp_DataObject::text( const int index ) const +QString LightApp_DataObject::text( const int id ) const { - // add "Entry" column - return index == EntryIdx ? entry() : CAM_DataObject::text( index ); + return id == EntryId ? entry() : CAM_DataObject::text( id ); } /*! @@ -229,15 +200,14 @@ QString LightApp_DataObject::componentDataType() const /*! \brief Check if the specified column supports custom sorting. - \param index column index + \param id column id \return \c true if column sorting should be customized \sa compare() */ -bool LightApp_DataObject::customSorting( const int index ) const +bool LightApp_DataObject::customSorting( const int id ) const { // perform custom sorting for the "Entry" column - return index == EntryIdx ? true - : CAM_DataObject::customSorting( index ); + return id == EntryId ? true : CAM_DataObject::customSorting( id ); } /*! @@ -248,14 +218,14 @@ bool LightApp_DataObject::customSorting( const int index ) const \param left first data to compare \param right second data to compare - \param index column index + \param id column id \return result of the comparison \sa customSorting() */ -bool LightApp_DataObject::compare( const QVariant& left, const QVariant& right, - const int index ) const +bool LightApp_DataObject::compare( const QVariant& left, const QVariant& right, const int id ) const { - if ( index == EntryIdx ) { + if ( id == EntryId ) + { // perform custom sorting for the "Entry" column QString leftStr = left.toString(); QString rightStr = right.toString(); @@ -293,7 +263,7 @@ bool LightApp_DataObject::compare( const QVariant& left, const QVariant& right, } return QString::localeAwareCompare( leftStr, rightStr ) < 0; } - return CAM_DataObject::compare( left, right, index ); + return CAM_DataObject::compare( left, right, id ); } /*! @@ -343,22 +313,22 @@ QString LightApp_ModuleObject::name() const /*! \brief Get data object icon for the specified column. - \param index column index + \param id column id \return object icon for the specified column */ -QPixmap LightApp_ModuleObject::icon( const int index ) const +QPixmap LightApp_ModuleObject::icon( const int id ) const { - return CAM_ModuleObject::icon( index ); + return CAM_ModuleObject::icon( id ); } /*! \brief Get data object tooltip for the specified column. - \param index column index + \param id column id \return object tooltip for the specified column */ -QString LightApp_ModuleObject::toolTip( const int index ) const +QString LightApp_ModuleObject::toolTip( const int id ) const { - return CAM_ModuleObject::toolTip( index ); + return CAM_ModuleObject::toolTip( id ); } /*! diff --git a/src/LightApp/LightApp_DataObject.h b/src/LightApp/LightApp_DataObject.h index 77f3b7861..fe4f7cb40 100644 --- a/src/LightApp/LightApp_DataObject.h +++ b/src/LightApp/LightApp_DataObject.h @@ -34,30 +34,26 @@ class LIGHTAPP_EXPORT LightApp_DataObject : public virtual CAM_DataObject class Key; public: - //! Column index + //! Column id enum { - EntryIdx = NameIdx + 1 //!< entry column + EntryId = NameId + 1 //!< entry column }; public: LightApp_DataObject( SUIT_DataObject* = 0 ); virtual ~LightApp_DataObject(); - virtual int columnCount() const; - virtual QString columnTitle( const int = NameIdx ) const; - virtual bool appropriate( const int = NameIdx ) const; - virtual SUIT_DataObjectKey* key() const; virtual QString entry() const; - virtual QString text( const int = NameIdx ) const; + virtual QString text( const int = NameId ) const; virtual SUIT_DataObject* componentObject() const; virtual QString componentDataType() const; - virtual bool customSorting( const int = NameIdx ) const; - virtual bool compare( const QVariant&, const QVariant&, - const int = NameIdx ) const; + virtual bool customSorting( const int = NameId ) const; + virtual bool compare( const QVariant&, const QVariant&, const int = NameId ) const; + virtual int groupId() const; protected: QString myCompDataType; @@ -74,8 +70,8 @@ public: virtual ~LightApp_ModuleObject(); virtual QString name() const; - QPixmap icon( const int = NameIdx ) const; - QString toolTip( const int = NameIdx ) const; + QPixmap icon( const int = NameId ) const; + QString toolTip( const int = NameId ) const; virtual void insertChild( SUIT_DataObject*, int ); }; diff --git a/src/LightApp/LightApp_Module.cxx b/src/LightApp/LightApp_Module.cxx index f2e42984d..12a94b34a 100644 --- a/src/LightApp/LightApp_Module.cxx +++ b/src/LightApp/LightApp_Module.cxx @@ -37,16 +37,19 @@ #include "LightApp_ShowHideOp.h" #include "LightApp_SelectionMgr.h" -#include #include #include +#include #include #include #include #include +#include +#ifndef DISABLE_SALOMEOBJECT #include #include +#endif #ifndef DISABLE_VTKVIEWER #ifndef DISABLE_SALOMEOBJECT @@ -86,6 +89,7 @@ #include #include + /*!Constructor.*/ LightApp_Module::LightApp_Module( const QString& name ) : CAM_Module( name ), @@ -173,6 +177,7 @@ bool LightApp_Module::isSelectionCompatible() { // return true if selected objects belong to this module bool isCompatible = true; +#ifndef DISABLE_SALOMEOBJECT SALOME_ListIO selected; if ( LightApp_SelectionMgr *Sel = getApp()->selectionMgr() ) Sel->selectedObjects( selected ); @@ -189,6 +194,7 @@ bool LightApp_Module::isSelectionCompatible() isCompatible = ( aStudy->componentDataType( io->getEntry() ) == moduleDataType ); } } +#endif return isCompatible; } @@ -211,6 +217,14 @@ bool LightApp_Module::activateModule( SUIT_Study* study ) if ( mySwitchOp == 0 ) mySwitchOp = new LightApp_SwitchOp( this ); + QString EntryCol = QObject::tr( "ENTRY_COLUMN" ); + LightApp_DataModel* m = dynamic_cast( dataModel() ); + if( m ) + { + SUIT_AbstractModel* treeModel = dynamic_cast( getApp()->objectBrowser()->model() ); + m->registerColumn( getApp()->objectBrowser(), EntryCol, LightApp_DataObject::EntryId ); + treeModel->setAppropriate( EntryCol, Qtx::Toggled ); + } return res; } @@ -231,7 +245,16 @@ bool LightApp_Module::deactivateModule( SUIT_Study* study ) anIt.value()->abort(); } - return CAM_Module::activateModule( study ); + QString EntryCol = QObject::tr( "ENTRY_COLUMN" ); + LightApp_DataModel* m = dynamic_cast( dataModel() ); + if( m ) + { + SUIT_AbstractModel* treeModel = dynamic_cast( getApp()->objectBrowser()->model() ); + + treeModel->setAppropriate( EntryCol, Qtx::Shown ); + m->unregisterColumn( getApp()->objectBrowser(), EntryCol ); + } + return CAM_Module::deactivateModule( study ); } /*!NOT IMPLEMENTED*/ @@ -319,7 +342,7 @@ void LightApp_Module::updateControls() /*!Create new instance of data model and return it.*/ CAM_DataModel* LightApp_Module::createDataModel() { - return new LightApp_DataModel(this); + return new LightApp_DataModel( this ); } /*!Create and return instance of LightApp_Selection.*/ @@ -600,3 +623,14 @@ void LightApp_Module::onViewManagerAdded( SUIT_ViewManager* ) void LightApp_Module::onViewManagerRemoved( SUIT_ViewManager* ) { } + +/*! + \brief Returns instance of operation by its id; if there is no operation + corresponding to this id, null pointer is returned + \param id - operation id + \return operation instance +*/ +LightApp_Operation* LightApp_Module::operation( const int id ) const +{ + return myOperations.contains( id ) ? myOperations[id] : 0; +} diff --git a/src/LightApp/LightApp_Module.h b/src/LightApp/LightApp_Module.h index 08c8eb7d3..d32fb1eb8 100644 --- a/src/LightApp/LightApp_Module.h +++ b/src/LightApp/LightApp_Module.h @@ -134,6 +134,8 @@ protected: virtual bool isSelectionCompatible(); + LightApp_Operation* operation( const int ) const; + private: typedef QMap MapOfOperation; diff --git a/src/OCCViewer/Makefile.am b/src/OCCViewer/Makefile.am index 0f0e24c01..069463643 100755 --- a/src/OCCViewer/Makefile.am +++ b/src/OCCViewer/Makefile.am @@ -55,7 +55,8 @@ dist_libOCCViewer_la_SOURCES = \ OCCViewer_SetRotationPointDlg.cxx \ OCCViewer_ClippingDlg.cxx \ OCCViewer_AxialScaleDlg.cxx \ - OCCViewer_Trihedron.cxx + OCCViewer_Trihedron.cxx \ + OCCViewer_ToolTip.cxx MOC_FILES = \ OCCViewer_AISSelector_moc.cxx \ @@ -68,7 +69,9 @@ MOC_FILES = \ OCCViewer_CreateRestoreViewDlg_moc.cxx \ OCCViewer_SetRotationPointDlg_moc.cxx \ OCCViewer_ClippingDlg_moc.cxx \ - OCCViewer_AxialScaleDlg_moc.cxx + OCCViewer_AxialScaleDlg_moc.cxx \ + OCCViewer_ToolTip_moc.cxx + nodist_libOCCViewer_la_SOURCES = $(MOC_FILES) dist_salomeres_DATA = \ diff --git a/src/OCCViewer/OCCViewer_ToolTip.cxx b/src/OCCViewer/OCCViewer_ToolTip.cxx new file mode 100644 index 000000000..536acdc22 --- /dev/null +++ b/src/OCCViewer/OCCViewer_ToolTip.cxx @@ -0,0 +1,103 @@ +// 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: OCCViewer_ToolTip.cxx +// Author: Alexandre SOLOVYOV + +#include +#include +#include +#include + +#include + +#include + +/*! + Constructor + + \param wnd - window where the tooltip should be assigned +*/ +OCCViewer_ToolTip::OCCViewer_ToolTip( OCCViewer_ViewWindow* wnd ) +: QtxToolTip( wnd->getViewPort() ), + myWnd( wnd ) +{ + connect( this, SIGNAL( maybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ), + this, SLOT( onToolTip( QPoint, QString&, QFont&, QRect&, QRect& ) ) ); +} + +/*! + Destructor + */ +OCCViewer_ToolTip::~OCCViewer_ToolTip() +{ +} + +/*! + \return font of the tooltip + */ +QFont OCCViewer_ToolTip::font() const +{ + return myFont; +} + +/*! + Change font of the tooltip + + \param f - new font + */ +void OCCViewer_ToolTip::setFont( const QFont& f ) +{ + myFont = f; +} + +/*! + Tooltip handler + + \param p - current point + \param str - returned tooltip text + \param f - returned tooltip font + \param txtRect - returned tooltip text rectangle + \param rect - returned tooltip rectangle + */ +void OCCViewer_ToolTip::onToolTip( QPoint p, QString& str, QFont& f, QRect& txtRect, QRect& rect ) +{ + OCCViewer_Viewer* v = dynamic_cast( myWnd->getViewManager()->getViewModel() ); + Handle( AIS_InteractiveContext ) aCont = v->getAISContext(); + if( aCont.IsNull() ) + return; + + QString txt; + Handle( SelectMgr_EntityOwner ) owner = aCont->DetectedOwner(); + if( !owner.IsNull() ) + emit toolTipFor( owner, txt ); + + Handle_AIS_InteractiveObject obj = aCont->DetectedInteractive(); + if( txt.isEmpty() && !obj.IsNull() ) + emit toolTipFor( obj, txt ); + + if( txt.isEmpty() ) + return; + + str = txt; + QFontMetrics m( myFont ); + int w = m.width( str ), h = m.height(); + + txtRect = QRect( p.x()+4, p.y()-h, w, h ); + rect = txtRect; +} diff --git a/src/OCCViewer/OCCViewer_ToolTip.h b/src/OCCViewer/OCCViewer_ToolTip.h new file mode 100644 index 000000000..42ff7fed9 --- /dev/null +++ b/src/OCCViewer/OCCViewer_ToolTip.h @@ -0,0 +1,63 @@ +// 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 +// +#ifndef OCCVIEWER_TOOLTIP_H +#define OCCVIEWER_TOOLTIP_H + +#include +#include +#include + +class OCCViewer_ViewWindow; +class Handle_SelectMgr_EntityOwner; +class Handle_AIS_InteractiveObject; + +/*! + \class OCCViewer_ToolTip + \brief Custom tooltip for AIS_InteractiveObjects and SelectMgr_EntityOwners in the OCC Viewer +*/ +class OCCVIEWER_EXPORT OCCViewer_ToolTip : public QtxToolTip +{ + Q_OBJECT + +public: + OCCViewer_ToolTip( OCCViewer_ViewWindow* ); + virtual ~OCCViewer_ToolTip(); + + QFont font() const; + void setFont( const QFont& ); + +signals: + /*! + Called when owner is detected; allows to redefine tooltip text for owner + */ + void toolTipFor( const Handle_SelectMgr_EntityOwner&, QString& ); + /*! + Called when object is detected; allows to redefine tooltip text for object + */ + void toolTipFor( const Handle_AIS_InteractiveObject&, QString& ); + +public slots: + void onToolTip( QPoint, QString&, QFont&, QRect&, QRect& ); + +private: + OCCViewer_ViewWindow* myWnd; + QFont myFont; +}; + +#endif diff --git a/src/OCCViewer/OCCViewer_ViewManager.cxx b/src/OCCViewer/OCCViewer_ViewManager.cxx index 39c740c5d..8bb6aad76 100755 --- a/src/OCCViewer/OCCViewer_ViewManager.cxx +++ b/src/OCCViewer/OCCViewer_ViewManager.cxx @@ -24,7 +24,7 @@ Constructor */ OCCViewer_ViewManager::OCCViewer_ViewManager( SUIT_Study* study, SUIT_Desktop* theDesktop, bool DisplayTrihedron ) -: SUIT_ViewManager( study, theDesktop, new OCCViewer_Viewer( DisplayTrihedron ) ) +: SUIT_ViewManager( study, theDesktop, new OCCViewer_Viewer( DisplayTrihedron, false ) ) { setTitle( tr( "OCC_VIEW_TITLE" ) ); } diff --git a/src/QDS/QDS_ComboBox.cxx b/src/QDS/QDS_ComboBox.cxx index f7131aada..2d5fd05eb 100644 --- a/src/QDS/QDS_ComboBox.cxx +++ b/src/QDS/QDS_ComboBox.cxx @@ -335,12 +335,9 @@ void QDS_ComboBox::reset() int id = -1; QString aDefValue = defaultValue(); if ( !aDefValue.isEmpty() ) - id = aDefValue.toInt(); - - if ( id == -1 ) - id = getId( 0 ); - - setIntegerValue( id ); + setString( aDefValue ); + else + setIntegerValue( getId( 0 ) ); } /*! @@ -599,9 +596,9 @@ void QDS_ComboBox::updateComboBox() if ( cb ) { if ( myIcons.contains( id ) ) - cb->insertItem( -1, QIcon(myIcons[id]), myValue[id] ); + cb->addItem( QIcon(myIcons[id]), myValue[id] ); else - cb->insertItem( -1, myValue[id] ); + cb->addItem( myValue[id] ); } } diff --git a/src/QDS/QDS_Datum.cxx b/src/QDS/QDS_Datum.cxx index 81e944e91..b3780f699 100644 --- a/src/QDS/QDS_Datum.cxx +++ b/src/QDS/QDS_Datum.cxx @@ -18,20 +18,15 @@ // #include "QDS_Datum.h" -#include "QDS_Validator.h" - -#include - +#include +#include #include -#include -#include -#include -#include -#include -#include #include +#include +#include -#include +#include +#include /*! \class QDS_Datum::Wrapper @@ -45,15 +40,14 @@ public: Wrapper( QWidget* = 0 ); virtual ~Wrapper(); - QWidget* widget() const; - void setWidget( QWidget* ); + QWidget* widget() const; + void setWidget( QWidget* ); virtual void setGeometry( int x, int y, int w, int h ); virtual void setSizePolicy( QSizePolicy ); private: - QWidget* myWid; - QHBoxLayout* myBase; + QWidget* myWid; }; /*! @@ -64,9 +58,9 @@ QDS_Datum::Wrapper::Wrapper( QWidget* parent ) : QWidget( parent ), myWid( 0 ) { - //QHBoxLayout* base = new QHBoxLayout( this ); - //base->setAutoAdd( true ); - myBase = new QHBoxLayout( this ); + setLayout( new QHBoxLayout() ); + layout()->setSpacing( 0 ); + layout()->setMargin( 0 ); setFocusPolicy( Qt::StrongFocus ); } @@ -92,21 +86,16 @@ QWidget* QDS_Datum::Wrapper::widget() const */ void QDS_Datum::Wrapper::setWidget( QWidget* wid ) { - if ( myWid == wid ) + if ( myWid == wid || !wid ) return; + wid->setParent( this ); + QHBoxLayout* hl = qobject_cast( layout() ); + if( myWid ) + hl->removeWidget( myWid ); + hl->addWidget( wid ); myWid = wid; - if ( !myWid ) - return; - - if ( myWid->parent() != this ) { - myWid->setParent( this ); - myWid->move( QPoint( 0, 0 ) ); - myWid->hide(); - myBase->addWidget( myWid ); - } - setTabOrder( this, myWid ); setFocusProxy( myWid ); @@ -211,7 +200,8 @@ QDS_Datum::QDS_Datum( const QString& id, QWidget* parent, const int flags, const myUnits( 0 ), myControl( 0 ), myFlags( flags ), - myInitialised( false ) + myInitialised( false ), + myTr( false ) { if ( myFlags & Label ) myWrapper.insert( Label, new Wrapper( parent ) ); @@ -296,6 +286,44 @@ int QDS_Datum::type() const return res; } +/*! + \brief Return state of custom translation. + \return true if custom translation is enabled +*/ +bool QDS_Datum::isCustomTr() const +{ + return myTr; +} + +/*! + \brief Change state of custom translation. + + Custom translation means that text labels of datums are translated + with help of standard Qt mechanism of internationalization. In this + case special records should be placed into *.ts files under context "QDS". + For example, if label has name "myLabel", the corresponding translation + should be written: + + QDS + + myLabel + myLabel translation + + ... + + If custom translation mechanism is deactivated, then labels will be shown + with text got from xml data dictionary file + + By default, the custom translation is deactivated + + \param on - if it is true, custom translation is activated, otherwise, deactivated +*/ +void QDS_Datum::enableCustomTr( const bool on ) +{ + myTr = on; + labelWidget()->setText( label() ); +} + /*! \brief Get the datum label text. \return label text @@ -306,11 +334,19 @@ QString QDS_Datum::label() const QString labStr; if ( !myDicItem.IsNull() ) + { labStr = toQString( myDicItem->GetLabel() ); - + if( labStr.isNull() ) + labStr = toQString( myDicItem->GetId() ); + } + if( myTr ) + { + QString dest = QApplication::translate( "QDS", labStr.toLatin1().constData() ); + if( labStr != dest ) + labStr = dest; + } if ( flags() & NotAccel ) labStr = removeAccel( labStr ); - return labStr; } @@ -942,7 +978,7 @@ bool QDS_Datum::isValid( const bool msgBox, const QString& extMsg, const QString info += QString( "\n" ) + extMsg; QString msg; - for ( uint i = 0; i < info.length(); i++ ) + for ( int i = 0; i < info.length(); i++ ) if ( info.at( i ) == '\n' ) msg += QString( "
" ); else diff --git a/src/QDS/QDS_Datum.h b/src/QDS/QDS_Datum.h index c42e92241..920371d56 100644 --- a/src/QDS/QDS_Datum.h +++ b/src/QDS/QDS_Datum.h @@ -20,19 +20,18 @@ #define QDS_DATUM_H #include "QDS.h" - -#include -#include #include +#include +#include + +class QHBoxLayout; +class QVBoxLayout; +class QGridLayout; +class QValidator; #include -class QLabel; class QWidget; -class QValidator; -class QVBoxLayout; -class QHBoxLayout; -class QGridLayout; class QDS_EXPORT QDS_Datum : public QObject, public QDS { @@ -115,6 +114,9 @@ public: operator QWidget*() const; + bool isCustomTr() const; + void enableCustomTr( const bool ); + signals: void paramChanged(); void paramChanged( QString& ); @@ -196,7 +198,7 @@ private: QString mySourceValue; QString myTargetValue; - bool myInitialised; + bool myInitialised, myTr; friend class QDS; }; diff --git a/src/QDS/QDS_SpinBox.cxx b/src/QDS/QDS_SpinBox.cxx index e3966a1c5..82ebbbb0d 100644 --- a/src/QDS/QDS_SpinBox.cxx +++ b/src/QDS/QDS_SpinBox.cxx @@ -170,7 +170,8 @@ void QDS_SpinBox::unitSystemChanged( const QString& system ) sb->setSuffix( suffix() ); sb->setPrefix( prefix() ); - sb->setMinimum( minValue().toInt() ); - sb->setMaximum( maxValue().toInt() ); + sb->setMinimum( minValue().isEmpty() ? -INT_MAX : minValue().toInt() ); + sb->setMaximum( maxValue().isEmpty() ? INT_MAX : maxValue().toInt() ); + } } diff --git a/src/Qtx/Makefile.am b/src/Qtx/Makefile.am index 99d868f2a..1c8b6eac9 100755 --- a/src/Qtx/Makefile.am +++ b/src/Qtx/Makefile.am @@ -165,6 +165,7 @@ MOC_FILES = \ QtxPathEdit_moc.cxx \ QtxPathListEdit_moc.cxx \ QtxPopupMgr_moc.cxx \ + QtxRubberBand_moc.cxx \ QtxSearchTool_moc.cxx \ QtxSplash_moc.cxx \ QtxToolBar_moc.cxx \ diff --git a/src/Qtx/Qtx.h b/src/Qtx/Qtx.h index 49ab74cae..466127033 100755 --- a/src/Qtx/Qtx.h +++ b/src/Qtx/Qtx.h @@ -96,6 +96,12 @@ public: AppropriateRole = Qt::UserRole + 100 //!< can be used to return \c true if data is appropriate }; + typedef enum { + Shown, //!< column should be always visible + Hidden, //!< column should be always hidden + Toggled //!< it should be possible to show/hide the column with help of popup menu + } Appropriate; //!< appropriate status + static QString toQString( const char*, const int = -1 ); static QString toQString( const short*, const int = -1 ); static QString toQString( const unsigned char*, const int = -1 ); diff --git a/src/Qtx/QtxRubberBand.h b/src/Qtx/QtxRubberBand.h index e16426167..7e88d6445 100755 --- a/src/Qtx/QtxRubberBand.h +++ b/src/Qtx/QtxRubberBand.h @@ -27,8 +27,10 @@ #include -class QTX_EXPORT QtxAbstractRubberBand: public QWidget +class QTX_EXPORT QtxAbstractRubberBand : public QWidget { + Q_OBJECT + protected: QtxAbstractRubberBand( QWidget* ); @@ -57,8 +59,9 @@ protected: class QTX_EXPORT QtxRectRubberBand: public QtxAbstractRubberBand { -public: + Q_OBJECT +public: QtxRectRubberBand( QWidget* ); virtual ~QtxRectRubberBand(); @@ -71,8 +74,9 @@ public: class QTX_EXPORT QtxPolyRubberBand: public QtxAbstractRubberBand { -public: + Q_OBJECT +public: QtxPolyRubberBand( QWidget* ); virtual ~QtxPolyRubberBand(); diff --git a/src/Qtx/QtxTreeView.cxx b/src/Qtx/QtxTreeView.cxx index 6cf3ca533..ea2e520d2 100644 --- a/src/Qtx/QtxTreeView.cxx +++ b/src/Qtx/QtxTreeView.cxx @@ -112,8 +112,9 @@ void QtxTreeView::Header::contextMenuEvent( QContextMenuEvent* e ) else if ( qVariantCanConvert( iconData ) ) icon = qVariantValue( iconData ); } - if ( ( !lab.isEmpty() || !icon.isNull() ) && - appropriate.isValid() ? appropriate.toBool() : true ) { + if( ( !lab.isEmpty() || !icon.isNull() ) && + appropriate.isValid() ? appropriate.toInt()==Qtx::Toggled : true ) + { QAction* a = menu.addAction( icon, lab ); a->setCheckable( true ); a->setChecked( !isSectionHidden( i ) ); @@ -153,6 +154,7 @@ void QtxTreeView::Header::contextMenuEvent( QContextMenuEvent* e ) e->accept(); } + /*! \class QtxTreeView \brief Tree view class with possibility to display columns popup menu. @@ -371,3 +373,23 @@ void QtxTreeView::emitSortingEnabled( bool enabled ) { emit( sortingEnabled( enabled ) ); } + +void QtxTreeView::setModel( QAbstractItemModel* m ) +{ + if( model() ) + disconnect( model(), SIGNAL( headerDataChanged( Qt::Orientation, int, int ) ), + this, SLOT( onAppropriate( Qt::Orientation, int, int ) ) ); + QTreeView::setModel( m ); + connect( model(), SIGNAL( headerDataChanged( Qt::Orientation, int, int ) ), + this, SLOT( onAppropriate( Qt::Orientation, int, int ) ) ); +} + +void QtxTreeView::onAppropriate( Qt::Orientation orient, int first, int last ) +{ + if( orient==Qt::Horizontal ) + for( int i=first; i<=last; i++ ) + { + int appr = model()->headerData( i, orient, Qtx::AppropriateRole ).toInt(); + header()->setSectionHidden( i, appr==Qtx::Hidden ); + } +} diff --git a/src/Qtx/QtxTreeView.h b/src/Qtx/QtxTreeView.h index f02eaf65c..e8e7b090c 100644 --- a/src/Qtx/QtxTreeView.h +++ b/src/Qtx/QtxTreeView.h @@ -53,10 +53,13 @@ public: void resizeColumnToEncloseContents( int ); + virtual void setModel( QAbstractItemModel* ); + protected slots: void onHeaderClicked( int ); void rowsAboutToBeRemoved( const QModelIndex&, int, int ); void selectionChanged( const QItemSelection&, const QItemSelection& ); + void onAppropriate( Qt::Orientation, int, int ); protected: void setOpened( const QModelIndex&, const int, bool ); diff --git a/src/STD/STD_Application.h b/src/STD/STD_Application.h index 77f2ed646..96e295240 100755 --- a/src/STD/STD_Application.h +++ b/src/STD/STD_Application.h @@ -49,9 +49,12 @@ class STD_EXPORT STD_Application : public SUIT_Application Q_OBJECT public: - enum { FileNewId, FileOpenId, FileCloseId, FileSaveId, FileSaveAsId, FileExitId, - ViewWindowsId, ViewToolBarsId, ViewStatusBarId, NewWindowId, - EditCutId, EditCopyId, EditPasteId, HelpAboutId, UserID }; + enum { MenuFileId, FileNewId, FileOpenId, FileCloseId, FileSaveId, FileSaveAsId, FileExitId, + MenuViewId, ViewWindowsId, ViewToolBarsId, ViewStatusBarId, NewWindowId, + MenuEditId, EditCutId, EditCopyId, EditPasteId, + MenuHelpId, HelpAboutId, + UserID + }; public: STD_Application(); @@ -94,6 +97,8 @@ public: bool exitConfirmation() const; void setExitConfirmation( const bool ); + virtual void updateDesktopTitle(); + signals: /*!emit that view manager added*/ void viewManagerAdded( SUIT_ViewManager* ); @@ -129,18 +134,11 @@ private slots: virtual void onViewManagerActivated( SUIT_ViewManager* ); protected: - enum { MenuFileId = 1, - MenuViewId = 2, - MenuEditId = 3, - MenuHelpId = 7 - }; - enum { OpenCancel, OpenNew, OpenExist }; enum { CloseCancel, CloseSave, CloseDiscard }; protected: virtual void createActions(); - virtual void updateDesktopTitle(); virtual void updateCommandsStatus(); virtual void setDesktop( SUIT_Desktop* ); diff --git a/src/SUIT/SUIT_Application.cxx b/src/SUIT/SUIT_Application.cxx index ead59e4c4..35c44b80e 100755 --- a/src/SUIT/SUIT_Application.cxx +++ b/src/SUIT/SUIT_Application.cxx @@ -639,10 +639,10 @@ int SUIT_Application::registerAction( const int id, QAction* a ) myActionMap.insert( ident, a ); if ( desktop() && desktop()->menuMgr() ) - desktop()->menuMgr()->registerAction( a ); + desktop()->menuMgr()->registerAction( a, id ); if ( desktop() && desktop()->toolMgr() ) - desktop()->toolMgr()->registerAction( a ); + desktop()->toolMgr()->registerAction( a, id ); return ident; } diff --git a/src/SUIT/SUIT_DataBrowser.cxx b/src/SUIT/SUIT_DataBrowser.cxx index 1444ab357..e9ee49087 100644 --- a/src/SUIT/SUIT_DataBrowser.cxx +++ b/src/SUIT/SUIT_DataBrowser.cxx @@ -308,6 +308,8 @@ void SUIT_DataBrowser::init( SUIT_DataObject* root ) setItemDelegate( qobject_cast( model() )->delegate() ); connect( treeView(), SIGNAL( sortingEnabled( bool ) ), model(), SLOT( setSortingEnabled( bool ) ) ); + connect( treeView(), SIGNAL( clicked( const QModelIndex& ) ), + this, SLOT( onClicked( const QModelIndex& ) ) ); connect( treeView(), SIGNAL( doubleClicked( const QModelIndex& ) ), this, SLOT( onDblClicked( const QModelIndex& ) ) ); connect( treeView(), SIGNAL( expanded( const QModelIndex& ) ), @@ -330,6 +332,16 @@ void SUIT_DataBrowser::init( SUIT_DataObject* root ) \sa updateKey(), setUpdateKey() */ +/*! + \fn void SUIT_DataBrowser::clicked( SUIT_DataObject* o ); + \brief This signal is emitted when a mouse button is clicked. + + The data object the mouse was clicked on is specified by \a o. + The signal is only emitted when the object is valid. + + \param o data object which is clicked +*/ + /*! \fn void SUIT_DataBrowser::doubleClicked( SUIT_DataObject* o ); \brief This signal is emitted when a mouse button is double-clicked. @@ -348,6 +360,22 @@ void SUIT_DataBrowser::onModelUpdated() setModified(); } +/*! + \brief Called when item is clicked in the tree view + \internal + + Emits signal clicked( SUIT_DataObject* ); +*/ +void SUIT_DataBrowser::onClicked( const QModelIndex& index ) +{ + SUIT_ProxyModel* m = qobject_cast( model() ); + + if ( m ) { + SUIT_DataObject* obj = m->object( index ); + if ( obj ) emit( clicked( obj ) ); + } +} + /*! \brief Called when item is double-clicked in the tree view \internal diff --git a/src/SUIT/SUIT_DataBrowser.h b/src/SUIT/SUIT_DataBrowser.h index 9ab076bb3..77d423f1d 100644 --- a/src/SUIT/SUIT_DataBrowser.h +++ b/src/SUIT/SUIT_DataBrowser.h @@ -72,10 +72,12 @@ private: signals: void requestUpdate(); + void clicked( SUIT_DataObject* ); void doubleClicked( SUIT_DataObject* ); private slots: void onModelUpdated(); + void onClicked( const QModelIndex& ); void onDblClicked( const QModelIndex& ); void onExpanded( const QModelIndex& ); diff --git a/src/SUIT/SUIT_DataObject.cxx b/src/SUIT/SUIT_DataObject.cxx index 26c27a429..98b323b3a 100755 --- a/src/SUIT/SUIT_DataObject.cxx +++ b/src/SUIT/SUIT_DataObject.cxx @@ -112,64 +112,6 @@ SUIT_DataObject* SUIT_DataObject::lastChild() const return child; } -/*! - \brief Get the number of the columns provided by the data tree. - - This method can be re-implemented in the subclasses. - Default implementation returns 1 ("Name" column) only. - - \return number of the columns -*/ -int SUIT_DataObject::columnCount() const -{ - return 1; // one column ("Name") is provided by default -} - -/*! - \brief Get column title. - - This method can be re-implemented in the subclasses. - Default implementation returns the title for the first column ("Name") only. - - \param index column index - \return title of the specified column -*/ -QString SUIT_DataObject::columnTitle( const int index ) const -{ - if ( index == NameIdx ) - return QObject::tr( "NAME_COLUMN" ); // one column ("Name") is provided by default - return QString(); -} - -/*! - \brief Get column icon. - - This method can be re-implemented in the subclasses. - Default implementation returns null pixmap. - - \param index column index - \return icon of the specified column -*/ -QPixmap SUIT_DataObject::columnIcon( const int /*index*/ ) const -{ - return QPixmap(); -} - -/*! - \brief Check if the column should appear in the tree view header popup menu - (to show/hide the column). - - Default implementation returns \c false because 'Name' column should be - always visible. - - \param index column index - \return \c true if the column can be shown/hidden -*/ -bool SUIT_DataObject::appropriate( const int /*index*/ ) const -{ - return false; -} - /*! \brief Get the number of the child objects. \return number of the children @@ -448,15 +390,15 @@ QString SUIT_DataObject::name() const This method can be re-implemented in the subclasses. Default implementation returns null string. - Column with \a index = 0 (NameIdx) is supposed to be used + Column with \a id = 0 (NameId) is supposed to be used to get the object name (as it does the default implementation). - \param index column index + \param id column id \return object text data */ -QString SUIT_DataObject::text( const int index ) const +QString SUIT_DataObject::text( const int id ) const { - return index == NameIdx ? name() : QString(); + return id == NameId ? name() : QString(); } /*! @@ -465,13 +407,12 @@ QString SUIT_DataObject::text( const int index ) const This method can be re-implemented in the subclasses. Default implementation returns null pixmap. - The parameter \a index specifies the column number - (to display, for example, in the tree view widget). + The parameter \a id specifies the column identificator - \param index column index + \param id column id \return object icon for the specified column */ -QPixmap SUIT_DataObject::icon( const int /*index*/ ) const +QPixmap SUIT_DataObject::icon( const int /*id*/ ) const { return QPixmap(); } @@ -482,14 +423,13 @@ QPixmap SUIT_DataObject::icon( const int /*index*/ ) const This method can be re-implemented in the subclasses. Default implementation returns null color. - The parameter \a index specifies the column number - (to display, for example, in the tree view widget). + The parameter \a id specifies the column identificator \param role color role - \param index column index + \param id column id \return object color for the specified column */ -QColor SUIT_DataObject::color( const ColorRole /*role*/, const int /*index*/ ) const +QColor SUIT_DataObject::color( const ColorRole /*role*/, const int /*id*/ ) const { return QColor(); } @@ -500,13 +440,13 @@ QColor SUIT_DataObject::color( const ColorRole /*role*/, const int /*index*/ ) c This method can be re-implemented in the subclasses. Default implementation returns null string. - The parameter \a index specifies the column number + The parameter \a id specifies the column identificator (to display, for example, in the tree view widget). - \param index column index + \param id column id \return object tooltip for the specified column */ -QString SUIT_DataObject::toolTip( const int /*index*/ ) const +QString SUIT_DataObject::toolTip( const int /*id*/ ) const { return QString(); } @@ -517,13 +457,12 @@ QString SUIT_DataObject::toolTip( const int /*index*/ ) const This method can be re-implemented in the subclasses. Default implementation returns null string. - The parameter \a index specifies the column number - (to display, for example, in the tree view widget). + The parameter \a id specifies the column identificator - \param index column index + \param id column id \return object status tip for the specified column */ -QString SUIT_DataObject::statusTip( const int /*index*/ ) const +QString SUIT_DataObject::statusTip( const int /*id*/ ) const { return QString(); } @@ -535,13 +474,12 @@ QString SUIT_DataObject::statusTip( const int /*index*/ ) const This method can be re-implemented in the subclasses. Default implementation returns null string. - The parameter \a index specifies the column number - (to display, for example, in the tree view widget). + The parameter \a id specifies the column identificator - \param index column index + \param id column id \return object "what's this" information for the specified column */ -QString SUIT_DataObject::whatsThis( const int /*index*/ ) const +QString SUIT_DataObject::whatsThis( const int /*id*/ ) const { return QString(); } @@ -552,13 +490,12 @@ QString SUIT_DataObject::whatsThis( const int /*index*/ ) const This method can be re-implemented in the subclasses. Default implementation returns application default font. - The parameter \a index specifies the column number - (to display, for example, in the tree view widget). + The parameter \a id specifies the column identificator - \param index column index + \param id column id \return object font for the specified column */ -QFont SUIT_DataObject::font( const int /*index*/ ) const +QFont SUIT_DataObject::font( const int /*id*/ ) const { return QFont(); } @@ -570,13 +507,13 @@ QFont SUIT_DataObject::font( const int /*index*/ ) const Default implementation returns default alignment which is Qt:AlignLeft. - The parameter \a index specifies the column number + The parameter \a id specifies the column identificator (to display, for example, in the tree view widget). - \param index column index + \param id column id \return object text alignment flags for the specified column */ -int SUIT_DataObject::alignment( const int /*index*/ ) const +int SUIT_DataObject::alignment( const int /*id*/ ) const { return Qt::AlignLeft; } @@ -642,11 +579,11 @@ bool SUIT_DataObject::isSelectable() const This method can be re-implemented in the subclasses. Default implementation returns \c false (all objects are not checkable). - \param index column index + \param id column id \return \c true if the item can be checked or unchecked by the user \sa isOn(), setOn() */ -bool SUIT_DataObject::isCheckable( const int /*index*/ ) const +bool SUIT_DataObject::isCheckable( const int /*id*/ ) const { return false; } @@ -658,13 +595,13 @@ bool SUIT_DataObject::isCheckable( const int /*index*/ ) const Default implementation supports the checked state for the first ("Name") column only. - \param index column index + \param id column id \return checked state of the object for the specified column \sa setOn(), isCheckable() */ -bool SUIT_DataObject::isOn( const int index ) const +bool SUIT_DataObject::isOn( const int id ) const { - return index == NameIdx && myCheck; + return id == NameId && myCheck; } /*! @@ -675,12 +612,12 @@ bool SUIT_DataObject::isOn( const int index ) const ("Name") column only. \param on new checked state of the object for the specified column - \param index column index + \param id column id \sa isOn(), isCheckable() */ -void SUIT_DataObject::setOn( const bool on, const int index ) +void SUIT_DataObject::setOn( const bool on, const int id ) { - if ( index == NameIdx ) + if( id == NameId ) myCheck = on; } @@ -711,11 +648,11 @@ void SUIT_DataObject::setOpen( const bool on ) Default implementation returns false ("Name" column does not require custom sorting). - \param index column index + \param id column id \return \c true if column sorting should be customized \sa compare() */ -bool SUIT_DataObject::customSorting( const int /*index*/ ) const +bool SUIT_DataObject::customSorting( const int /*id*/ ) const { return false; } @@ -732,12 +669,12 @@ bool SUIT_DataObject::customSorting( const int /*index*/ ) const \param left first data to compare \param right second data to compare - \param index column index + \param id column id \return result of the comparison \sa customSorting() */ bool SUIT_DataObject::compare( const QVariant& /*left*/, const QVariant& /*right*/, - const int /*index*/ ) const + const int /*id*/ ) const { return false; } @@ -941,6 +878,21 @@ void SUIT_DataObject::update() { } +/*! + \brief return unique group identificator + + Groups of data objects are used for column information search. + Each column of data model has one or several registered group id + If object has the same group id as one of registered, the information + will be shown; the custom id of column will be passed into data() method + in order to identify column from point of view of data object + + */ +int SUIT_DataObject::groupId() const +{ + return 0; +} + /*! \fn void SUIT_DataObject::Signal::created( SUIT_DataObject* object ); \brief Emitted when data object is created. diff --git a/src/SUIT/SUIT_DataObject.h b/src/SUIT/SUIT_DataObject.h index 40916cf03..03798ea8e 100755 --- a/src/SUIT/SUIT_DataObject.h +++ b/src/SUIT/SUIT_DataObject.h @@ -55,9 +55,10 @@ public: HighlightedText //!< highlighted foreground (text) color } ColorRole; - //! Column index - enum { - NameIdx //!< name column + //! Column id + enum + { + NameId //!< name column }; SUIT_DataObject( SUIT_DataObject* = 0 ); @@ -67,11 +68,6 @@ public: SUIT_DataObject* lastChild() const; SUIT_DataObject* firstChild() const; - virtual int columnCount() const; - virtual QString columnTitle( const int = NameIdx ) const; - virtual QPixmap columnIcon( const int = NameIdx ) const; - virtual bool appropriate( const int = NameIdx ) const; - int childCount() const; int childPos( const SUIT_DataObject* ) const; SUIT_DataObject* childObject( const int ) const; @@ -98,34 +94,34 @@ public: virtual void setParent( SUIT_DataObject* ); virtual QString name() const; - virtual QString text( const int = NameIdx ) const; - virtual QPixmap icon( const int = NameIdx ) const; - virtual QColor color( const ColorRole, const int = NameIdx ) const; - virtual QString toolTip( const int = NameIdx ) const; - virtual QString statusTip( const int = NameIdx ) const; - virtual QString whatsThis( const int = NameIdx ) const; - virtual QFont font( const int = NameIdx ) const; - virtual int alignment( const int = NameIdx ) const; + virtual QString text( const int = NameId ) const; + virtual QPixmap icon( const int = NameId ) const; + virtual QColor color( const ColorRole, const int = NameId ) const; + virtual QString toolTip( const int = NameId ) const; + virtual QString statusTip( const int = NameId ) const; + virtual QString whatsThis( const int = NameId ) const; + virtual QFont font( const int = NameId ) const; + virtual int alignment( const int = NameId ) const; virtual bool isDragable() const; virtual bool isDropAccepted( SUIT_DataObject* obj ); virtual bool isEnabled() const; virtual bool isSelectable() const; - virtual bool isCheckable( const int = NameIdx ) const; + virtual bool isCheckable( const int = NameId ) const; - virtual bool isOn( const int = NameIdx ) const; - virtual void setOn( const bool, const int = NameIdx ); + virtual bool isOn( const int = NameId ) const; + virtual void setOn( const bool, const int = NameId ); virtual bool isOpen() const; virtual void setOpen( const bool ); virtual void update(); - virtual bool customSorting( const int = NameIdx ) const; - virtual bool compare( const QVariant&, const QVariant&, - const int = NameIdx ) const; + virtual bool customSorting( const int = NameId ) const; + virtual bool compare( const QVariant&, const QVariant&, const int = NameId ) const; virtual SUIT_DataObjectKey* key() const; + virtual int groupId() const; static Signal* signal(); static bool connect( const char*, QObject*, const char* ); diff --git a/src/SUIT/SUIT_TreeModel.cxx b/src/SUIT/SUIT_TreeModel.cxx index b58523931..09230462b 100755 --- a/src/SUIT/SUIT_TreeModel.cxx +++ b/src/SUIT/SUIT_TreeModel.cxx @@ -25,6 +25,31 @@ #include "SUIT_DataObject.h" #include +#include + +SUIT_AbstractModel::SUIT_AbstractModel() +{ +} + +SUIT_AbstractModel::operator const QAbstractItemModel*() const +{ + return dynamic_cast( this ); +} + +SUIT_AbstractModel::operator QAbstractItemModel*() +{ + return dynamic_cast( this ); +} + +SUIT_AbstractModel::operator const QObject*() const +{ + return dynamic_cast( this ); +} + + + + + /*! \class SUIT_TreeModel::TreeItem @@ -450,6 +475,140 @@ SUIT_TreeModel::~SUIT_TreeModel() delete myRootItem; } +/*! + \brief Register new column in the model + \param group_id - unique data object group identificator + \param name - translated column name + \param custom_id - custom column id that should be passed into method SUIT_DataObject::data() + */ +void SUIT_TreeModel::registerColumn( const int group_id, const QString& name, const int custom_id ) +{ + bool found = false; + for( int i=0, n=myColumns.size(); i