Version: 8.3.0
YACS::HMI::SchemaItem Class Reference

#include <SchemaItem.hxx>

Inheritance diagram for YACS::HMI::SchemaItem:
Collaboration diagram for YACS::HMI::SchemaItem:

Public Member Functions

 SchemaItem (SchemaItem *parent, QString label, Subject *subject)
 
virtual ~SchemaItem ()
 
virtual void appendChild (SchemaItem *child)
 
virtual void removeChild (SchemaItem *child)
 
virtual void insertChild (int row, SchemaItem *child)
 
virtual SchemaItemchild (int row)
 
virtual int childCount () const
 
virtual int columnCount () const
 
virtual QVariant data (int column, int role) const
 
virtual Qt::ItemFlags flags (const QModelIndex &index)
 
virtual int row () const
 
virtual SchemaItemparent ()
 
virtual SubjectgetSubject ()
 
virtual void update (GuiEvent event, int type, Subject *son)
 
virtual void select (bool isSelected)
 
virtual void toggleState ()
 
QModelIndex modelIndex (int column=0)
 
virtual void popupMenu (QWidget *caller, const QPoint &globalPos)
 
virtual ItemMimeDatamimeData (ItemMimeData *mime)
 
virtual bool dropMimeData (const QMimeData *data, Qt::DropAction action)
 
virtual void reparent (SchemaItem *parent)
 
virtual void setCaseValue ()
 used in node derived classes More...
 
bool isEmphasized ()
 
void setEmphasize (bool emphasize)
 
- Public Member Functions inherited from YACS::HMI::GuiObserver
 GuiObserver ()
 
virtual ~GuiObserver ()
 
virtual void incrementSubjects (Subject *subject)
 
virtual void decrementSubjects (Subject *subject)
 
int getNbSubjects ()
 
bool isDestructible ()
 

Protected Member Functions

virtual QVariant editionToolTip (int column) const
 
virtual QVariant runToolTip (int column) const
 
virtual QVariant editionWhatsThis (int column) const
 
virtual QVariant runWhatsThis (int column) const
 
virtual QString getMimeFormat ()
 
virtual void setExecState (int execState)
 

Protected Attributes

QList< SchemaItem * > _childItems
 
QList< QVariant > _itemData
 
QList< QVariant > _itemDeco
 
QList< QVariant > _itemForeground
 
QList< QVariant > _itemBackground
 
QList< QVariant > _itemCheckState
 
QList< QVariant > _itemToolTip
 
QList< QVariant > _itemWhatsThis
 
QString _label
 
SchemaItem_parentItem
 
Subject_subject
 
int _execState
 
bool _emphasized
 
- Protected Attributes inherited from YACS::HMI::GuiObserver
std::set< Subject * > _subjectSet
 
bool _destructible
 

Additional Inherited Members

- Static Public Member Functions inherited from YACS::HMI::GuiObserver
static std::string eventName (GuiEvent event)
 
static void setEventMap ()
 
- Static Protected Attributes inherited from YACS::HMI::GuiObserver
static std::map< int, std::string > _eventNameMap
 

Detailed Description

Definition at line 36 of file SchemaItem.hxx.

Constructor & Destructor Documentation

SchemaItem::SchemaItem ( SchemaItem parent,
QString  label,
Subject subject 
)

Definition at line 39 of file SchemaItem.cxx.

References DEBTRACE, YACS::UNDEFINED, and YACS::HMI::YLabel.

40 {
41  DEBTRACE("SchemaItem::SchemaItem " << label.toStdString() << " " << this);
43  _label = label;
44  _subject = subject;
45 
46  _itemData << QVariant() << QVariant() << QVariant(); // --- 3 columns max
47  _itemDeco << QVariant() << QVariant() << QVariant(); // --- 3 columns max
48  _itemForeground << QVariant() << QVariant() << QVariant(); // --- 3 columns max
49  _itemBackground << QVariant() << QVariant() << QVariant(); // --- 3 columns max
50  _itemCheckState << QVariant() << QVariant() << QVariant(); // --- 3 columns max
51  _itemToolTip << QVariant() << QVariant() << QVariant(); // --- 3 columns max
52  _itemWhatsThis << QVariant() << QVariant() << QVariant(); // --- 3 columns max
53  _itemData.replace(YLabel, label);
54  _itemToolTip.replace(YLabel, label);
55  _itemWhatsThis.replace(YLabel, QString("This is the default WhatsThis of ") + label);
56 
57  _itemForeground.replace(YLabel, QColor("blue"));
58  _itemBackground.replace(YLabel, QtGuiContext::getQtCurrent()->getSchemaModel()->stdBackBrush());
59  //_itemCheckState.replace(YLabel, Qt::Unchecked); // --- only for item with checkbox
60 
61  if (_subject)
62  {
63  _subject->attach(this);
65  }
66 
67  if (_parentItem)
68  _parentItem->appendChild(this);
70  _emphasized = false;
71 }
SchemaItem::~SchemaItem ( )
virtual

