Version: 8.3.0
YACS::HMI::TreeView Class Reference

#include <TreeView.hxx>

Inheritance diagram for YACS::HMI::TreeView:
Collaboration diagram for YACS::HMI::TreeView:

Public Slots

void viewSelection (const QModelIndex &ind)
 
void resizeColumns ()
 
virtual void onCommitData (QWidget *editor)
 

Public Member Functions

 TreeView (QWidget *parent=0)
 
virtual ~TreeView ()
 
virtual void setModel (QAbstractItemModel *model)
 

Protected Member Functions

virtual bool event (QEvent *event)
 
void contextMenuEvent (QContextMenuEvent *event)
 

Protected Attributes

bool _isEdition
 
ValueDelegate_valueDelegate
 

Detailed Description

Definition at line 33 of file TreeView.hxx.

Constructor & Destructor Documentation

TreeView::TreeView ( QWidget parent = 0)

Definition at line 41 of file TreeView.cxx.

References _isEdition, _valueDelegate, onCommitData(), YACS::HMI::YLabel, and YACS::HMI::YValue.

42  : QTreeView(parent)
43 {
44  setDragDropMode(QAbstractItemView::DragDrop);
45  setDragEnabled(true);
46  setAcceptDrops(true);
47  setDropIndicatorShown(true);
48  _isEdition = true;
49 
50  _valueDelegate = new ValueDelegate(parent);
51 
52  connect(_valueDelegate, SIGNAL(commitData(QWidget*)),
53  this, SLOT(onCommitData(QWidget*)));
54 
55  setItemDelegateForColumn(YLabel, _valueDelegate); // --- port label
56  setItemDelegateForColumn(YValue, _valueDelegate); // --- port value
57 }
TreeView::~TreeView ( )
virtual

Definition at line 59 of file TreeView.cxx.

60 {
61 }

Member Function Documentation

void TreeView::contextMenuEvent ( QContextMenuEvent *  event)
protected

Definition at line 123 of file TreeView.cxx.

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

124 {
125  QModelIndexList selList = selectedIndexes();
126  if (selList.isEmpty())
127  return;
128  QModelIndex selected = selList.front();
129  if (selected.isValid())
130  {
131  SchemaItem* item = static_cast<SchemaItem*>(selected.internalPointer());
132  item->popupMenu(this, event->globalPos());
133  }
134 }
bool TreeView::event ( QEvent event)
protectedvirtual

Definition at line 99 of file TreeView.cxx.

References YACS::HMI::QtGuiContext::getGMain(), YACS::HMI::QtGuiContext::getQtCurrent(), and YACS::HMI::GenericGui::onHelpContextModule().

100 {
101  if (event->type() == QEvent::WhatsThisClicked)
102  {
103  QWhatsThisClickedEvent* clicked = static_cast<QWhatsThisClickedEvent*>(event);
104  QtGuiContext::getQtCurrent()->getGMain()->onHelpContextModule("YACS",clicked->href());
105  return true; // what's this remains open if true is returned
106  }
107 
108  if (event->type() == QEvent::ToolTip)
109  {
110  QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
111  QModelIndex index = indexAt(helpEvent->pos());
112  if (index.isValid())
113  {
114  QString valtip = model()->data(index, Qt::ToolTipRole).toString();
115  QToolTip::showText(helpEvent->globalPos(), valtip);
116  }
117  else
118  QToolTip::hideText();
119  }
120  return QTreeView::event(event);
121 }
void TreeView::onCommitData ( QWidget editor)
virtualslot

After edition with a specific editor created by ValueDelegate for a cell of Tree item, the resulting string is tested for setValue on the corresponding subject. Result of the setValue (succes or failure) is transmitted to ValueDelegate for further action in case of failure.

Definition at line 143 of file TreeView.cxx.

