Version: 9.15.0
YACS::HMI::SchemaModel Class Reference

#include <SchemaModel.hxx>

Inheritance diagram for YACS::HMI::SchemaModel:
Collaboration diagram for YACS::HMI::SchemaModel:

Public Slots

void updateSelection (const QItemSelection &selected, const QItemSelection &deselected)
 

Signals

void signalSelection (const QModelIndex &index)
 

Public Member Functions

 SchemaModel (YACS::HMI::Subject *context, QObject *parent=0)
 
virtual ~SchemaModel ()
 
virtual QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const
 
virtual QModelIndex parent (const QModelIndex &index) const
 
virtual int rowCount (const QModelIndex &parent=QModelIndex()) const
 
virtual int columnCount (const QModelIndex &parent=QModelIndex()) const
 
virtual QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 
virtual QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 
virtual bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 
virtual Qt::ItemFlags flags (const QModelIndex &index) const
 
virtual void update (GuiEvent event, int type, Subject *son)
 
SchemaItemgetRootItem ()
 
bool isEdition ()
 
void setEdition (bool isEdition=true)
 
const QBrush & stdBackBrush ()
 
const QBrush & editedBackBrush ()
 
const QBrush & emphasizeBackBrush ()
 
virtual QMimeDatamimeData (const QModelIndexList &indexes) const
 
virtual bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
 
virtual Qt::DropActions supportedDropActions () const
 
virtual QStringList mimeTypes () const
 
- Public Member Functions inherited from YACS::HMI::GuiObserver
 GuiObserver ()
 
virtual ~GuiObserver ()
 
virtual void select (bool isSelected)
 
virtual void incrementSubjects (Subject *subject)
 
virtual void decrementSubjects (Subject *subject)
 
int getNbSubjects ()
 
bool isDestructible ()
 

Protected Member Functions

void setNewRoot (YACS::HMI::Subject *root)
 

Protected Attributes

Subject_context
 
Subject_root
 
SchemaItem_rootItem
 
QBrush _stdBackBrush
 
QBrush _editedBackBrush
 
QBrush _emphasizeBackBrush
 
bool _isEdition
 
- Protected Attributes inherited from YACS::HMI::GuiObserver
std::set< Subject * > _subjectSet
 
bool _destructible
 

Friends

class SchemaItem
 
class SchemaNodeItem
 
class SchemaComposedNodeItem
 
class SchemaDirTypesItem
 
class SchemaDirLinksItem
 
class SchemaDirContainersItem
 
class SchemaContainerItem
 
class SchemaComponentItem
 

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 49 of file SchemaModel.hxx.

Constructor & Destructor Documentation

◆ SchemaModel()

SchemaModel::SchemaModel ( YACS::HMI::Subject context,
QObject parent = 0 
)

Definition at line 39 of file SchemaModel.cxx.

40  :
42 {
43  DEBTRACE("SchemaModel::SchemaModel");
44  _context=context;
45  _root=0;
46  _rootItem=0;
47  _context->attach(this);
48  _stdBackBrush = QColor("white");
49  _editedBackBrush = QColor("yellow");
50  _emphasizeBackBrush = QColor("magenta");
51  _isEdition = true;
52 }
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
virtual QModelIndex parent(const QModelIndex &index) const
Definition: SchemaModel.cxx:80
virtual void attach(GuiObserver *obs)

References _context, _editedBackBrush, _emphasizeBackBrush, _isEdition, _root, _rootItem, _stdBackBrush, YACS::HMI::Subject::attach(), and DEBTRACE.

◆ ~SchemaModel()

SchemaModel::~SchemaModel ( )
virtual

Definition at line 54 of file SchemaModel.cxx.

55 {
56  DEBTRACE("SchemaModel::~SchemaModel");
57  _subjectSet.clear(); // --- avoid destruction loop on delete context
58 }
std::set< Subject * > _subjectSet

References YACS::HMI::GuiObserver::_subjectSet, and DEBTRACE.

Member Function Documentation

◆ columnCount()

int SchemaModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 107 of file SchemaModel.cxx.