Definition at line 73 of file SchemaItem.cxx.

References DEBTRACE.

74 {
75  DEBTRACE("SchemaItem::~SchemaItem " << _label.toStdString() << " " << this);
76  if (_parentItem)
77  {
79  int position = row();
80  model->beginRemoveRows(_parentItem->modelIndex(), position, position);
82  _parentItem->removeChild(this);
83  model->endRemoveRows();
84  }
85 }

Member Function Documentation

void SchemaItem::appendChild ( SchemaItem child)
virtual

Definition at line 87 of file SchemaItem.cxx.

References DEBTRACE.

Referenced by reparent(), and YACS::HMI::SchemaNodeItem::update().

88 {
89  DEBTRACE("SchemaItem::appendChild");
90  _childItems.append(child);
91 }
SchemaItem * SchemaItem::child ( int  row)
virtual

Definition at line 105 of file SchemaItem.cxx.

Referenced by YACS::HMI::SchemaModel::index(), and YACS::HMI::SchemaNodeItem::update().

106 {
107  //DEBTRACE("SchemaItem::child");
108  return _childItems.value(row);
109 }
int SchemaItem::columnCount ( ) const
virtual

Definition at line 117 of file SchemaItem.cxx.

118 {
119  //DEBTRACE("SchemaItem::columnCount " << _itemData.count());
120  return _itemData.count();
121 }
QVariant SchemaItem::data ( int  column,
int  role 
) const
virtual

Definition at line 123 of file SchemaItem.cxx.

Referenced by YACS::HMI::SchemaModel::data(), YACS::HMI::SchemaInPortItem::dropMimeData(), YACS::HMI::SchemaDirTypesItem::dropMimeData(), YACS::HMI::SchemaNodeItem::dropMimeData(), YACS::HMI::SchemaComposedNodeItem::dropMimeData(), and YACS::HMI::SceneObserverItem::getToolTip().

124 {
125  //DEBTRACE("SchemaItem::data "<< column);
126  if (role == Qt::DisplayRole)
127  return _itemData.value(column);
128  if (role == Qt::DecorationRole)
129  return _itemDeco.value(column);
130  if (role == Qt::ForegroundRole)
131  return _itemForeground.value(column);
132  if (role == Qt::BackgroundRole)
133  return _itemBackground.value(column);
134  if (role == Qt::CheckStateRole)
135  return _itemCheckState.value(column);
136  if (role == Qt::ToolTipRole)
137  if (QtGuiContext::getQtCurrent()->isEdition())
138  return editionToolTip(column);
139  else
140  return runToolTip(column);
141  if (role == Qt::WhatsThisRole)
142  if (QtGuiContext::getQtCurrent()->isEdition())
143  return editionWhatsThis(column);
144  else
145  return runWhatsThis(column);
146  return QVariant();
147 }
bool SchemaItem::dropMimeData ( const QMimeData data,
Qt::DropAction  action 
)
virtual
QVariant SchemaItem::editionToolTip ( int  column) const
protectedvirtual

Reimplemented in YACS::HMI::SchemaProcItem.

Definition at line 301 of file SchemaItem.cxx.

302 {
303  QString val = QString("Edition: ") + _itemData.value(0).toString();
304  QString val1 = _itemData.value(1).toString();
305  QString val2 = _itemData.value(2).toString();
306  if (!val1.isEmpty()) val += QString(" | ") + val1;
307  if (!val2.isEmpty()) val += QString(" | ") + val2;
308  return val;
309 }
QVariant SchemaItem::editionWhatsThis ( int  column) const
protectedvirtual
Qt::ItemFlags SchemaItem::flags ( const QModelIndex &  index)
virtual

Reimplemented in YACS::HMI::SchemaComposedNodeItem, YACS::HMI::SchemaNodeItem, YACS::HMI::SchemaDirTypesItem, YACS::HMI::SchemaDirLinksItem, YACS::HMI::SchemaInPortItem, and YACS::HMI::SchemaOutPortItem.

Definition at line 149 of file SchemaItem.cxx.

Referenced by YACS::HMI::SchemaModel::flags().