References _valueDelegate, DEBTRACE, YACS::ENGINE::DataPort::edGetType(), YACS::HMI::GenericEditor::getColumnInSubject(), YACS::HMI::QtGuiContext::getGuiExecutor(), YACS::HMI::Subject::getParent(), YACS::HMI::SubjectDataPort::getPort(), YACS::HMI::QtGuiContext::getQtCurrent(), YACS::HMI::GenericEditor::GetStrValue(), YACS::HMI::GenericEditor::getSubject(), YACS::ENGINE::TypeCode::kind(), YACS::HMI::SubjectSwitch::setCase(), YACS::HMI::GuiExecutor::setInPortValue(), YACS::HMI::SubjectDataPort::setName(), YACS::HMI::ValueDelegate::setResultEditing(), YACS::HMI::SubjectDataPort::setValue(), YACS::ENGINE::String, YASSERT, and YACS::HMI::YValue.

Referenced by TreeView().

144 {
145  DEBTRACE("TreeView::onCommitData " << editor);
146  GenericEditor* gedit = dynamic_cast<GenericEditor*>(editor);
147  YASSERT(gedit);
148  QString val = gedit->GetStrValue();
149  string strval = val.toStdString();
150  DEBTRACE(strval);
151  bool isOk = false;
152 
153  Subject *sub = gedit->getSubject();
154  YASSERT(sub);
155  SubjectDataPort *sdp = dynamic_cast<SubjectDataPort*>(sub);
156  if (sdp)
157  {
158  if (gedit->getColumnInSubject() == YValue)
159  {
160  if (sdp->getPort()->edGetType()->kind() == YACS::ENGINE::String)
161  strval = "\"" + strval + "\"";
162  DEBTRACE(strval);
163  isOk = sdp->setValue(strval);
164 
166  if (executor) executor->setInPortValue(sdp->getPort(), strval);
167  }
168  else // --- YLabel
169  {
170  isOk = sdp->setName(strval);
171  }
172  }
173  else
174  {
175  SubjectNode *snode = dynamic_cast<SubjectNode*>(sub);
176  YASSERT(snode);
177  sub = snode->getParent();
178  SubjectSwitch *sswitch = dynamic_cast<SubjectSwitch*>(sub);
179  YASSERT(sswitch);
180  isOk = sswitch->setCase(strval, snode);
181  }
182 
183  if (_valueDelegate)
184  _valueDelegate->setResultEditing(editor, isOk);
185  }
void TreeView::resizeColumns ( )
slot

Definition at line 77 of file TreeView.cxx.

References _isEdition, YACS::HMI::QtGuiContext::_mapOfSchemaItem, YACS::HMI::QtGuiContext::getQtCurrent(), YACS::HMI::GuiContext::getSubjectProc(), YACS::HMI::SchemaItem::modelIndex(), YACS::HMI::YState, YACS::HMI::YType, and YACS::HMI::YValue.

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

78 {
81  QModelIndex index = item->modelIndex();
82  setExpanded(index, true);
83  resizeColumnToContents(0);
84  if (_isEdition)
85  {
86  setColumnHidden(YType, false);
87  setColumnHidden(YValue, false);
88  setColumnWidth(YType, 100);
89  setColumnWidth(YValue, 100);
90  }
91  else
92  {
93  setColumnHidden(YType, true);
94  setColumnHidden(YState, false);
95  setColumnWidth(YState, 100);
96  }
97 }
void TreeView::setModel ( QAbstractItemModel model)
virtual

Definition at line 63 of file TreeView.cxx.

References _isEdition, DEBTRACE, YACS::HMI::QtGuiContext::getQtCurrent(), and YACS::HMI::QtGuiContext::isEdition().

64 {
65  QTreeView::setModel(model);
67  DEBTRACE("_isEdition=" << _isEdition);
68 }
void TreeView::viewSelection ( const QModelIndex &  ind)
slot

Definition at line 70 of file TreeView.cxx.

71 {
72  QModelIndex ind0 = ind.sibling(ind.row(), 0);
73  //DEBTRACE("TreeView::viewSelection " << ind.row() << " " << ind.column() << " / " << ind0.row() << " " << ind0.column());
74  scrollTo(ind0);
75 }

Member Data Documentation

bool YACS::HMI::TreeView::_isEdition
protected

Definition at line 50 of file TreeView.hxx.

Referenced by resizeColumns(), setModel(), and TreeView().

ValueDelegate* YACS::HMI::TreeView::_valueDelegate
protected

Definition at line 51 of file TreeView.hxx.

Referenced by onCommitData(), and TreeView().


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