108 {
109  //DEBTRACE("SchemaModel::columnCount " << parent.isValid());
110  if (parent.isValid())
111  return static_cast<SchemaItem*>(parent.internalPointer())->columnCount();
112  if (_rootItem)
113  {
114  if (_isEdition) return 3;
115  else return 3; //_rootItem->columnCount();
116  }
117  else
118  return 0;
119 }
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const

References _isEdition, _rootItem, and parent().

◆ data()

QVariant SchemaModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
virtual

Definition at line 121 of file SchemaModel.cxx.

122 {
123  //DEBTRACE("SchemaModel::data");
124  if (!index.isValid())
125  return QVariant();
126  SchemaItem *item = static_cast<SchemaItem*>(index.internalPointer());
127  return item->data(index.column(), role);
128 }
virtual QVariant data(int column, int role) const
Definition: SchemaItem.cxx:123
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: SchemaModel.cxx:60

References YACS::HMI::SchemaItem::data(), and index().

Referenced by dropMimeData().

◆ dropMimeData()

bool SchemaModel::dropMimeData ( const QMimeData data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex &  parent 
)
virtual

Definition at line 274 of file SchemaModel.cxx.

276 {
277  DEBTRACE("SchemaModel::dropMimeData");
278  if (action == Qt::IgnoreAction)
279  return true;
280 
281  string name = "empty";
282  SchemaItem *item = 0;
283  if (parent.isValid())
284  {
285  item = static_cast<SchemaItem*>(parent.internalPointer());
286  name = item->getSubject()->getName();
287  }
288  DEBTRACE(row << " " << column << " "<< name);
289 
290  if ((row >= 0) && (column >=0))
291  {
292  QModelIndex ind = index(row, column, parent);
293  if (!ind.isValid())
294  return false;
295  DEBTRACE("---");
296  item = static_cast<SchemaItem*>(ind.internalPointer());
297  }
298  if (!item)
299  return false;
300  return item->dropMimeData(data, action);
301 }
virtual Subject * getSubject()
Definition: SchemaItem.cxx:169
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action)
Definition: SchemaItem.cxx:284
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
virtual std::string getName()

References data(), DEBTRACE, YACS::HMI::SchemaItem::dropMimeData(), YACS::HMI::Subject::getName(), YACS::HMI::SchemaItem::getSubject(), index(), and parent().

◆ editedBackBrush()

const QBrush & SchemaModel::editedBackBrush ( )

Definition at line 240 of file SchemaModel.cxx.

241 {
242  return _editedBackBrush;
243 }

References _editedBackBrush.

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

◆ emphasizeBackBrush()

const QBrush & SchemaModel::emphasizeBackBrush ( )

Definition at line 245 of file SchemaModel.cxx.

246 {
247  return _emphasizeBackBrush;
248 }

References _emphasizeBackBrush.

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

◆ flags()

Qt::ItemFlags SchemaModel::flags ( const QModelIndex &  index) const
virtual

Definition at line 182 of file SchemaModel.cxx.

183 {
184  //DEBTRACE("SchemaModel::flags");
185  if (!index.isValid())
186  return 0;
187  SchemaItem *item = static_cast<SchemaItem*>(index.internalPointer());
188  return item->flags(index);
189 }
virtual Qt::ItemFlags flags(const QModelIndex &index)
Definition: SchemaItem.cxx:149

References YACS::HMI::SchemaItem::flags(), and index().

◆ getRootItem()

SchemaItem* YACS::HMI::SchemaModel::getRootItem ( )
inline

Definition at line 78 of file SchemaModel.hxx.

78 {return _rootItem; };

References _rootItem.

Referenced by YACS::HMI::SchemaItem::modelIndex().

◆ headerData()

QVariant SchemaModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
virtual

Definition at line 130 of file SchemaModel.cxx.

131 {
132  //DEBTRACE("SchemaModel::headerData");
133  if (role != Qt::DisplayRole)
134  return QVariant();
135 
136  if (orientation == Qt::Horizontal)
137  //return QString("Colonne %1").arg(section);
138  if (_isEdition)
139  switch (section)
140  {
141  case YLabel: return QString("Name");
142  case YType: return QString("Type");
143  case YValue: return QString("Value");
144  default: return QString("- %1 -").arg(section);
145  }
146  else
147  switch (section)
148  {
149  case YLabel: return QString("Name");
150  case YType: return QString("Type");
151  case YState: return QString("State");
152  default: return QString("- %1 -").arg(section);
153  }
154  else
155  return QVariant();
156 }

