return QString();
}
+/*!
+ \brief Returns the string identifier of the data objects referenced by this one.
+
+ This method should be reimplemented in the subclasses.
+ Default implementation returns null string.
+
+ \return ID string of the referenced data object
+*/
+QString LightApp_DataObject::refEntry() const
+{
+ return QString();
+}
+
+/*!
+ \brief Tells if this data objects is a reference to some other or not.
+
+ The base implementation retuns true, if refEntry() returns non-empty string.
+
+ \return true if refEntry() is a non-empty string.
+*/
+bool LightApp_DataObject::isReference() const
+{
+ return !refEntry().isEmpty();
+}
+
/*!
\brief Get the data object unique key.
\return data object key
/*!
\brief Get object text data for the specified column.
- Column with \a id = 0 (NameId) is supposed to be used
+ Column with \a id == NameId is supposed to be used
to get the object name.
- Column with \a id = 1 (EntryId) is supposed to be used
+ Column with \a id == EntryId is supposed to be used
to get the object entry.
+ Column with \a id == RefEntryId is supposed to be used
+ to show the entry of the object referenced by this one.
\param id column id
\return object text data
*/
QString LightApp_DataObject::text( const int id ) const
{
- return id == EntryId ? entry() : CAM_DataObject::text( id );
+ QString txt;
+
+ switch ( id )
+ {
+ case EntryId:
+ txt = entry();
+ break;
+ case RefEntryId:
+ // Issue 21379: reference support at LightApp level
+ if ( isReference() )
+ txt = refEntry();
+ break;
+ default:
+ // Issue 21379: Note that we cannot return some specially decorated
+ // name string (like "* ref_obj_name") when isReference() returns true,
+ // since there is no generic way at LightApp level
+ // to query the object name using refEntry() up to now.
+ // TODO: Think how to make reference name generation
+ // more generic at move it here from SalomeApp level...
+ txt = CAM_DataObject::text( id );
+ break;
+ }
+
+ return txt;
+}
+
+/*!
+ \brief Get data object color for the specified column.
+ \param role color role
+ \param id column id (not used)
+ \return object color for the specified column
+*/
+QColor LightApp_DataObject::color( const ColorRole role, const int id) const
+{
+ QColor c;
+
+ // Issue 21379: reference support at LightApp level
+ // Centralized way for choosing text/background color for references.
+ // Colors for "normal" objects should be chosen by sub-classes.
+ switch ( role )
+ {
+ case Text:
+ case Foreground:
+ // text color (not selected item)
+ // TODO: think how to detect invalid references...
+ if ( isReference() )
+ c = QColor( 255, 0, 0 ); // valid reference (red)
+ break;
+
+ case Highlight:
+ // background color for the highlighted item
+ // TODO: think how to detect invalid references...
+ if ( isReference() )
+ c = QColor( 255, 0, 0 ); // valid reference (red)
+ break;
+
+ case HighlightedText:
+ // text color for the highlighted item
+ if ( isReference() )
+ c = QColor( 255, 255, 255 ); // white
+ break;
+
+ default:
+ break;
+ }
+
+ if ( !c.isValid() )
+ c = CAM_DataObject::color( role, id );
+
+ return c;
}
/*!
public:
//! Column id
enum {
- EntryId = VisibilityId + 1 //!< entry column
+ EntryId = VisibilityId + 1, //!< entry column
+ RefEntryId //!< reference entry column
};
public:
virtual SUIT_DataObjectKey* key() const;
virtual QString entry() const;
+ virtual QString refEntry() const;
+ virtual bool isReference() const;
+
virtual QString text( const int = NameId ) const;
+ virtual QColor color( const ColorRole, const int = NameId ) const;
virtual SUIT_DataObject* componentObject() const;
virtual QString componentDataType() const;
return myEntry;
}
+//=================================================================================
+// function : SALOME_PYQT_DataObjectLight::refEntry()
+// purpose : return entry of the data object referenced by this one (if any)
+//=================================================================================
+QString SALOME_PYQT_DataObjectLight::refEntry() const
+{
+ return myRefEntry;
+}
+
+//=================================================================================
+// function : SALOME_PYQT_DataObjectLight::setRefEntry()
+// purpose : sets entry of the data object referenced by this one
+//=================================================================================
+void SALOME_PYQT_DataObjectLight::setRefEntry( const QString& refEntry )
+{
+ myRefEntry = refEntry;
+}
+
//=================================================================================
// function : SALOME_PYQT_DataObjectLight::name()
// purpose : return name of object
return myToolTip;
}
+//=================================================================================
+// function : SALOME_PYQT_DataObjectLight::toolTip()
+// purpose : return toolTip of object
+//=================================================================================
+QColor SALOME_PYQT_DataObjectLight::color( const ColorRole role, const int id ) const
+{
+ QColor c;
+
+ switch ( role )
+ {
+ case Text:
+ case Foreground:
+ if ( !isReference() )
+ c = myColor;
+ break;
+
+ default:
+ break;
+ }
+
+ // Issue 21379: LightApp_DataObject::color() defines colors for valid references
+ if ( !c.isValid() )
+ c = LightApp_DataObject::color( role, id );
+
+ return c;
+}
bool SALOME_PYQT_DataObjectLight::setName(const QString& name)
{
{
myToolTip = tooltip;
}
+
+void SALOME_PYQT_DataObjectLight::setColor(const QColor& color)
+{
+ myColor = color;
+}
virtual ~SALOME_PYQT_DataObjectLight();
virtual QString entry() const;
+
+ virtual QString refEntry() const;
+ void setRefEntry( const QString& refEntry );
virtual QString name() const;
- QPixmap icon(const int = NameId) const;
- QString toolTip(const int = NameId) const;
-
- bool setName(const QString& name);
- void setIcon(const QString& icon);
- void setToolTip(const QString& tooltip);
+ virtual QPixmap icon(const int = NameId) const;
+ virtual QString toolTip(const int = NameId) const;
+
+ bool setName(const QString& name);
+ void setIcon(const QString& icon);
+ void setToolTip(const QString& tooltip);
+
+ virtual QColor color( const ColorRole, const int = NameId ) const;
+ void setColor(const QColor& color);
private:
QString myEntry;
+ QString myRefEntry;
QString myName;
QString myToolTip;
QPixmap myIcon;
+ QColor myColor;
};
#endif // SALOME_PYQT_DATAOBJECTLIGHT_H
}
}
+/*
+ * Return color of object
+ */
+QColor SALOME_PYQT_ModuleLight::getColor(const QString& obj)
+{
+ SALOME_PYQT_DataObjectLight* dataObj = findObject( obj );
+ if( dataObj ) {
+ return dataObj->color( SUIT_DataObject::Foreground );
+ }
+ return QColor();
+}
+
+/*
+ * Set color for object
+ */
+void SALOME_PYQT_ModuleLight::setColor(const QString& obj, const QColor& color)
+{
+ SALOME_PYQT_DataObjectLight* dataObj = findObject( obj );
+ if( dataObj ) {
+ dataObj->setColor( color );
+ }
+}
+
+/*
+ * Return entry of the referenced object (if any)
+ */
+QString SALOME_PYQT_ModuleLight::getReference(const QString& obj)
+{
+ SALOME_PYQT_DataObjectLight* dataObj = findObject(obj);
+ if(dataObj) {
+ return dataObj->refEntry();
+ }
+ return QString::null;
+}
+
+
+/*
+ * Set entry of the referenced object
+ */
+void SALOME_PYQT_ModuleLight::setReference(const QString& obj, const QString& refEntry)
+{
+ SALOME_PYQT_DataObjectLight* dataObj = findObject(obj);
+ if(dataObj) {
+ dataObj->setRefEntry(refEntry);
+ }
+}
+
/*
* Remove object by entry
*/
void dumpPython(QStringList& theListOfFiles);
/*create new SALOME_PYQT_DataObjectLight and return its entry*/
- QString createObject(const QString& parent);
- QString createObject(const QString& name,
- const QString& iconname,
- const QString& tooltip,
- const QString& parent);
+ QString createObject(const QString& parent);
+ QString createObject(const QString& name,
+ const QString& iconname,
+ const QString& tooltip,
+ const QString& parent);
/*Sets Name, Icon and Tool Tip for object*/
void setName(const QString& obj,const QString& iconname);
void setIcon(const QString& obj,const QString& name);
- void setToolTip(const QString& obj, const QString& name);
+ void setToolTip(const QString& obj, const QString& tooltip);
/*Gets Name and Tool Tip for object*/
QString getName(const QString& obj);
QString getToolTip(const QString& obj);
+
+ void setColor(const QString& obj, const QColor& color);
+ QColor getColor(const QString& obj);
+
+ void setReference( const QString& obj,
+ const QString& refEntry );
+ QString getReference( const QString& obj );
+
/*remove object*/
void removeObject(const QString& obj);
/*remove child*/
ProcessVoidEvent(new TSetToolTipEvent(obj,tooltip));
}
+/*!
+ SalomePyQt::setReference(obj,refEntry)
+ Set entry to referenced object
+*/
+class TSetRefEvent: public SALOME_Event
+{
+public:
+ QString myObj;
+ QString myRefEntry;
+ TSetRefEvent( const QString& obj,
+ const QString& refEntry) : myObj(obj),
+ myRefEntry(refEntry) {}
+ virtual void Execute() {
+ SALOME_PYQT_ModuleLight* module = getActiveModule();
+ if ( module )
+ module->setReference(myObj,myRefEntry);
+ }
+};
+void SalomePyQt::setReference(const QString& obj,const QString& refEntry)
+{
+ ProcessVoidEvent(new TSetRefEvent(obj,refEntry));
+}
+
+/*!
+ SalomePyQt::setColor(obj,color)
+ Set object color
+*/
+class TSetColorEvent: public SALOME_Event
+{
+public:
+ QString myObj;
+ QColor myColor;
+ TSetColorEvent( const QString& obj,
+ const QColor& color) : myObj(obj),
+ myColor(color) {}
+ virtual void Execute() {
+ SALOME_PYQT_ModuleLight* module = getActiveModule();
+ if ( module )
+ module->setColor(myObj,myColor);
+ }
+};
+void SalomePyQt::setColor(const QString& obj,const QColor& color)
+{
+ ProcessVoidEvent(new TSetColorEvent(obj,color));
+}
+
/*!
SalomePyQt::getName(obj)
Return name of object
return ProcessEvent(new TGetToolTipEvent(obj));
}
+/*!
+ SalomePyQt::getReference(obj)
+ Return entry of the referenced object (if any)
+*/
+class TGetRefEvent: public SALOME_Event
+{
+public:
+ typedef QString TResult;
+ TResult myResult;
+ QString myObj;
+ TGetRefEvent( const QString& obj ) : myObj(obj) {}
+ virtual void Execute() {
+ SALOME_PYQT_ModuleLight* module = getActiveModule();
+ if ( module )
+ myResult = module->getReference(myObj);
+ }
+};
+QString SalomePyQt::getReference(const QString& obj)
+{
+ return ProcessEvent(new TGetRefEvent(obj));
+}
+
+/*!
+ SalomePyQt::getColor(obj)
+ Return the color of the object
+*/
+class TGetColorEvent: public SALOME_Event
+{
+public:
+ typedef QColor TResult;
+ TResult myResult;
+ QString myObj;
+ TGetColorEvent( const QString& obj ) : myObj(obj) {}
+ virtual void Execute() {
+ SALOME_PYQT_ModuleLight* module = getActiveModule();
+ if ( module )
+ myResult = module->getColor(myObj);
+ }
+};
+QColor SalomePyQt::getColor(const QString& obj)
+{
+ return ProcessEvent(new TGetColorEvent(obj));
+}
/*!
SalomePyQt::removeChild(obj)
static QString getName(const QString& obj);
static QString getToolTip(const QString& obj);
+ static void setColor(const QString& obj,const QColor& color);
+ static QColor getColor(const QString& obj);
+
+ static void setReference( const QString& obj,
+ const QString& refEntry );
+ static QString getReference( const QString& obj );
+
static QIcon loadIcon( const QString&, const QString& );
static void helpContext( const QString&, const QString& );
static QString createObject( const QString& = QString("") ) /ReleaseGIL/ ;
static QString createObject( const QString&,
- const QString&,
- const QString&,
- const QString& = QString("") ) /ReleaseGIL/ ;
+ const QString&,
+ const QString&,
+ const QString& = QString("") ) /ReleaseGIL/ ;
static void setName(const QString& ,const QString& ) /ReleaseGIL/ ;
static void setIcon(const QString& ,const QString& ) /ReleaseGIL/ ;
static QString getName(const QString& ) /ReleaseGIL/ ;
static QString getToolTip(const QString& ) /ReleaseGIL/ ;
+ static void setColor( const QString&, const QColor& ) /ReleaseGIL/ ;
+ static QColor getColor( const QString& ) /ReleaseGIL/ ;
+
+ static void setReference( const QString& ,const QString& ) /ReleaseGIL/ ;
+ static QString getReference( const QString& ) /ReleaseGIL/ ;
+
static void removeObject(const QString& ) /ReleaseGIL/ ;
static void removeChild(const QString& = QString("") ) /ReleaseGIL/ ;
static QStringList getChildren(const QString&=QString("") , const bool = false) /ReleaseGIL/ ;
/*!find original object by double click on item */
void SalomeApp_Application::onDblClick( SUIT_DataObject* theObj )
{
- SalomeApp_DataObject* obj = dynamic_cast<SalomeApp_DataObject*>( theObj );
- SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
+ // Issue 21379: References are supported at LightApp_DataObject level
+ LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>( theObj );
- if( study && obj )
+ if( obj && obj->isReference() )
{
- QString entry = obj->entry();
- _PTR(SObject) sobj = study->studyDS()->FindObjectID( entry.toStdString() ), ref;
-
- if( sobj && sobj->ReferencedObject( ref ) )
- {
- entry = ref->GetID().c_str();
+ QString entry = obj->refEntry();
- SUIT_DataOwnerPtrList aList;
- aList.append( new LightApp_DataOwner( entry ) );
- selectionMgr()->setSelected( aList, false );
+ SUIT_DataOwnerPtrList aList;
+ aList.append( new LightApp_DataOwner( entry ) );
+ selectionMgr()->setSelected( aList, false );
+
+ SUIT_DataBrowser* ob = objectBrowser();
- SUIT_DataBrowser* ob = objectBrowser();
-
- QModelIndexList aSelectedIndexes = ob->selectedIndexes();
- if ( !aSelectedIndexes.isEmpty() )
- ob->treeView()->scrollTo( aSelectedIndexes.first() );
- }
+ QModelIndexList aSelectedIndexes = ob->selectedIndexes();
+ if ( !aSelectedIndexes.isEmpty() )
+ ob->treeView()->scrollTo( aSelectedIndexes.first() );
}
}
{
QString txt;
- // add "Value", "IOR", and "Reference Entry" columns
+ // Text for "Value" and "IOR" columns
switch ( id )
{
case ValueId:
case IORId:
txt = ior( referencedObject() );
break;
- case RefEntryId :
- if ( isReference() )
- txt = entry( referencedObject() );
- break;
default:
+ // Issue 21379: LightApp_DataObject::text() treats "Entry"
+ // and "Reference Entry" columns
txt = LightApp_DataObject::text( id );
break;
}
case Foreground:
// text color (not selected item)
if ( isReference() ) {
- if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) )
- c = QColor( 255, 0, 0 ); // valid reference (red)
- else
+ if ( QString(referencedObject()->GetName().c_str()).isEmpty() )
c = QColor( 200, 200, 200 ); // invalid reference (grayed)
}
else if ( myObject ) {
}
}
break;
+
case Highlight:
// background color for the highlighted item
if ( isReference() ) {
- if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) )
- c = QColor( 255, 0, 0 ); // valid reference (red)
- else
+ if ( QString(referencedObject()->GetName().c_str()).isEmpty() )
c = QColor( 200, 200, 200 ); // invalid reference (grayed)
}
else if ( myObject ) {
}
}
break;
- case HighlightedText:
- // text color for the highlighted item
- if ( isReference() )
- c = QColor( 255, 255, 255 ); // white
+ default:
break;
}
+
+ // Issue 21379: LightApp_DataObject::color() defines colors for valid references
if ( !c.isValid() )
c = LightApp_DataObject::color( role, id );
+
return c;
}
return myObject;
}
+/*!
+ \brief Returns the string identifier of the data objects referenced by this one.
+
+ Re-implemented from LightApp_DataObject using SALOMEDS API.
+
+ \return ID string of the referenced SObject
+*/
+QString SalomeApp_DataObject::refEntry() const
+{
+ return entry( referencedObject() );
+}
+
/*!
\brief Check if the data object is a reference.
+
+ Re-implemented from LightApp_DataObject using SALOMEDS API.
+
\return \c true if this data object actually refers to another one
*/
bool SalomeApp_DataObject::isReference() const
public:
//! Column id
enum {
- ValueId = EntryId + 1, //!< value column
- IORId, //!< IOR column
- RefEntryId //!< reference entry column
+ ValueId = RefEntryId + 1, //!< value column
+ IORId //!< IOR column
};
public:
virtual _PTR(SObject) object() const;
- bool isReference() const;
+ virtual QString refEntry() const;
+ virtual bool isReference() const;
_PTR(SObject) referencedObject() const;
+
bool hasChildren() const;
bool expandable() const;