29 #include <QApplication>
36 #include <QMouseEvent>
47 CatalogWidget::CatalogWidget(
QWidget *parent,
52 DEBTRACE(
"CatalogWidget::CatalogWidget");
62 setHeaderHidden(
true );
67 setDragDropMode(QAbstractItemView::DragOnly);
69 setDropIndicatorShown(
true);
71 setSelectionMode(QAbstractItemView::ExtendedSelection);
76 DEBTRACE(
"CatalogWidget::addCatalogFromFile " << fileName);
77 QFileInfo afi(fileName.c_str());
81 string aFile = afi.fileName().toStdString();
101 DEBTRACE(
"CatalogWidget::getCatalogFromType " << typeName);
111 if (!catalog)
return;
113 QTreeWidgetItem *itemCata = 0;
114 QTreeWidgetItem *category = 0;
116 itemCata =
new QTreeWidgetItem((
QTreeWidget*)0, QStringList(QString(name.c_str())));
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)
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())));
135 else if ( ! ((*it).second)->isEquivalent(
_typeToCataMap[typeName]->_typeMap[typeName]) )
137 DEBTRACE(
" ========================================================================================================");
138 DEBTRACE(
" type " << typeName <<
" not compatible with one of same name already present in another catalog, FORCE NEW!");
139 DEBTRACE(
" ========================================================================================================");
141 item->setForeground(0,Qt::blue);
148 category =
new QTreeWidgetItem(itemCata, QStringList(QString(
"Components")));
149 map<string, ComponentDefinition*>::const_iterator it = catalog->
_componentMap.begin();
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())));
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())));
169 category =
new QTreeWidgetItem(itemCata, QStringList(QString(
"Composed Nodes")));
170 map<string, ComposedNode*>::const_iterator it = catalog->
_composednodeMap.begin();
172 QTreeWidgetItem *item =
new QTreeWidgetItem(category, QStringList(QString((it->first).c_str())));
183 DEBTRACE(
"startDrag " << supportedActions);
191 QList<QTreeWidgetItem*> selectList = selectedItems();
192 for (
int i=0;
i<selectList.size();
i++)
194 QTreeWidgetItem *parent = selectList[
i]->parent();
195 if (!parent)
continue;
196 QTreeWidgetItem *grandPa = parent->parent();
197 if (!grandPa)
continue;
198 QTreeWidgetItem *grandGrandPa = grandPa->parent();
201 cataName = grandGrandPa->text(0).toStdString();
203 cataName = grandPa->text(0).toStdString();
210 string definition =
"";
212 if (! parent->text(0).compare(
"Types"))
215 definition = selectList[
i]->text(0).toStdString();
216 pixmap.load(
"icons:data_link.png");
218 else if (parent->text(0).contains(
"Nodes"))
221 definition = selectList[
i]->text(0).toStdString();
222 pixmap.load(
"icons:add_node.png");
224 else if (! grandPa->text(0).compare(
"Components"))
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");
233 mimeInfo =
"Component";
234 compo = selectList[
i]->text(0).toStdString();
235 pixmap.load(
"icons:component.png");
237 QString mimeType =
"yacs/cata" + mimeInfo;
241 DEBTRACE(
"mimeInfo=" << mimeInfo.toStdString() <<
" definition=" << definition <<
" compo=" << compo);
242 drag =
new QDrag(
this);
244 drag->setMimeData(mime);
245 mime->setData(mimeType, mimeInfo.toLatin1());
246 drag->setPixmap(pixmap);
248 theMimeInfo = mimeInfo;
257 if (theMimeInfo == mimeInfo)
259 DEBTRACE(
"mimeInfo=" << mimeInfo.toStdString() <<
" definition=" << definition <<
" compo=" << compo);
275 drag->exec(supportedActions);
281 DEBTRACE(
"CatalogWidget::mousePressEvent ");
283 if(event->button() == Qt::MidButton)
285 QTreeWidget::mousePressEvent(event);
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
std::map< std::string, ComposedNode * > _composednodeMap
std::map< std::string, ComponentDefinition * > _componentMap
std::map< std::string, Node * > _nodeMap
std::map< std::string, TypeCode * > _typeMap
virtual Catalog * loadCatalog(const std::string &sourceKind, const std::string &path)
Load a catalog of calculation to use as factory.
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()
YACSRUNTIMESALOME_EXPORT RuntimeSALOME * getSALOMERuntime()