References _isEdition, YACS::HMI::YLabel, YACS::HMI::YState, YACS::HMI::YType, and YACS::HMI::YValue.

◆ index()

QModelIndex SchemaModel::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const
virtual

Definition at line 60 of file SchemaModel.cxx.

61 {
62  // DEBTRACE("SchemaModel::index");
63  if (!hasIndex(row, column, parent))
64  return QModelIndex();
65 
66  SchemaItem *parentItem = 0;
67 
68  if (!parent.isValid())
69  parentItem = _rootItem;
70  else
71  parentItem = static_cast<SchemaItem*>(parent.internalPointer());
72 
73  SchemaItem *childItem = parentItem->child(row);
74  if (childItem)
75  return createIndex(row, column, childItem);
76  else
77  return QModelIndex();
78 }
virtual SchemaItem * child(int row)
Definition: SchemaItem.cxx:105

References _rootItem, YACS::HMI::SchemaItem::child(), and parent().

Referenced by YACS::HMI::EditionElementaryNode::createTablePorts(), data(), dropMimeData(), flags(), mimeData(), YACS::HMI::SchemaItem::modelIndex(), parent(), setData(), YACS::HMI::EditionElementaryNode::synchronize(), YACS::HMI::EditionSwitch::synchronize(), and updateSelection().

◆ isEdition()

bool YACS::HMI::SchemaModel::isEdition ( )
inline

◆ mimeData()

QMimeData * SchemaModel::mimeData ( const QModelIndexList &  indexes) const
virtual

Definition at line 258 of file SchemaModel.cxx.

259 {
260  DEBTRACE("SchemaModel::mimeData");
261  ItemMimeData *mime = new ItemMimeData;
262  mime->setSubject(_root);
263 
264  if (indexes.empty())
265  return mime;
266  QModelIndex index = indexes.first();
267  if (!index.isValid())
268  return mime;
269  SchemaItem *item = static_cast<SchemaItem*>(index.internalPointer());
270  DEBTRACE("mimeData valid index");
271  return item->mimeData(mime);
272 }
virtual void setSubject(Subject *sub)
virtual ItemMimeData * mimeData(ItemMimeData *mime)
Definition: SchemaItem.cxx:276

References _root, DEBTRACE, index(), YACS::HMI::SchemaItem::mimeData(), and YACS::HMI::ItemMimeData::setSubject().

◆ mimeTypes()

QStringList SchemaModel::mimeTypes ( ) const
virtual

Definition at line 309 of file SchemaModel.cxx.

310 {
311  //DEBTRACE("SchemaModel::mimeTypes");
312  QStringList types;
313  types << "yacs/subject" << "yacs/subjectNode" << "yacs/subjectOutPort"
314  << "yacs/cataService" << "yacs/cataType" << "yacs/cataNode"
315  << "yacs/subjectOutGate";
316  return types;
317 }

◆ parent()

QModelIndex SchemaModel::parent ( const QModelIndex &  index) const
virtual

Definition at line 80 of file SchemaModel.cxx.

81 {
82  // DEBTRACE("SchemaModel::parent");
83  if (!index.isValid())
84  return QModelIndex();
85  SchemaItem *childItem = static_cast<SchemaItem*>(index.internalPointer());
86  SchemaItem *parentItem = childItem->parent();
87  if (parentItem == _rootItem)
88  return QModelIndex();
89  return createIndex(parentItem->row(), 0, parentItem);
90 }
virtual int row() const
Definition: SchemaItem.cxx:154
virtual SchemaItem * parent()
Definition: SchemaItem.cxx:163

References _rootItem, index(), YACS::HMI::SchemaItem::parent(), and YACS::HMI::SchemaItem::row().

Referenced by columnCount(), dropMimeData(), index(), rowCount(), and gui.Appli.Runner::run().

◆ rowCount()

int SchemaModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 92 of file SchemaModel.cxx.

