Version: 8.3.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 ( YACS::HMI::Subject context,
QObject parent = 0 
)

Definition at line 39 of file SchemaModel.cxx.

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

40  :
41  QAbstractItemModel(parent)
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 }
SchemaModel::~SchemaModel ( )
virtual

Definition at line 54 of file SchemaModel.cxx.

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

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

Member Function Documentation

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

Definition at line 107 of file SchemaModel.cxx.

References _isEdition, and _rootItem.

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 }
QVariant SchemaModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
virtual

Definition at line 121 of file SchemaModel.cxx.

References YACS::HMI::SchemaItem::data().

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 }
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.

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

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 }
const QBrush & SchemaModel::editedBackBrush ( )

Definition at line 240 of file SchemaModel.cxx.

References _editedBackBrush.

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

241 {
242  return _editedBackBrush;
243 }
const QBrush & SchemaModel::emphasizeBackBrush ( )

Definition at line 245 of file SchemaModel.cxx.

References _emphasizeBackBrush.

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

246 {
247  return _emphasizeBackBrush;
248 }
Qt::ItemFlags SchemaModel::flags ( const QModelIndex &  index) const
virtual

Definition at line 182 of file SchemaModel.cxx.

References YACS::HMI::SchemaItem::flags().

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 }
SchemaItem* YACS::HMI::SchemaModel::getRootItem ( )
inline

Definition at line 78 of file SchemaModel.hxx.

References _rootItem.

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

78 {return _rootItem; };
QVariant SchemaModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
virtual

Definition at line 130 of file SchemaModel.cxx.

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

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 }
QModelIndex SchemaModel::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const
virtual

Definition at line 60 of file SchemaModel.cxx.

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

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

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 }
bool YACS::HMI::SchemaModel::isEdition ( )
inline
QMimeData * SchemaModel::mimeData ( const QModelIndexList &  indexes) const
virtual

Definition at line 258 of file SchemaModel.cxx.

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

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 }
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 }
QModelIndex SchemaModel::parent ( const QModelIndex &  index) const
virtual

Definition at line 80 of file SchemaModel.cxx.

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

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 }
int SchemaModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 92 of file SchemaModel.cxx.

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

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

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 }
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.

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

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

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 }
void SchemaModel::setEdition ( bool  isEdition = true)

Definition at line 230 of file SchemaModel.cxx.

References _isEdition, and isEdition().

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

231 {
233 }
void SchemaModel::setNewRoot ( YACS::HMI::Subject root)
protected

Definition at line 250 of file SchemaModel.cxx.

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

Referenced by update().

251 {
252  _root = root;
253  QString name = _root->getName().c_str();
255  SchemaProcItem *procItem = new SchemaProcItem(_rootItem, name, _root);
256 }
void YACS::HMI::SchemaModel::signalSelection ( const QModelIndex &  index)
signal

Referenced by updateSelection().

const QBrush & SchemaModel::stdBackBrush ( )

Definition at line 235 of file SchemaModel.cxx.

References _stdBackBrush.

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

236 {
237  return _stdBackBrush;
238 }
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 }
void SchemaModel::update ( GuiEvent  event,
int  type,
Subject son 
)
virtual

Reimplemented from YACS::HMI::GuiObserver.

Definition at line 192 of file SchemaModel.cxx.

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

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

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 }
void SchemaModel::updateSelection ( const QItemSelection &  selected,
const QItemSelection &  deselected 
)
slot

Definition at line 205 of file SchemaModel.cxx.

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

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 }

Friends And Related Function Documentation

friend class SchemaComponentItem
friend

Definition at line 60 of file SchemaModel.hxx.

friend class SchemaComposedNodeItem
friend

Definition at line 55 of file SchemaModel.hxx.

friend class SchemaContainerItem
friend

Definition at line 59 of file SchemaModel.hxx.

friend class SchemaDirContainersItem
friend

Definition at line 58 of file SchemaModel.hxx.

friend class SchemaDirLinksItem
friend

Definition at line 57 of file SchemaModel.hxx.

friend class SchemaDirTypesItem
friend

Definition at line 56 of file SchemaModel.hxx.

friend class SchemaItem
friend

Definition at line 53 of file SchemaModel.hxx.

Referenced by setNewRoot().

friend class SchemaNodeItem
friend

Definition at line 54 of file SchemaModel.hxx.

Member Data Documentation

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

Definition at line 101 of file SchemaModel.hxx.

Referenced by SchemaModel().

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

Definition at line 106 of file SchemaModel.hxx.

Referenced by editedBackBrush(), and SchemaModel().

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

Definition at line 107 of file SchemaModel.hxx.

Referenced by emphasizeBackBrush(), and SchemaModel().

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

Definition at line 108 of file SchemaModel.hxx.

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

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

Definition at line 102 of file SchemaModel.hxx.

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

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

Definition at line 103 of file SchemaModel.hxx.

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

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: