Version: 9.16.0
YACS::HMI::CatalogWidget Class Reference

#include <CatalogWidget.hxx>

Inheritance diagram for YACS::HMI::CatalogWidget:
Collaboration diagram for YACS::HMI::CatalogWidget:

Public Member Functions

 CatalogWidget (QWidget *parent, YACS::ENGINE::Catalog *builtinCatalog, YACS::ENGINE::Catalog *sessionCatalog)
 
virtual ~CatalogWidget ()
 
virtual bool addCatalogFromFile (std::string fileName)
 
virtual std::map< std::string, YACS::ENGINE::Catalog * > getCataMap ()
 
virtual YACS::ENGINE::CataloggetCatalog (std::string cataName)
 
virtual YACS::ENGINE::CataloggetCatalogFromType (std::string typeName)
 
virtual void mousePressEvent (QMouseEvent *event)
 

Protected Member Functions

virtual void addCatalog (YACS::ENGINE::Catalog *catalog, std::string name)
 
virtual void startDrag (Qt::DropActions supportedActions)
 

Protected Attributes

YACS::ENGINE::Catalog_builtinCatalog
 
YACS::ENGINE::Catalog_sessionCatalog
 
int _idCatalog
 
std::map< std::string, YACS::ENGINE::Catalog * > _cataMap
 
std::map< std::string, YACS::ENGINE::Catalog * > _typeToCataMap
 
bool _dragModifier
 

Detailed Description

Definition at line 37 of file CatalogWidget.hxx.

Constructor & Destructor Documentation

◆ CatalogWidget()

CatalogWidget::CatalogWidget ( QWidget parent,
YACS::ENGINE::Catalog builtinCatalog,
YACS::ENGINE::Catalog sessionCatalog 
)

Definition at line 47 of file CatalogWidget.cxx.

50 : QTreeWidget(parent)
51{
52 DEBTRACE("CatalogWidget::CatalogWidget");
53 _builtinCatalog = builtinCatalog;
54 _sessionCatalog = sessionCatalog;
55
56 _idCatalog = 0;
57 _cataMap.clear();
58 _typeToCataMap.clear();
59 _dragModifier=false;
60
61 setColumnCount(1);
62 setHeaderHidden( true );
63
64 addCatalog(_builtinCatalog, "Built In");
65 addCatalog(_sessionCatalog, "Current Session");
66
67 setDragDropMode(QAbstractItemView::DragOnly);
68 setDragEnabled(true);
69 setDropIndicatorShown(true);
70
71 setSelectionMode(QAbstractItemView::ExtendedSelection);
72}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
std::map< std::string, YACS::ENGINE::Catalog * > _cataMap
YACS::ENGINE::Catalog * _builtinCatalog
YACS::ENGINE::Catalog * _sessionCatalog
std::map< std::string, YACS::ENGINE::Catalog * > _typeToCataMap
virtual void addCatalog(YACS::ENGINE::Catalog *catalog, std::string name)

References _builtinCatalog, _cataMap, _dragModifier, _idCatalog, _sessionCatalog, _typeToCataMap, addCatalog(), and DEBTRACE.

◆ ~CatalogWidget()

CatalogWidget::~CatalogWidget ( )
virtual

Definition at line 177 of file CatalogWidget.cxx.

178{
179}

Member Function Documentation

◆ addCatalog()

void CatalogWidget::addCatalog ( YACS::ENGINE::Catalog catalog,
std::string  name 
)
protectedvirtual

Definition at line 108 of file CatalogWidget.cxx.

110{
111 if (!catalog) return;
112
113 QTreeWidgetItem *itemCata = 0;
114 QTreeWidgetItem *category = 0;
115
116 itemCata = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString(name.c_str())));
117 insertTopLevelItem(_idCatalog, itemCata);
118 _idCatalog++;
119
120 if (! catalog->_typeMap.empty())
121 {
122 category = new QTreeWidgetItem(itemCata, QStringList(QString("Types")));
123 map<string, TypeCode*>::const_iterator it = catalog->_typeMap.begin();
124 for (; it != catalog->_typeMap.end(); ++it)
125 {
126 DEBTRACE("Type : " <<(*it).first
127 << " " << (*it).second->getKindRepr()
128 << " " << (*it).second->name()
129 << " " << (*it).second->shortName()
130 << " " << (*it).second->id() );
131 string typeName = it->first;
132 QTreeWidgetItem *item = new QTreeWidgetItem(category, QStringList(QString(typeName.c_str())));
133 if (! _typeToCataMap.count(typeName))
134 _typeToCataMap[typeName] = catalog;
135 else if ( ! ((*it).second)->isEquivalent(_typeToCataMap[typeName]->_typeMap[typeName]) )
136 {
137 DEBTRACE(" ========================================================================================================");
138 DEBTRACE(" type " << typeName << " not compatible with one of same name already present in another catalog, FORCE NEW!");
139 DEBTRACE(" ========================================================================================================");
140 _typeToCataMap[typeName] = catalog;
141 item->setForeground(0,Qt::blue);
142 }
143 }
144 }
145
146 if (! catalog->_componentMap.empty())
147 {
148 category = new QTreeWidgetItem(itemCata, QStringList(QString("Components")));
149 map<string, ComponentDefinition*>::const_iterator it = catalog->_componentMap.begin();
150 for (; it != catalog->_componentMap.end(); ++it)
151 {
152 QTreeWidgetItem *item = new QTreeWidgetItem(category, QStringList(QString((it->first).c_str())));
153 map<string, ServiceNode *>::const_iterator its = (it->second)->_serviceMap.begin();
154 for (; its != (it->second)->_serviceMap.end(); ++its)
155 QTreeWidgetItem *sitem = new QTreeWidgetItem(item, QStringList(QString((its->first).c_str())));
156 }
157 }
158
159 if (! catalog->_nodeMap.empty())
160 {
161 category = new QTreeWidgetItem(itemCata, QStringList(QString("Elementary Nodes")));
162 map<string, Node*>::const_iterator it = catalog->_nodeMap.begin();
163 for (; it != catalog->_nodeMap.end(); ++it)
164 QTreeWidgetItem *item = new QTreeWidgetItem(category, QStringList(QString((it->first).c_str())));
165 }
166
167 if (! catalog->_composednodeMap.empty())
168 {
169 category = new QTreeWidgetItem(itemCata, QStringList(QString("Composed Nodes")));
170 map<string, ComposedNode*>::const_iterator it = catalog->_composednodeMap.begin();
171 for (; it != catalog->_composednodeMap.end(); ++it)
172 QTreeWidgetItem *item = new QTreeWidgetItem(category, QStringList(QString((it->first).c_str())));
173 }
174 _cataMap[name] = catalog;
175}
std::map< std::string, ComposedNode * > _composednodeMap
Definition: Catalog.hxx:52
std::map< std::string, ComponentDefinition * > _componentMap
Definition: Catalog.hxx:50
std::map< std::string, Node * > _nodeMap
Definition: Catalog.hxx:51
std::map< std::string, TypeCode * > _typeMap
Definition: Catalog.hxx:49

References _cataMap, YACS::ENGINE::Catalog::_componentMap, YACS::ENGINE::Catalog::_composednodeMap, _idCatalog, YACS::ENGINE::Catalog::_nodeMap, YACS::ENGINE::Catalog::_typeMap, _typeToCataMap, and DEBTRACE.

Referenced by addCatalogFromFile(), and CatalogWidget().

◆ addCatalogFromFile()

bool CatalogWidget::addCatalogFromFile ( std::string  fileName)
virtual

Definition at line 74 of file CatalogWidget.cxx.

75{
76 DEBTRACE("CatalogWidget::addCatalogFromFile " << fileName);
77 QFileInfo afi(fileName.c_str());
78 if(!afi.exists())
79 return false;
80 Catalog *cataProc = YACS::ENGINE::getSALOMERuntime()->loadCatalog("proc", fileName);
81 string aFile = afi.fileName().toStdString();
82 addCatalog(cataProc, aFile);
83 return true;
84}
class for YACS catalogs.
Definition: Catalog.hxx:42
virtual Catalog * loadCatalog(const std::string &sourceKind, const std::string &path)
Load a catalog of calculation to use as factory.
Definition: Runtime.cxx:285
YACSRUNTIMESALOME_EXPORT RuntimeSALOME * getSALOMERuntime()

References addCatalog(), DEBTRACE, YACS::ENGINE::getSALOMERuntime(), and YACS::ENGINE::Runtime::loadCatalog().

Referenced by YACS::HMI::GenericGui::GenericGui(), Yacsgui::initialize(), YACS::HMI::GenericGui::onImportCatalog(), and Yacsgui::preferencesChanged().

◆ getCatalog()

YACS::ENGINE::Catalog * CatalogWidget::getCatalog ( std::string  cataName)
virtual

Definition at line 91 of file CatalogWidget.cxx.

92{
93 YACS::ENGINE::Catalog* catalog = 0;
94 if (_cataMap.count(cataName))
95 catalog = _cataMap[cataName];
96 return catalog;
97}

References _cataMap.

◆ getCatalogFromType()

YACS::ENGINE::Catalog * CatalogWidget::getCatalogFromType ( std::string  typeName)
virtual

Definition at line 99 of file CatalogWidget.cxx.

100{
101 DEBTRACE("CatalogWidget::getCatalogFromType " << typeName);
102 YACS::ENGINE::Catalog* catalog = 0;
103 if (_typeToCataMap.count(typeName))
104 catalog = _typeToCataMap[typeName];
105 return catalog;
106}

References _typeToCataMap, and DEBTRACE.

Referenced by YACS::HMI::TablePortsEdition::oncb_insert_activated().

◆ getCataMap()

std::map< std::string, YACS::ENGINE::Catalog * > CatalogWidget::getCataMap ( )
virtual

Definition at line 86 of file CatalogWidget.cxx.

87{
88 return _cataMap;
89}

References _cataMap.

◆ mousePressEvent()

void CatalogWidget::mousePressEvent ( QMouseEvent *  event)
virtual

Definition at line 279 of file CatalogWidget.cxx.

280{
281 DEBTRACE("CatalogWidget::mousePressEvent ");
282 _dragModifier= false;
283 if(event->button() == Qt::MidButton)
284 _dragModifier= true;
285 QTreeWidget::mousePressEvent(event);
286}

References _dragModifier, and DEBTRACE.

◆ startDrag()

void CatalogWidget::startDrag ( Qt::DropActions  supportedActions)
protectedvirtual

Definition at line 181 of file CatalogWidget.cxx.