93 {
94  //DEBTRACE("SchemaModel::rowCount");
95  SchemaItem *parentItem;
96  if (parent.column() > 0)
97  return 0;
98  if (!parent.isValid())
99  parentItem = _rootItem;
100  else
101  parentItem = static_cast<SchemaItem*>(parent.internalPointer());
102  if (parentItem)
103  return parentItem->childCount();
104  else return 0;
105 }
virtual int childCount() const
Definition: SchemaItem.cxx:111

References _rootItem, YACS::HMI::SchemaItem::childCount(), and parent().

Referenced by YACS::HMI::EditionElementaryNode::synchronize(), and YACS::HMI::EditionSwitch::synchronize().

◆ setData()

bool SchemaModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
virtual

For EditRole, setData only emit dataChanged signal, actual modification is done in SchemaItem.

Definition at line 162 of file SchemaModel.cxx.

163 {
164  DEBTRACE("SchemaModel::setData");
165  if (index.isValid() && role == Qt::EditRole)
166  {
167  DEBTRACE("Qt::EditRole, emit dataChanged");
168  emit dataChanged(index, index);
169  return true;
170  }
171  if (index.isValid() && role == Qt::CheckStateRole)
172  {
173  DEBTRACE("Qt::CheckStateRole, toggle state");
174  SchemaItem *item = static_cast<SchemaItem*>(index.internalPointer());
175  item->toggleState();
176  emit dataChanged(index, index);
177  return true;
178  }
179  return false;
180 }
virtual void toggleState()
Definition: SchemaItem.cxx:239

References DEBTRACE, index(), and YACS::HMI::SchemaItem::toggleState().

Referenced by YACS::HMI::SchemaComposedNodeItem::SchemaComposedNodeItem(), YACS::HMI::SchemaComposedNodeItem::setCaseValue(), YACS::HMI::SchemaNodeItem::setCaseValue(), YACS::HMI::ItemEdition::setEdited(), YACS::HMI::SchemaComposedNodeItem::update(), YACS::HMI::SchemaInPortItem::update(), YACS::HMI::SchemaItem::update(), YACS::HMI::SchemaNodeItem::update(), YACS::HMI::SchemaOutPortItem::update(), and YACS::HMI::SchemaReferenceItem::update().

◆ setEdition()

void SchemaModel::setEdition ( bool  isEdition = true)

Definition at line 230 of file SchemaModel.cxx.

231 {
233 }

References _isEdition, and isEdition().

Referenced by YACS::HMI::GenericGui::createContext().

◆ setNewRoot()

void SchemaModel::setNewRoot ( YACS::HMI::Subject root)
protected

Definition at line 250 of file SchemaModel.cxx.

251 {
252  _root = root;
253  QString name = _root->getName().c_str();
255  SchemaProcItem *procItem = new SchemaProcItem(_rootItem, name, _root);
256 }
static QtGuiContext * getQtCurrent()
friend class SchemaItem
Definition: SchemaModel.hxx:53

References _root, _rootItem, YACS::HMI::Subject::getName(), YACS::HMI::QtGuiContext::getQtCurrent(), and SchemaItem.

Referenced by update().

◆ signalSelection

void YACS::HMI::SchemaModel::signalSelection ( const QModelIndex &  index)
signal

Referenced by updateSelection().

◆ stdBackBrush()

const QBrush & SchemaModel::stdBackBrush ( )

Definition at line 235 of file SchemaModel.cxx.

236 {
237  return _stdBackBrush;
238 }

References _stdBackBrush.

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

◆ supportedDropActions()

Qt::DropActions SchemaModel::supportedDropActions ( ) const
virtual

Definition at line 303 of file SchemaModel.cxx.

304 {
305  //DEBTRACE("SchemaModel::supportedDropActions");
306  return Qt::CopyAction | Qt::MoveAction | Qt::LinkAction;
307 }

◆ update()

void SchemaModel::update ( GuiEvent  event,
int  type,
Subject son 
)
virtual

Reimplemented from YACS::HMI::GuiObserver.

Definition at line 192 of file SchemaModel.cxx.

193 {
194  DEBTRACE("SchemaModel::update "<<eventName(event)<<" "<<type<<" "<<son);
195  switch (event)
196  {
197  case YACS::HMI::NEWROOT:
198  setNewRoot(son);
199  break;
200 // default:
201 // DEBTRACE("SchemaModel::update(), event not handled: "<< eventName(event));
202  }
203 }
static std::string eventName(GuiEvent event)
void setNewRoot(YACS::HMI::Subject *root)

