1 // Copyright (C) 2006-2008 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "SchemaOutPortItem.hxx"
20 #include "ItemMimeData.hxx"
21 #include "QtGuiContext.hxx"
24 #include "commandsProc.hxx"
25 #include "DataPort.hxx"
26 #include "TypeCode.hxx"
27 #include "InputPort.hxx"
28 #include "OutputPort.hxx"
29 #include "PresetNode.hxx"
30 #include "DataNode.hxx"
31 #include "InlineNode.hxx"
36 #include "YacsTrace.hxx"
39 using namespace YACS::ENGINE;
40 using namespace YACS::HMI;
42 /*! column 1: YLabel = name, set in SchemaItem,
43 * column 2: YType = data type, never editable,
44 * column 3: YValue = value
46 SchemaOutPortItem::SchemaOutPortItem(SchemaItem *parent, QString label, Subject* subject)
47 : SchemaItem::SchemaItem(parent, label, subject)
49 SubjectDataPort *subPort = dynamic_cast<SubjectDataPort*>(subject);
52 DataPort *dport = subPort->getPort();
53 TypeOfElem typort = ProcInvoc::getTypeOfPort(dport);
54 // _itemData.replace(YType, dport->edGetType()->getKindRepr());
55 _itemData.replace(YType, dport->edGetType()->name());
56 _itemForeground.replace(YType, QColor("black"));
57 OutputPort * outport = 0;
61 case YACS::HMI::OUTPUTPORT:
62 _itemDeco.replace(YLabel, QIcon("icons:out_port.png"));
63 outport = dynamic_cast<OutputPort*>(dport);
64 _itemData.replace(YValue, outport->getAsString().c_str());
66 case YACS::HMI::OUTPUTDATASTREAMPORT:
67 _itemDeco.replace(YLabel, QIcon("icons:out_port.png"));
68 _itemData.replace(YValue, "stream");
69 _itemForeground.replace(YValue, QColor("grey"));
70 //_itemDeco.replace(YValue, QColor("grey"));
76 void SchemaOutPortItem::update(GuiEvent event, int type, Subject* son)
78 DEBTRACE("SchemaOutPortItem::update");
79 SchemaItem::update(event, type, son);
80 QModelIndex index = QModelIndex();
81 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
86 SubjectOutputPort *sop = dynamic_cast<SubjectOutputPort*>(son);
89 DataFlowPort *port = dynamic_cast<DataFlowPort*>(sop->getPort());
90 DEBTRACE(port->getAsString());
91 _itemData.replace(YValue, port->getAsString().c_str());
92 _itemForeground.replace(YValue, QColor("green"));
93 model->setData(modelIndex(YValue), 0); // --- to emit dataChanged signal
99 SubjectOutputPort *sip = dynamic_cast<SubjectOutputPort*>(son);
102 _itemData.replace(YValue, sip->getExecValue().c_str());
103 _itemForeground.replace(YValue, QColor("darkMagenta"));
104 model->setData(modelIndex(YValue), 0); // --- to emit dataChanged signal
111 Qt::ItemFlags SchemaOutPortItem::flags(const QModelIndex &index)
113 //DEBTRACE("SchemaOutPortItem::flags");
114 Qt::ItemFlags pflag = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
115 if (! QtGuiContext::getQtCurrent()->isEdition())
118 Qt::ItemFlags flagEdit = 0;
119 int column = index.column();
124 SubjectDataPort *sdp = dynamic_cast<SubjectDataPort*>(_subject);
125 Node *parent = sdp->getPort()->getNode();
127 if (dynamic_cast<DataNode*>(parent) || dynamic_cast<InlineNode*>(parent))
128 flagEdit = Qt::ItemIsEditable; // --- port name editable
132 SubjectDataPort *sdp = dynamic_cast<SubjectDataPort*>(_subject);
133 Node *node = sdp->getPort()->getNode();
134 PresetNode *pnode = dynamic_cast<PresetNode*>(node);
136 flagEdit = Qt::ItemIsEditable; // --- port value editable for preset node
139 return pflag | flagEdit;
142 void SchemaOutPortItem::popupMenu(QWidget *caller, const QPoint &globalPos)
145 m.popupMenu(caller, globalPos);
148 QString SchemaOutPortItem::getMimeFormat()
150 return "yacs/subjectOutPort";