182{
183 DEBTRACE("startDrag " << supportedActions);
184 if (! QtGuiContext::getQtCurrent()) return;
185 if (! QtGuiContext::getQtCurrent()->isEdition()) return;
186
187 QDrag *drag = 0;
188 ItemMimeData *mime = 0;
189 QString theMimeInfo;
190
191 QList<QTreeWidgetItem*> selectList = selectedItems();
192 for (int i=0; i<selectList.size(); i++)
193 {
194 QTreeWidgetItem *parent = selectList[i]->parent();
195 if (!parent) continue;
196 QTreeWidgetItem *grandPa = parent->parent();
197 if (!grandPa) continue;
198 QTreeWidgetItem *grandGrandPa = grandPa->parent();
199 string cataName ="";
200 if (grandGrandPa)
201 cataName = grandGrandPa->text(0).toStdString();
202 else
203 cataName = grandPa->text(0).toStdString();
204 DEBTRACE("cataName=" << cataName);
205 YASSERT(_cataMap.count(cataName));
206 YACS::ENGINE::Catalog *catalog = _cataMap[cataName];
207
208 QString mimeInfo;
209 string compo = "";
210 string definition = "";
211 QPixmap pixmap;
212 if (! parent->text(0).compare("Types"))
213 {
214 mimeInfo = "Type";
215 definition = selectList[i]->text(0).toStdString();
216 pixmap.load("icons:data_link.png");
217 }
218 else if (parent->text(0).contains("Nodes"))
219 {
220 mimeInfo = "Node";
221 definition = selectList[i]->text(0).toStdString();
222 pixmap.load("icons:add_node.png");
223 }
224 else if (! grandPa->text(0).compare("Components"))
225 {
226 mimeInfo = "Service";
227 definition = selectList[i]->text(0).toStdString();
228 compo = parent->text(0).toStdString();
229 pixmap.load("icons:new_salome_service_node.png");
230 }
231 else
232 {
233 mimeInfo = "Component";
234 compo = selectList[i]->text(0).toStdString();
235 pixmap.load("icons:component.png");
236 }
237 QString mimeType = "yacs/cata" + mimeInfo;
238
239 if (!drag) // --- intialize mime data with the first selected item
240 {
241 DEBTRACE("mimeInfo=" << mimeInfo.toStdString() << " definition=" << definition << " compo=" << compo);
242 drag = new QDrag(this);
243 mime = new ItemMimeData;
244 drag->setMimeData(mime);
245 mime->setData(mimeType, mimeInfo.toLatin1());
246 drag->setPixmap(pixmap);
247
248 theMimeInfo = mimeInfo;
249
250 mime->setCatalog(catalog);
251 mime->setCataName(cataName);
252 mime->setCompo(compo);
253 mime->setType(definition);
254 }
255 else // --- push only selected item of the same mimeType than the first
256 {
257 if (theMimeInfo == mimeInfo)
258 {
259 DEBTRACE("mimeInfo=" << mimeInfo.toStdString() << " definition=" << definition << " compo=" << compo);
260 mime->setCatalog(catalog);
261 mime->setCataName(cataName);
262 mime->setCompo(compo);
263 mime->setType(definition);
264 }
265 }
266 }
267
268 if (drag)
269 {
270 if(_dragModifier)
271 mime->setControl(true);
272 else
273 mime->setControl(false);
274
275 drag->exec(supportedActions);
276 }
277}
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
Definition: YacsTrace.hxx:59
virtual void setCompo(std::string compo)
virtual void setType(std::string aType)
virtual void setCataName(std::string cataName)
virtual void setCatalog(YACS::ENGINE::Catalog *cata)
virtual void setControl(bool control)
static QtGuiContext * getQtCurrent()

References _cataMap, _dragModifier, DEBTRACE, YACS::HMI::QtGuiContext::getQtCurrent(), yacsorb.CORBAEngineTest::i, YACS::HMI::ItemMimeData::setCatalog(), YACS::HMI::ItemMimeData::setCataName(), YACS::HMI::ItemMimeData::setCompo(), YACS::HMI::ItemMimeData::setControl(), YACS::HMI::ItemMimeData::setType(), and YASSERT.

Member Data Documentation

◆ _builtinCatalog

YACS::ENGINE::Catalog* YACS::HMI::CatalogWidget::_builtinCatalog
protected

Definition at line 55 of file CatalogWidget.hxx.

Referenced by CatalogWidget().

◆ _cataMap

std::map<std::string, YACS::ENGINE::Catalog*> YACS::HMI::CatalogWidget::_cataMap
protected

Definition at line 58 of file CatalogWidget.hxx.

Referenced by addCatalog(), CatalogWidget(), getCatalog(), getCataMap(), and startDrag().

◆ _dragModifier

bool YACS::HMI::CatalogWidget::_dragModifier
protected

Definition at line 60 of file CatalogWidget.hxx.

Referenced by CatalogWidget(), mousePressEvent(), and startDrag().

◆ _idCatalog

int YACS::HMI::CatalogWidget::_idCatalog
protected

Definition at line 57 of file CatalogWidget.hxx.

Referenced by addCatalog(), and CatalogWidget().

◆ _sessionCatalog

YACS::ENGINE::Catalog* YACS::HMI::CatalogWidget::_sessionCatalog
protected

Definition at line 56 of file CatalogWidget.hxx.

Referenced by CatalogWidget().

◆ _typeToCataMap

std::map<std::string, YACS::ENGINE::Catalog*> YACS::HMI::CatalogWidget::_typeToCataMap
protected

Definition at line 59 of file CatalogWidget.hxx.

Referenced by addCatalog(), CatalogWidget(), and getCatalogFromType().


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