References DEBTRACE, YACS::HMI::GuiObserver::eventName(), YACS::HMI::NEWROOT, and setNewRoot().

Referenced by gui.graph.MyCanvas::customEvent().

◆ updateSelection

void SchemaModel::updateSelection ( const QItemSelection &  selected,
const QItemSelection &  deselected 
)
slot

Definition at line 205 of file SchemaModel.cxx.

207 {
208  DEBTRACE("SchemaModel::updateSelection");
209  QModelIndex index;
210  QModelIndexList items = selected.indexes();
211 
212  foreach (index, items)
213  {
214  SchemaItem *item = static_cast<SchemaItem*>(index.internalPointer());
215  DEBTRACE("updateSelection select "<< item->getSubject()->getName());
216  item->getSubject()->select(true);
217  emit signalSelection(index);
218  }
219 
220  items = deselected.indexes();
221 
222  foreach (index, items)
223  {
224  SchemaItem *item = static_cast<SchemaItem*>(index.internalPointer());
225  DEBTRACE("updateSelection deselect "<< item->getSubject()->getName());
226  item->getSubject()->select(false);
227  }
228 }
void signalSelection(const QModelIndex &index)
virtual void select(bool isSelected)

References DEBTRACE, YACS::HMI::Subject::getName(), YACS::HMI::SchemaItem::getSubject(), index(), YACS::HMI::Subject::select(), and signalSelection().

Friends And Related Function Documentation

◆ SchemaComponentItem

friend class SchemaComponentItem
friend

Definition at line 60 of file SchemaModel.hxx.

◆ SchemaComposedNodeItem

friend class SchemaComposedNodeItem
friend

Definition at line 55 of file SchemaModel.hxx.

◆ SchemaContainerItem

friend class SchemaContainerItem
friend

Definition at line 59 of file SchemaModel.hxx.

◆ SchemaDirContainersItem

friend class SchemaDirContainersItem
friend

Definition at line 58 of file SchemaModel.hxx.

◆ SchemaDirLinksItem

friend class SchemaDirLinksItem
friend

Definition at line 57 of file SchemaModel.hxx.

◆ SchemaDirTypesItem

friend class SchemaDirTypesItem
friend

Definition at line 56 of file SchemaModel.hxx.

◆ SchemaItem

friend class SchemaItem
friend

Definition at line 53 of file SchemaModel.hxx.

Referenced by setNewRoot().

◆ SchemaNodeItem

friend class SchemaNodeItem
friend

Definition at line 54 of file SchemaModel.hxx.

Member Data Documentation

◆ _context

Subject* YACS::HMI::SchemaModel::_context
protected

Definition at line 101 of file SchemaModel.hxx.

Referenced by SchemaModel().

◆ _editedBackBrush

QBrush YACS::HMI::SchemaModel::_editedBackBrush
protected

Definition at line 106 of file SchemaModel.hxx.

Referenced by editedBackBrush(), and SchemaModel().

◆ _emphasizeBackBrush

QBrush YACS::HMI::SchemaModel::_emphasizeBackBrush
protected

Definition at line 107 of file SchemaModel.hxx.

Referenced by emphasizeBackBrush(), and SchemaModel().

◆ _isEdition

bool YACS::HMI::SchemaModel::_isEdition
protected

Definition at line 108 of file SchemaModel.hxx.

Referenced by columnCount(), headerData(), isEdition(), SchemaModel(), and setEdition().

◆ _root

Subject* YACS::HMI::SchemaModel::_root
protected

Definition at line 102 of file SchemaModel.hxx.

Referenced by mimeData(), SchemaModel(), and setNewRoot().

◆ _rootItem

SchemaItem* YACS::HMI::SchemaModel::_rootItem
protected

Definition at line 103 of file SchemaModel.hxx.

Referenced by columnCount(), getRootItem(), index(), parent(), rowCount(), SchemaModel(), and setNewRoot().

◆ _stdBackBrush

QBrush YACS::HMI::SchemaModel::_stdBackBrush
protected

Definition at line 105 of file SchemaModel.hxx.

Referenced by SchemaModel(), and stdBackBrush().


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