12#include <QTreeWidgetItem>
16#include <QDragEnterEvent>
24 applicationNode =
new QTreeWidgetItem(
this,QStringList() <<
"Applications");
25 modulesNode =
new QTreeWidgetItem(
this,QStringList() <<
"Modules");
26 resourcesNode =
new QTreeWidgetItem(
this,QStringList() <<
"Resources");
27 templatesNode =
new QTreeWidgetItem(
this,QStringList() <<
"Templates");
28 portsNode =
new QTreeWidgetItem(
this,QStringList() <<
"Ports");
30 applicationNode->setIcon(0,QIcon(
":/folder-app.svg"));
31 modulesNode->setIcon(0,QIcon(
":/folder-mod.svg"));
32 resourcesNode->setIcon(0,QIcon(
":/folder-res.svg"));
33 templatesNode->setIcon(0,QIcon(
":/folder.svg"));
34 portsNode->setIcon(0,QIcon(
":/folder-ports.svg"));
37 addTopLevelItem(applicationNode);
38 addTopLevelItem(modulesNode);
39 addTopLevelItem(resourcesNode);
40 addTopLevelItem(templatesNode);
41 addTopLevelItem(portsNode);
43 setExpandsOnDoubleClick(
false);
44 setContextMenuPolicy(Qt::CustomContextMenu);
45 resizeColumnToContents(0);
48 connect(
this,
SIGNAL(customContextMenuRequested(QPoint)),
this,SLOT(
onContext(QPoint)));
50 openFile =
new QAction(
"Open File",
this);
51 importFile =
new QAction(
"Import Files...",
this);
53 topLevelMenu.addAction(openFile);
54 topLevelMenu.addAction(importFile);
56 loadFiles =
new QAction(
"Load",
this);
57 auto* separator =
new QAction(
this);
58 separator->setSeparator(
true);
59 reopen =
new QAction(
"Refresh",
this);
60 remove =
new QAction(
"Remove",
this);
61 editApplication =
new QAction(
"Edit",
this);
63 secondLevelMenu.addAction(loadFiles);
64 secondLevelMenu.addAction(editApplication);
65 secondLevelMenu.addAction(separator);
66 secondLevelMenu.addAction(reopen);
67 secondLevelMenu.addAction(remove);
69 edit =
new QAction(
"Edit",
this);
70 leafLevelMenu.addAction(edit);
81 ext_editor =
"notepad.exe";
83 ext_editor =
"xdg-open";
87 setDragDropMode(DragOnly);
92 ext_editor = editor.c_str();
100 QTreeWidgetItem *item =
new QTreeWidgetItem(applicationNode,QStringList() << app->
getName());
101 item->setData(0,Qt::UserRole + 1,qlonglong(app));
103 item->setIcon(0,QIcon(
":/run22.svg"));
110 if (pos!=std::string::npos) {
111 fname = fpath.substr(pos+1);
115 fname = fname + std::string(
" (") + fpath + std::string(
")");
117 QTreeWidgetItem *xml =
new QTreeWidgetItem(item,QStringList() << fname.data());
118 xml->setData(0,Qt::UserRole + 1,QString(fpath.data()));
120 xml->setIcon(0,QIcon(
":/file-xml22.svg"));
128 QTreeWidgetItem *item =
new QTreeWidgetItem(resourcesNode,QStringList() << comp->
getName());
129 item->setData(0,Qt::UserRole + 1,qlonglong(comp));
131 item->setIcon(0,QIcon(
":/computer22.svg"));
136 if (pos!=std::string::npos) {
137 fname = fpath.substr(pos+1);
141 fname = fname + std::string(
" (") + fpath + std::string(
")");
143 QTreeWidgetItem *xml =
new QTreeWidgetItem(item,QStringList() << fname.data());
144 xml->setData(0,Qt::UserRole + 1,QString(fpath.data()));
153 QTreeWidgetItem *item =
new QTreeWidgetItem(modulesNode,QStringList() << mod->
getName());
154 item->setData(0,Qt::UserRole + 1,qlonglong(mod));
156 item->setIcon(0,QIcon(
":/module22.svg"));
161 if (pos!=std::string::npos) {
162 fname = fpath.substr(pos+1);
166 fname = fname + std::string(
" (") + fpath + std::string(
")");
168 QTreeWidgetItem *xml =
new QTreeWidgetItem(item,QStringList() << fname.data());
169 xml->setData(0,Qt::UserRole + 1,QString(fpath.data()));
179 QTreeWidgetItem *item =
new QTreeWidgetItem(templatesNode,QStringList() << QString(
"%1 (%2)").arg(tmp->
name.data()).arg(tmp->
tmpFileName.data()));
182 item->setData(0,Qt::UserRole + 1 ,tmp->
name.data());
183 item->setData(0,Qt::UserRole + 2 ,tmp->
tmpFileName.data());
184 item->setIcon(0,QIcon(
":/file-xml22.svg"));
189 if (portDetails.size() < 2)
193 QTreeWidgetItem *item =
new QTreeWidgetItem(portsNode,QStringList() << portDetails[0]);
194 item->setIcon(0,QIcon(
":/port22.svg"));
195 QTreeWidgetItem *portIp =
new QTreeWidgetItem(item,QStringList() << portDetails[1]);
203 for(
int i=0;applicationNode->childCount();i++) {
204 if (applicationNode->child(i)->text(0) == name) {
224 if (item == applicationNode || item == resourcesNode || item == modulesNode || item == templatesNode) {
225 if (!item->isExpanded()) {
238 QString fileName = QString(
"%1").arg(app->
getXmlFile());
240 QFile file(fileName);
253 QString fileName = QString(
"%1").arg(mod->
getXmlFile());
255 QFile file(fileName);
267 QString fileName = QString(
"%1").arg(res->
getXmlFile());
269 QFile file(fileName);
279 QString name = item->data(0,Qt::UserRole + 1).toString();
280 QString tmpFileName = item->data(0,Qt::UserRole + 2).toString();
281 qDebug(
"%s",name.toLatin1().data());
284 notepad =
new QProcess(
this);
285 notepad->start(ext_editor,QStringList()<<tmpFileName);
290 QString fileName = item->data(0,Qt::UserRole + 1).toString();
291 qDebug(
"%s",fileName.toLatin1().data());
294 notepad =
new QProcess(
this);
295 notepad->start(ext_editor,QStringList()<<fileName);
302 if (selectedItems().count() <= 0) {
305 QTreeWidgetItem *selectedItem = selectedItems().at(0);
308 if (!selectedItem->data(0,Qt::UserRole).isValid()) {
309 QTreeWidget::mousePressEvent(event);
312 qlonglong pointer = selectedItem->data(0,Qt::UserRole + 1).toLongLong();
314 auto* mimeData =
new QMimeData;
315 QByteArray strPointer = QString(
"%1").arg(pointer).toLatin1();
316 mimeData->setData(
"pointer",strPointer);
319 mimeData->setText(
"module");
322 mimeData->setText(
"application");
325 QFontMetrics fontMetric(font());
328 auto* drag =
new QDrag(
this);
329 drag->setMimeData(mimeData);
343 drag->exec(Qt::CopyAction);
348 QTreeWidget::mouseMoveEvent(event);
397 QTreeWidget::mousePressEvent(event);
404 if (!applicationNode) {
407 while(applicationNode->childCount() > 0) {
408 applicationNode->removeChild(applicationNode->child(0));
419 while(modulesNode->childCount() > 0) {
420 modulesNode->removeChild(modulesNode->child(0));
428 if (!resourcesNode) {
431 while(resourcesNode->childCount() > 0) {
432 resourcesNode->removeChild(resourcesNode->child(0));
440 if (!templatesNode) {
443 while(templatesNode->childCount() > 0) {
444 templatesNode->removeChild(templatesNode->child(0));
454 while (portsNode->childCount() > 0)
456 portsNode->removeChild(portsNode->child(0));
461 QList<QTreeWidgetItem*> clist = this->findItems(xmlFile, Qt::MatchContains|Qt::MatchRecursive, 0);
463 return clist.at(0)->parent();
473 QTreeWidgetItem *it = itemAt(p);
478 QPoint pp = QPoint(p.x(),p.y() + header()->height());
479 if (it == applicationNode || it ==resourcesNode || it == modulesNode || it == templatesNode) {
480 topLevelMenu.exec(mapToGlobal(pp));
482 else if(it == portsNode)
487 if (it->parent() == applicationNode) {
488 loadFiles->setText(
"Load Application");
489 secondLevelMenu.exec(mapToGlobal(pp));
490 }
else if (it->parent() == resourcesNode) {
491 loadFiles->setText(
"Load Resource");
492 secondLevelMenu.exec(mapToGlobal(pp));
493 }
else if (it->parent() == modulesNode) {
494 loadFiles->setText(
"Load Module");
495 secondLevelMenu.exec(mapToGlobal(pp));
497 else if(it->parent() == portsNode || it->parent()->parent() == portsNode)
502 leafLevelMenu.exec(mapToGlobal(pp));
510 QTreeWidgetItem *it = currentItem();
516 if (it->parent() == applicationNode) {
520 QString fileName = QString(
"%1").arg(app->
getXmlFile());
522 QFile file(fileName);
540 QTreeWidgetItem *it = currentItem();
546 if (it->parent() == applicationNode) {
551 }
else if (it->parent() == resourcesNode) {
556 }
else if (it->parent() == modulesNode) {
571 QTreeWidgetItem *item = currentItem();
577 QString fileName = item->data(0,Qt::UserRole + 1).toString();
580 notepad =
new QProcess(
this);
581 notepad->start(ext_editor,QStringList()<<fileName);
583 QString name = item->data(0,Qt::UserRole + 1).toString();
584 QString tmpFileName = item->data(0,Qt::UserRole + 2).toString();
585 qDebug(
"%s",name.toLatin1().data());
588 notepad =
new QProcess(
this);
589 notepad->start(ext_editor,QStringList()<<tmpFileName);
599 QTreeWidgetItem *it = currentItem();
604 QTreeWidgetItem *parent = it -> parent();
605 int index = it -> parent() -> indexOfChild(it);
607 if (it->parent() == applicationNode) {
611 QString fileName = QString(
"%1").arg(app->
getXmlFile());
612 QString appName = it->text(0);
614 QFile file(fileName);
625 }
else if (it->parent() == resourcesNode) {
629 QString fileName = QString(
"%1").arg(res->
getXmlFile());
630 QString resName = it->text(0);
631 QFile file(fileName);
640 }
else if (it->parent() == modulesNode) {
644 QString fileName = QString(
"%1").arg(mod->
getXmlFile());
645 QString modName = it->text(0);
646 QFile file(fileName);
657 parent -> child(index) -> setSelected(
true);
658 scrollToItem(parent -> child(index));
665 QTreeWidgetItem *item = currentItem();
674 if (missingFile || QMessageBox::question(
this,
"Removing",
"Are you sure to remove this item?") == QMessageBox::Yes) {
676 if (item->parent() == applicationNode) {
680 QString appName = item->text(0);
686 }
else if (item->parent() == resourcesNode) {
690 QString resName = item->text(0);
694 }
else if (item->parent() == modulesNode) {
698 QString modName = item->text(0);
704 while(item->childCount()>0) {
705 delete item->takeChild(0);
708 if (item->parent()) {
709 int index = item->parent()->indexOfChild(item);
710 delete item->parent()->takeChild(index);
int SIGNAL(int pid, int signum)
const char * getXmlFile()
const char * getXmlFile()
const char * getXmlFile()
static constexpr value_type preferred_separator
Abstract Class TempLoader.