150 {
151  return Qt::ItemIsEnabled | Qt::ItemIsSelectable;// | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
152 }
QString SchemaItem::getMimeFormat ( )
protectedvirtual

Reimplemented in YACS::HMI::SchemaComposedNodeItem, YACS::HMI::SchemaNodeItem, and YACS::HMI::SchemaOutPortItem.

Definition at line 333 of file SchemaItem.cxx.

334 {
335  return "yacs/subject";
336 }
void SchemaItem::insertChild ( int  row,
SchemaItem child 
)
virtual

Definition at line 99 of file SchemaItem.cxx.

References DEBTRACE.

100 {
101  DEBTRACE("SchemaItem::insertChild");
102  _childItems.insert(row, child);
103 }
bool YACS::HMI::SchemaItem::isEmphasized ( )
inline

Definition at line 66 of file SchemaItem.hxx.

References _emphasized.

66 {return _emphasized; };
ItemMimeData * SchemaItem::mimeData ( ItemMimeData mime)
virtual

setData mime type must be coherent with SchemaModel::mimeTypes

Definition at line 276 of file SchemaItem.cxx.

References DEBTRACE, and YACS::HMI::ItemMimeData::setSubject().

Referenced by YACS::HMI::SchemaModel::mimeData().

277 {
278  DEBTRACE("SchemaItem::mimeData");
279  mime->setSubject(_subject);
280  mime->setData(getMimeFormat(), "_subject");
281  return mime;
282 }
QModelIndex SchemaItem::modelIndex ( int  column = 0)
SchemaItem * SchemaItem::parent ( )
virtual
void SchemaItem::removeChild ( SchemaItem child)
virtual
void SchemaItem::reparent ( SchemaItem parent)
virtual

Definition at line 289 of file SchemaItem.cxx.

References appendChild().

Referenced by YACS::HMI::SchemaComposedNodeItem::update().

290 {
292  if (_parentItem)
293  _parentItem->appendChild(this);
294 }
int SchemaItem::row ( ) const
virtual

Definition at line 154 of file SchemaItem.cxx.

Referenced by YACS::HMI::SchemaModel::parent(), and YACS::HMI::SchemaComposedNodeItem::update().

155 {
156  //DEBTRACE("SchemaItem::row");
157  int row=0;
158  if (_parentItem)
159  row = _parentItem->_childItems.indexOf(const_cast<SchemaItem*>(this));
160  return row;
161 }
QVariant SchemaItem::runToolTip ( int  column) const
protectedvirtual

Reimplemented in YACS::HMI::SchemaProcItem.

Definition at line 311 of file SchemaItem.cxx.

312 {
313  QString val = QString("Execution: ") + _itemData.value(0).toString();
314  QString val1 = _itemData.value(1).toString();
315  QString val2 = _itemData.value(2).toString();
316  if (!val1.isEmpty()) val += QString(" | ") + val1;
317  if (!val2.isEmpty()) val += QString(" | ") + val2;
318  return val;
319 }
QVariant SchemaItem::runWhatsThis ( int  column) const
protectedvirtual

Definition at line 327 of file SchemaItem.cxx.

328 {
329  QString val = QString("Execution help: ") + _itemWhatsThis.value(column).toString();
330  return val;
331 }
void SchemaItem::select ( bool  isSelected)
virtual

Reimplemented from YACS::HMI::GuiObserver.

Definition at line 206 of file SchemaItem.cxx.

References YACS::HMI::ADD, YACS::HMI::ADDCONTROLLINK, YACS::HMI::ADDLINK, YACS::HMI::CONTROLLINK, YACS::HMI::DATALINK, and DEBTRACE.

207 {
208  DEBTRACE("SchemaItem::select " << _label.toStdString() << " " << isSelected);
209  QItemSelectionModel* selectionModel = QtGuiContext::getQtCurrent()->getSelectionModel();
210  QModelIndex anIndex = modelIndex();
211  QItemSelection newSelection(anIndex, anIndex);
212 
213  if (isSelected)
214  {
215  if (!QtGuiContext::getQtCurrent()->_mapOfEditionItem.count(_subject))
216  {
217  int elemType = _subject->getType();
219  if (elemType == YACS::HMI::DATALINK) event = YACS::HMI::ADDLINK;
220  else if (elemType == YACS::HMI::CONTROLLINK) event = YACS::HMI::ADDCONTROLLINK;
222  }
223 
225  QItemSelection currentSelected = selectionModel->selection();
226  if (currentSelected != newSelection)
227  {
228  DEBTRACE("currentSelected != newSelection");
229  // selectionModel->select(newSelection, QItemSelectionModel::ClearAndSelect);
230  selectionModel->select(newSelection, QItemSelectionModel::Clear);
231  selectionModel->select(newSelection, QItemSelectionModel::Select);
232  }
234  }
235  else
236  selectionModel->select(newSelection, QItemSelectionModel::Deselect);
237 }
void SchemaItem::setCaseValue ( )
virtual

used in node derived classes

Reimplemented in YACS::HMI::SchemaComposedNodeItem, and YACS::HMI::SchemaNodeItem.

Definition at line 297 of file SchemaItem.cxx.

Referenced by YACS::HMI::SchemaComposedNodeItem::update().

298 {
299 }
void YACS::HMI::SchemaItem::setEmphasize ( bool  emphasize)
inline

Definition at line 67 of file SchemaItem.hxx.

References _emphasized.

67 {_emphasized = emphasize; };
void SchemaItem::setExecState ( int  execState)
protectedvirtual

Reimplemented in YACS::HMI::SchemaProcItem.

Definition at line 338 of file SchemaItem.cxx.

References YACS::ACTIVATED, DEBTRACE, YACS::DESACTIVATED, YACS::DISABLED, YACS::DONE, YACS::ERROR, YACS::EXECFAILED, YACS::FAILED, YACS::INTERNALERR, YACS::INVALID, YACS::LOADED, YACS::LOADFAILED, YACS::PAUSE, YACS::READY, YACS::SUSPENDED, YACS::TOACTIVATE, YACS::TOLOAD, YACS::UNDEFINED, and YACS::HMI::YState.

Referenced by YACS::HMI::SchemaComposedNodeItem::SchemaComposedNodeItem(), YACS::HMI::SchemaNodeItem::SchemaNodeItem(), YACS::HMI::SchemaNodeItem::update(), and YACS::HMI::SchemaComposedNodeItem::update().

339 {
340  DEBTRACE("SchemaItem::setExecState " << execState);
341  _execState = execState;
342  QString stateDef;
343  QColor sc;
344  switch (_execState)
345  {
346  case YACS::UNDEFINED: sc = Resource::UNDEFINED ; stateDef = "UNDEFINED" ; break;
347  case YACS::INVALID: sc = Resource::INVALID ; stateDef = "INVALID" ; break;
348  case YACS::READY: sc = Resource::READY ; stateDef = "READY" ; break;
349  case YACS::TOLOAD: sc = Resource::TOLOAD ; stateDef = "TOLOAD" ; break;
350  case YACS::LOADED: sc = Resource::LOADED ; stateDef = "LOADED" ; break;
351  case YACS::TOACTIVATE: sc = Resource::TOACTIVATE ; stateDef = "TOACTIVATE" ; break;
352  case YACS::ACTIVATED: sc = Resource::ACTIVATED ; stateDef = "ACTIVATED" ; break;
353  case YACS::DESACTIVATED: sc = Resource::DESACTIVATED; stateDef = "DESACTIVATED"; break;
354  case YACS::DONE: sc = Resource::DONE ; stateDef = "DONE" ; break;
355  case YACS::SUSPENDED: sc = Resource::SUSPENDED ; stateDef = "SUSPENDED" ; break;
356  case YACS::LOADFAILED: sc = Resource::LOADFAILED ; stateDef = "LOADFAILED" ; break;
357  case YACS::EXECFAILED: sc = Resource::EXECFAILED ; stateDef = "EXECFAILED" ; break;
358  case YACS::PAUSE: sc = Resource::PAUSE ; stateDef = "PAUSE" ; break;
359  case YACS::INTERNALERR: sc = Resource::INTERNALERR ; stateDef = "INTERNALERR" ; break;
360  case YACS::DISABLED: sc = Resource::DISABLED ; stateDef = "DISABLED" ; break;
361  case YACS::FAILED: sc = Resource::FAILED ; stateDef = "FAILED" ; break;
362  case YACS::ERROR: sc = Resource::ERROR ; stateDef = "ERROR" ; break;
363  default: sc = Resource::DEFAULT ; stateDef = "---" ;
364  }
365  _itemData.replace(YState, stateDef);
366  _itemForeground.replace(YState, sc);
367 }
void SchemaItem::toggleState ( )
virtual

Reimplemented in YACS::HMI::SchemaNodeItem.

Definition at line 239 of file SchemaItem.cxx.

References DEBTRACE, and YACS::HMI::YLabel.

Referenced by YACS::HMI::SchemaModel::setData(), and YACS::HMI::SchemaNodeItem::toggleState().

