36 using namespace YACS::HMI;
41 DEBTRACE(
"SchemaItem::SchemaItem " << label.toStdString() <<
" " <<
this);
46 _itemData << QVariant() << QVariant() << QVariant();
47 _itemDeco << QVariant() << QVariant() << QVariant();
48 _itemForeground << QVariant() << QVariant() << QVariant();
49 _itemBackground << QVariant() << QVariant() << QVariant();
50 _itemCheckState << QVariant() << QVariant() << QVariant();
51 _itemToolTip << QVariant() << QVariant() << QVariant();
52 _itemWhatsThis << QVariant() << QVariant() << QVariant();
53 _itemData.replace(
YLabel, label);
54 _itemToolTip.replace(
YLabel, label);
55 _itemWhatsThis.replace(
YLabel, QString(
"This is the default WhatsThis of ") + label);
57 _itemForeground.replace(
YLabel, QColor(
"blue"));
58 _itemBackground.replace(
YLabel, QtGuiContext::getQtCurrent()->getSchemaModel()->stdBackBrush());
63 _subject->attach(
this);
64 QtGuiContext::getQtCurrent()->_mapOfSchemaItem[_subject]=
this;
68 _parentItem->appendChild(
this);
73 SchemaItem::~SchemaItem()
75 DEBTRACE(
"SchemaItem::~SchemaItem " << _label.toStdString() <<
" " <<
this);
78 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
80 model->beginRemoveRows(_parentItem->modelIndex(), position, position);
81 if (_subject) QtGuiContext::getQtCurrent()->_mapOfSchemaItem.erase(_subject);
82 _parentItem->removeChild(
this);
83 model->endRemoveRows();
90 _childItems.append(child);
96 _childItems.removeAll(child);
101 DEBTRACE(
"SchemaItem::insertChild");
102 _childItems.insert(row, child);
108 return _childItems.value(row);
111 int SchemaItem::childCount()
const
114 return _childItems.count();
117 int SchemaItem::columnCount()
const
120 return _itemData.count();
123 QVariant SchemaItem::data(
int column,
int role)
const
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);
140 return runToolTip(column);
141 if (role == Qt::WhatsThisRole)
142 if (QtGuiContext::getQtCurrent()->isEdition())
143 return editionWhatsThis(column);
145 return runWhatsThis(column);
149 Qt::ItemFlags SchemaItem::flags(
const QModelIndex &index)
151 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
154 int SchemaItem::row()
const
159 row = _parentItem->_childItems.indexOf(const_cast<SchemaItem*>(
this));
177 QModelIndex index = QModelIndex();
178 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
182 DEBTRACE(
"SchemaItem::update RENAME " << _subject->getName());
183 _label = _subject->getName().c_str();
184 _itemData.replace(
YLabel, _label);
206 void SchemaItem::select(
bool isSelected)
208 DEBTRACE(
"SchemaItem::select " << _label.toStdString() <<
" " << isSelected);
209 QItemSelectionModel* selectionModel = QtGuiContext::getQtCurrent()->getSelectionModel();
210 QModelIndex anIndex = modelIndex();
211 QItemSelection newSelection(anIndex, anIndex);
215 if (!QtGuiContext::getQtCurrent()->_mapOfEditionItem.count(_subject))
217 int elemType = _subject->getType();
221 QtGuiContext::getQtCurrent()->getEditionRoot()->update(event, elemType, _subject);
224 QtGuiContext::getQtCurrent()->getGMain()->raiseStacked();
225 QItemSelection currentSelected = selectionModel->selection();
226 if (currentSelected != newSelection)
228 DEBTRACE(
"currentSelected != newSelection");
230 selectionModel->select(newSelection, QItemSelectionModel::Clear);
231 selectionModel->select(newSelection, QItemSelectionModel::Select);
233 QtGuiContext::getQtCurrent()->setSelectedSubject(_subject);
236 selectionModel->select(newSelection, QItemSelectionModel::Deselect);
239 void SchemaItem::toggleState()
241 if (_itemCheckState.value(
YLabel) == Qt::Unchecked)
243 DEBTRACE(
"SchemaItem::toggleState true");
244 _itemCheckState.replace(
YLabel, Qt::Checked);
248 DEBTRACE(
"SchemaItem::toggleState false");
249 _itemCheckState.replace(
YLabel, Qt::Unchecked);
253 QModelIndex SchemaItem::modelIndex(
int column)
256 SchemaModel *schema = QtGuiContext::getQtCurrent()->getSchemaModel();
257 if (_parentItem && (_parentItem !=schema->
getRootItem()))
258 return schema->
index(row(),
260 _parentItem->modelIndex());
262 return schema->
index(row(),
267 void SchemaItem::popupMenu(
QWidget *caller,
const QPoint &globalPos)
280 mime->setData(getMimeFormat(),
"_subject");
284 bool SchemaItem::dropMimeData(
const QMimeData* data, Qt::DropAction action)
291 _parentItem = parent;
297 void SchemaItem::setCaseValue()
301 QVariant SchemaItem::editionToolTip(
int column)
const
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;
311 QVariant SchemaItem::runToolTip(
int column)
const
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;
321 QVariant SchemaItem::editionWhatsThis(
int column)
const
323 QString val = QString(
"Edition help: ") + _itemWhatsThis.value(column).toString();
327 QVariant SchemaItem::runWhatsThis(
int column)
const
329 QString val = QString(
"Execution help: ") + _itemWhatsThis.value(column).toString();
333 QString SchemaItem::getMimeFormat()
335 return "yacs/subject";
338 void SchemaItem::setExecState(
int execState)
340 DEBTRACE(
"SchemaItem::setExecState " << execState);
341 _execState = execState;
363 default: sc = Resource::DEFAULT ; stateDef =
"---" ;
365 _itemData.replace(
YState, stateDef);
366 _itemForeground.replace(
YState, sc);