Version: 9.16.0
YACS::HMI::ValueDelegate Class Reference

#include <ValueDelegate.hxx>

Inheritance diagram for YACS::HMI::ValueDelegate:
Collaboration diagram for YACS::HMI::ValueDelegate:

Public Member Functions

 ValueDelegate (QObject *parent=0)
 
virtual ~ValueDelegate ()
 
virtual QWidgetcreateEditor (QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
 
virtual void setEditorData (QWidget *editor, const QModelIndex &index) const
 
virtual void setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
 
virtual void updateEditorGeometry (QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
 
virtual void setResultEditing (QWidget *editor, bool isOk)
 

Protected Attributes

std::map< Subject *, std::string > _errorMap
 

Detailed Description

Definition at line 116 of file ValueDelegate.hxx.

Constructor & Destructor Documentation

◆ ValueDelegate()

ValueDelegate::ValueDelegate ( QObject parent = 0)

Definition at line 245 of file ValueDelegate.cxx.

246 : QItemDelegate(parent)
247{
248 DEBTRACE("ValueDelegate::ValueDelegate");
249 _errorMap.clear();
250}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
std::map< Subject *, std::string > _errorMap

References _errorMap, and DEBTRACE.

◆ ~ValueDelegate()

ValueDelegate::~ValueDelegate ( )
virtual

Definition at line 252 of file ValueDelegate.cxx.

253{
254 DEBTRACE("ValueDelegate::~ValueDelegate");
255}

References DEBTRACE.

Member Function Documentation

◆ createEditor()

QWidget * ValueDelegate::createEditor ( QWidget parent,
const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const
virtual

Definition at line 257 of file ValueDelegate.cxx.

260{
261 DEBTRACE("ValueDelegate::createEditor");
262
263 SchemaItem *item = static_cast<SchemaItem*>(index.internalPointer());
264 Subject *subject = item->getSubject();
265 int column = index.column();
266 DEBTRACE(subject->getName() << " " << column);
267
268 QWidget *editor = 0;
269 SubjectDataPort *sport = 0;
270 SubjectNode *snode = 0;
271
272 if (column == YValue)
273 {
274 sport = dynamic_cast<SubjectDataPort*>(subject);
275 if (!sport)
276 snode= dynamic_cast<SubjectNode*>(subject);
277
278 if (sport)
279 {
280 YACS::ENGINE::DataPort *port = sport->getPort();
283 YACS::ENGINE::TypeCode *tc = port->edGetType();
284 YACS::ENGINE::DynType dt = tc->kind();
285 if (!istport && !ostport && dt == YACS::ENGINE::Int)
286 editor = new IntEditor(subject, this, column, parent);
287 }
288 else if (snode)
289 {
290 SubjectSwitch *sSwitch = dynamic_cast<SubjectSwitch*>(snode->getParent());
291 if (sSwitch)
292 editor = new CaseSwitchEditor(subject, this, column, parent);
293 }
294 }
295
296 if (column == YLabel)
297 {
298 sport = dynamic_cast<SubjectDataPort*>(subject);
299 if (sport)
300 editor = new NameEditor(subject, this, column, parent);
301 }
302
303 if (!editor) editor = new GeneralEditor(subject, this, column, parent);
304 return editor;
305}
TypeCode * edGetType() const
Definition: DataPort.hxx:53
Class for Study input Ports.
Definition: StudyPorts.hxx:51
Class for Study output Ports.
Definition: StudyPorts.hxx:33
Base class for all type objects.
Definition: TypeCode.hxx:68
DynType kind() const
Definition: TypeCode.cxx:47
virtual Subject * getSubject()
Definition: SchemaItem.cxx:169
virtual YACS::ENGINE::DataPort * getPort()
virtual Subject * getParent()
virtual std::string getName()

References DEBTRACE, YACS::ENGINE::DataPort::edGetType(), YACS::HMI::Subject::getName(), YACS::HMI::Subject::getParent(), YACS::HMI::SubjectDataPort::getPort(), YACS::HMI::SchemaItem::getSubject(), YACS::ENGINE::Int, YACS::ENGINE::TypeCode::kind(), YACS::HMI::YLabel, and YACS::HMI::YValue.

◆ setEditorData()

void ValueDelegate::setEditorData ( QWidget editor,
const QModelIndex &  index 
) const
virtual

Initialise the editor with data from model, unless there is a previous error in edition of this item, and it is the first initialisation of the editor: in case of error, a new editor must be initialised with the wrong edited string, for correction.

Definition at line 313 of file ValueDelegate.cxx.

315{
316 DEBTRACE("ValueDelegate::setEditorData");
317 GenericEditor* gedit = dynamic_cast<GenericEditor*>(editor);
318 YASSERT(gedit);
319 QString edited = gedit->GetStrValue();
320 DEBTRACE(edited.toStdString());
321 Subject *sub = gedit->getSubject();
322 if (! gedit->firstSetData()) // --- editor already initialized
323 return;
324 else if (_errorMap.count(sub)) // --- initialize with previous error
325 {
326 string error = _errorMap[sub];
327 gedit->setData(QString(error.c_str()));
328 _errorMap.erase(gedit->getSubject());
329 DEBTRACE("--------erase-----------");
330 }
331 else // --- initialize with model
332 gedit->setData(index.model()->data(index, Qt::DisplayRole));
333}
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
Definition: YacsTrace.hxx:59
virtual Subject * getSubject()
virtual void setData(QVariant val)
virtual bool firstSetData()
virtual QString GetStrValue()

References _errorMap, DEBTRACE, YACS::HMI::GenericEditor::firstSetData(), YACS::HMI::GenericEditor::GetStrValue(), YACS::HMI::GenericEditor::getSubject(), YACS::HMI::GenericEditor::setData(), and YASSERT.

◆ setModelData()

void ValueDelegate::setModelData ( QWidget editor,
QAbstractItemModel model,
const QModelIndex &  index 
) const
virtual

Nothing done here: model->setData is done by UPDATE.

Definition at line 338 of file ValueDelegate.cxx.

341{
342 DEBTRACE("ValueDelegate::setModelData");
343 GenericEditor* gedit = dynamic_cast<GenericEditor*>(editor);
344 YASSERT(gedit);
345 QString value = gedit->GetStrValue();
346 DEBTRACE(value.toStdString());
347 //model->setData(index, value, Qt::EditRole); // real set done by update
348}

References DEBTRACE, YACS::HMI::GenericEditor::GetStrValue(), and YASSERT.

◆ setResultEditing()

void ValueDelegate::setResultEditing ( QWidget editor,
bool  isOk 
)
virtual

If edition is in error, keep the wrong string value in a map, to initialise a next instance of editor with the wrong string, in order to help correction of the edition.

Definition at line 363 of file ValueDelegate.cxx.

364{
365 DEBTRACE("ValueDelegate::setResultEditing " << isOk);
366 GenericEditor* gedit = dynamic_cast<GenericEditor*>(editor);
367 YASSERT(gedit);
368 Subject *sub = gedit->getSubject();
369 string val = gedit->GetStrValue().toStdString();
370 DEBTRACE(sub->getName() << " " << val);
371 if (!isOk)
372 {
373 sub->update(EDIT, 1, sub);
374 _errorMap[sub] = val;
375 }
376 else
377 sub->update(EDIT, 0, sub);
378}
virtual void update(GuiEvent event, int type, Subject *son)

References _errorMap, DEBTRACE, YACS::HMI::EDIT, YACS::HMI::Subject::getName(), YACS::HMI::GenericEditor::GetStrValue(), YACS::HMI::GenericEditor::getSubject(), YACS::HMI::Subject::update(), and YASSERT.

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

◆ updateEditorGeometry()

void ValueDelegate::updateEditorGeometry ( QWidget editor,
const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const
virtual

Definition at line 350 of file ValueDelegate.cxx.

353{
354 DEBTRACE("ValueDelegate::updateEditorGeometry");
355 editor->setGeometry(option.rect);
356}

References DEBTRACE.

Member Data Documentation

◆ _errorMap

std::map<Subject*, std::string> YACS::HMI::ValueDelegate::_errorMap
mutableprotected

Definition at line 140 of file ValueDelegate.hxx.

Referenced by setEditorData(), setResultEditing(), and ValueDelegate().


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