240 {
241  if (_itemCheckState.value(YLabel) == Qt::Unchecked)
242  {
243  DEBTRACE("SchemaItem::toggleState true");
244  _itemCheckState.replace(YLabel, Qt::Checked);
245  }
246  else
247  {
248  DEBTRACE("SchemaItem::toggleState false");
249  _itemCheckState.replace(YLabel, Qt::Unchecked);
250  }
251 }
void SchemaItem::update ( GuiEvent  event,
int  type,
Subject son 
)
virtual

Reimplemented from YACS::HMI::GuiObserver.

Reimplemented in YACS::HMI::SchemaComposedNodeItem, YACS::HMI::SchemaNodeItem, YACS::HMI::SchemaComponentItem, YACS::HMI::SchemaContainerItem, YACS::HMI::SchemaDataTypeItem, YACS::HMI::SchemaInPortItem, YACS::HMI::SchemaLinkItem, YACS::HMI::SchemaOutPortItem, and YACS::HMI::SchemaReferenceItem.

Definition at line 174 of file SchemaItem.cxx.

References DEBTRACE, YACS::HMI::EDIT, YACS::HMI::SchemaModel::editedBackBrush(), YACS::HMI::EMPHASIZE, YACS::HMI::SchemaModel::emphasizeBackBrush(), YACS::HMI::RENAME, YACS::HMI::SchemaModel::setData(), YACS::HMI::SchemaModel::stdBackBrush(), and YACS::HMI::YLabel.

Referenced by gui.graph.MyCanvas::customEvent(), YACS::HMI::SchemaReferenceItem::update(), YACS::HMI::SchemaContainerItem::update(), YACS::HMI::SchemaOutPortItem::update(), YACS::HMI::SchemaInPortItem::update(), YACS::HMI::SchemaLinkItem::update(), YACS::HMI::SchemaDataTypeItem::update(), YACS::HMI::SchemaNodeItem::update(), and YACS::HMI::SchemaComposedNodeItem::update().

175 {
176  //DEBTRACE("SchemaItem::update "<< eventName(event) <<" "<<type<<" "<<son);
177  QModelIndex index = QModelIndex();
179  switch (event)
180  {
181  case RENAME:
182  DEBTRACE("SchemaItem::update RENAME " << _subject->getName());
183  _label = _subject->getName().c_str();
184  _itemData.replace(YLabel, _label);
185  model->setData(modelIndex(YLabel), 0); // --- to emit dataChanged signal
186  break;
187  case EDIT:
188  if (type)
189  _itemBackground.replace(YLabel, model->editedBackBrush());
190  else
191  _itemBackground.replace(YLabel, model->stdBackBrush());
192  model->setData(modelIndex(YLabel), 0); // --- to emit dataChanged signal
193  break;
194  case EMPHASIZE:
195  if (type)
196  _itemBackground.replace(YLabel, model->emphasizeBackBrush());
197  else
198  _itemBackground.replace(YLabel, model->stdBackBrush());
199  model->setData(modelIndex(YLabel), 0); // --- to emit dataChanged signal
200  break;
201  default:
202  break;
203  }
204 }

Member Data Documentation

QList<SchemaItem*> YACS::HMI::SchemaItem::_childItems
protected

Definition at line 76 of file SchemaItem.hxx.

bool YACS::HMI::SchemaItem::_emphasized
protected

Definition at line 88 of file SchemaItem.hxx.

Referenced by isEmphasized(), and setEmphasize().

int YACS::HMI::SchemaItem::_execState
protected

Definition at line 87 of file SchemaItem.hxx.

Referenced by YACS::HMI::SchemaProcItem::setExecState().

QList<QVariant> YACS::HMI::SchemaItem::_itemBackground
protected

Definition at line 80 of file SchemaItem.hxx.

Referenced by YACS::HMI::SchemaProcItem::setExecState().

QList<QVariant> YACS::HMI::SchemaItem::_itemCheckState
protected
QList<QVariant> YACS::HMI::SchemaItem::_itemToolTip
protected

Definition at line 82 of file SchemaItem.hxx.

QList<QVariant> YACS::HMI::SchemaItem::_itemWhatsThis
protected

Definition at line 83 of file SchemaItem.hxx.

QString YACS::HMI::SchemaItem::_label
protected

Definition at line 84 of file SchemaItem.hxx.

Referenced by YACS::HMI::SchemaReferenceItem::update().

SchemaItem* YACS::HMI::SchemaItem::_parentItem
protected

The documentation for this class was generated from the following files: