Version: 8.3.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 ( QWidget parent,
YACS::ENGINE::Catalog builtinCatalog,
YACS::ENGINE::Catalog sessionCatalog 
)

Definition at line 47 of file CatalogWidget.cxx.

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

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 }
CatalogWidget::~CatalogWidget ( )
virtual

Definition at line 176 of file CatalogWidget.cxx.

177 {
178 }

Member Function Documentation

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

Definition at line 107 of file CatalogWidget.cxx.

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().

109 {
110  if (!catalog) return;
111 
112  QTreeWidgetItem *itemCata = 0;
113  QTreeWidgetItem *category = 0;
114 
115  itemCata = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString(name.c_str())));
116  insertTopLevelItem(_idCatalog, itemCata);
117  _idCatalog++;
118 
119  if (! catalog->_typeMap.empty())
120  {
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)
124  {
125  DEBTRACE("Type : " <<(*it).first
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())));
132  if (! _typeToCataMap.count(typeName))
133  _typeToCataMap[typeName] = catalog;
134  else if ( ! ((*it).second)->isEquivalent(_typeToCataMap[typeName]->_typeMap[typeName]) )
135  {
136  DEBTRACE(" ========================================================================================================");
137  DEBTRACE(" type " << typeName << " not compatible with one of same name already present in another catalog, FORCE NEW!");
138  DEBTRACE(" ========================================================================================================");
139  _typeToCataMap[typeName] = catalog;
140  item->setForeground(0,Qt::blue);
141  }
142  }
143  }
144 
145  if (! catalog->_componentMap.empty())
146  {
147  category = new QTreeWidgetItem(itemCata, QStringList(QString("Components")));
148  map<string, ComponentDefinition*>::const_iterator it = catalog->_componentMap.begin();
149  for (; it != catalog->_componentMap.end(); ++it)
150  {
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())));
155  }
156  }
157 
158  if (! catalog->_nodeMap.empty())
159  {
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())));
164  }
165 
166  if (! catalog->_composednodeMap.empty())
167  {
168  category = new QTreeWidgetItem(itemCata, QStringList(QString("Composed Nodes")));
169  map<string, ComposedNode*>::const_iterator it = catalog->_composednodeMap.begin();
170  for (; it != catalog->_composednodeMap.end(); ++it)
171  QTreeWidgetItem *item = new QTreeWidgetItem(category, QStringList(QString((it->first).c_str())));
172  }
173  _cataMap[name] = catalog;
174 }
bool CatalogWidget::addCatalogFromFile ( std::string  fileName)
virtual

Definition at line 74 of file CatalogWidget.cxx.

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

Referenced by Yacsgui::initialize(), and Yacsgui::preferencesChanged().

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 }
YACS::ENGINE::Catalog * CatalogWidget::getCatalog ( std::string  cataName)
virtual

Definition at line 90 of file CatalogWidget.cxx.

References _cataMap.

91 {
92  YACS::ENGINE::Catalog* catalog = 0;
93  if (_cataMap.count(cataName))
94  catalog = _cataMap[cataName];
95  return catalog;
96 }
YACS::ENGINE::Catalog * CatalogWidget::getCatalogFromType ( std::string  typeName)
virtual

Definition at line 98 of file CatalogWidget.cxx.

References _typeToCataMap, and DEBTRACE.

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

99 {
100  DEBTRACE("CatalogWidget::getCatalogFromType " << typeName);
101  YACS::ENGINE::Catalog* catalog = 0;
102  if (_typeToCataMap.count(typeName))
103  catalog = _typeToCataMap[typeName];
104  return catalog;
105 }
std::map< std::string, YACS::ENGINE::Catalog * > CatalogWidget::getCataMap ( )
virtual

Definition at line 85 of file CatalogWidget.cxx.

References _cataMap.

86 {
87  return _cataMap;
88 }
void CatalogWidget::mousePressEvent ( QMouseEvent *  event)
virtual

Definition at line 278 of file CatalogWidget.cxx.

References _dragModifier, and DEBTRACE.

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

Definition at line 180 of file CatalogWidget.cxx.

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

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

Member Data Documentation

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

Definition at line 55 of file CatalogWidget.hxx.

Referenced by CatalogWidget().

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().

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

Definition at line 60 of file CatalogWidget.hxx.

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

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

Definition at line 57 of file CatalogWidget.hxx.

Referenced by addCatalog(), and CatalogWidget().

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

Definition at line 56 of file CatalogWidget.hxx.

Referenced by CatalogWidget().

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: