29 #include <QApplication>
36 #include <QMouseEvent>
44 using namespace YACS::ENGINE;
45 using namespace YACS::HMI;
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();
100 DEBTRACE(
"CatalogWidget::getCatalogFromType " << typeName);
110 if (!catalog)
return;
112 QTreeWidgetItem *itemCata = 0;
113 QTreeWidgetItem *category = 0;
115 itemCata =
new QTreeWidgetItem((
QTreeWidget*)0, QStringList(QString(name.c_str())));
121 category =
new QTreeWidgetItem(itemCata, QStringList(QString(
"Types")));
122 map<string, TypeCode*>::const_iterator it = catalog->
_typeMap.begin();
123 for (; it != catalog->
_typeMap.end(); ++it)
126 <<
" " << (*it).second->getKindRepr()
127 <<
" " << (*it).second->name()
128 <<
" " << (*it).second->shortName()
129 <<
" " << (*it).second->id() );
130 string typeName = it->first;
131 QTreeWidgetItem *item =
new QTreeWidgetItem(category, QStringList(QString(typeName.c_str())));
134 else if ( ! ((*it).second)->isEquivalent(
_typeToCataMap[typeName]->_typeMap[typeName]) )
136 DEBTRACE(
" ========================================================================================================");
137 DEBTRACE(
" type " << typeName <<
" not compatible with one of same name already present in another catalog, FORCE NEW!");
138 DEBTRACE(
" ========================================================================================================");
140 item->setForeground(0,Qt::blue);
147 category =
new QTreeWidgetItem(itemCata, QStringList(QString(
"Components")));
148 map<string, ComponentDefinition*>::const_iterator it = catalog->
_componentMap.begin();
151 QTreeWidgetItem *item =
new QTreeWidgetItem(category, QStringList(QString((it->first).c_str())));
152 map<string, ServiceNode *>::const_iterator its = (it->second)->_serviceMap.begin();
153 for (; its != (it->second)->_serviceMap.end(); ++its)
154 QTreeWidgetItem *sitem =
new QTreeWidgetItem(item, QStringList(QString((its->first).c_str())));
160 category =
new QTreeWidgetItem(itemCata, QStringList(QString(
"Elementary Nodes")));
161 map<string, Node*>::const_iterator it = catalog->
_nodeMap.begin();
162 for (; it != catalog->
_nodeMap.end(); ++it)
163 QTreeWidgetItem *item =
new QTreeWidgetItem(category, QStringList(QString((it->first).c_str())));
168 category =
new QTreeWidgetItem(itemCata, QStringList(QString(
"Composed Nodes")));
169 map<string, ComposedNode*>::const_iterator it = catalog->
_composednodeMap.begin();
171 QTreeWidgetItem *item =
new QTreeWidgetItem(category, QStringList(QString((it->first).c_str())));
182 DEBTRACE(
"startDrag " << supportedActions);
190 QList<QTreeWidgetItem*> selectList = selectedItems();
191 for (
int i=0;
i<selectList.size();
i++)
193 QTreeWidgetItem *parent = selectList[
i]->parent();
194 if (!parent)
continue;
195 QTreeWidgetItem *grandPa = parent->parent();
196 if (!grandPa)
continue;
197 QTreeWidgetItem *grandGrandPa = grandPa->parent();
200 cataName = grandGrandPa->text(0).toStdString();
202 cataName = grandPa->text(0).toStdString();
209 string definition =
"";
211 if (! parent->text(0).compare(
"Types"))
214 definition = selectList[
i]->text(0).toStdString();
215 pixmap.load(
"icons:data_link.png");
217 else if (parent->text(0).contains(
"Nodes"))
220 definition = selectList[
i]->text(0).toStdString();
221 pixmap.load(
"icons:add_node.png");
223 else if (! grandPa->text(0).compare(
"Components"))
225 mimeInfo =
"Service";
226 definition = selectList[
i]->text(0).toStdString();
227 compo = parent->text(0).toStdString();
228 pixmap.load(
"icons:new_salome_service_node.png");
232 mimeInfo =
"Component";
233 compo = selectList[
i]->text(0).toStdString();
234 pixmap.load(
"icons:component.png");
236 QString mimeType =
"yacs/cata" + mimeInfo;
240 DEBTRACE(
"mimeInfo=" << mimeInfo.toStdString() <<
" definition=" << definition <<
" compo=" << compo);
241 drag =
new QDrag(
this);
243 drag->setMimeData(mime);
244 mime->setData(mimeType, mimeInfo.toLatin1());
245 drag->setPixmap(pixmap);
247 theMimeInfo = mimeInfo;
256 if (theMimeInfo == mimeInfo)
258 DEBTRACE(
"mimeInfo=" << mimeInfo.toStdString() <<
" definition=" << definition <<
" compo=" << compo);
274 drag->exec(supportedActions);
280 DEBTRACE(
"CatalogWidget::mousePressEvent ");
282 if(event->button() == Qt::MidButton)
284 QTreeWidget::mousePressEvent(event);