ProjectManager.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include "pch.h"
  2. #include <QTreeWidget>
  3. #include <QAction>
  4. #include <QMenu>
  5. #include "ProjectManager.h"
  6. ProjectManager::ProjectManager(QWidget *parent, metavis* owner)
  7. : QWidget(parent), owner(owner)
  8. {
  9. QGridLayout* gridlayout = new QGridLayout();
  10. gridlayout->setContentsMargins(0, 0, 0, 0);
  11. treeWidget = new QTreeWidget();
  12. treeWidget->setColumnCount(1);
  13. treeWidget->setHeaderHidden(true);
  14. treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
  15. connect(treeWidget, &QTreeWidget::customContextMenuRequested, this, &ProjectManager::prepareMenu);
  16. QTreeWidgetItem* projectItem = new QTreeWidgetItem(treeWidget, QStringList("Project"), ProjectManager::Types::Project);
  17. projectItem->setExpanded(true);
  18. QTreeWidgetItem* filesItem = new QTreeWidgetItem(projectItem, QStringList("Metalog Files"), ProjectManager::Types::LogManger);
  19. new QTreeWidgetItem(filesItem, QStringList("run.metalog"), ProjectManager::Types::LogFile);
  20. new QTreeWidgetItem(filesItem, QStringList("run2.metalog"), ProjectManager::Types::LogFile);
  21. new QTreeWidgetItem(filesItem, QStringList("run3.metalog"), ProjectManager::Types::LogFile);
  22. new QTreeWidgetItem(filesItem, QStringList("run4.metalog"), ProjectManager::Types::LogFile);
  23. new QTreeWidgetItem(filesItem, QStringList("run5.metalog"), ProjectManager::Types::LogFile);
  24. filesItem->setExpanded(true);
  25. QTreeWidgetItem* graphItem = new QTreeWidgetItem(projectItem, QStringList("Graph Views"), ProjectManager::Types::GraphManger);
  26. new QTreeWidgetItem(graphItem, QStringList("Best vs Avg"), ProjectManager::Types::Graph);
  27. new QTreeWidgetItem(graphItem, QStringList("Mean Hamming Distance"), ProjectManager::Types::Graph);
  28. new QTreeWidgetItem(graphItem, QStringList("Min Max Average"), ProjectManager::Types::Graph);
  29. new QTreeWidgetItem(graphItem, QStringList("Particle"), ProjectManager::Types::Graph);
  30. graphItem->setExpanded(true);
  31. gridlayout->addWidget(treeWidget);
  32. this->setLayout(gridlayout);
  33. //Create Menus
  34. filesMenu = new QMenu(this);
  35. QAction* metaLogAddAction = new QAction("Add new .metalog-File...");
  36. connect(metaLogAddAction, &QAction::triggered, owner, &metavis::openFile);
  37. QAction* removeAllFilesAction = new QAction("Remove all metalog-Files");
  38. filesMenu->addAction(metaLogAddAction);
  39. filesMenu->addAction(removeAllFilesAction);
  40. metalogFileMenu = new QMenu(this);
  41. QIcon removeIcon(":/metavis/Resources/close_big_red.svg");
  42. QAction* removeMetalogFileAction = new QAction("Remove");
  43. removeMetalogFileAction->setIcon(removeIcon);
  44. QAction* assignToGraphAction = new QAction("Assign...");
  45. metalogFileMenu->addAction(removeMetalogFileAction);
  46. metalogFileMenu->addAction(assignToGraphAction);
  47. graphMenu = new QMenu(this);
  48. QAction* assignMetalogFileAction = new QAction("Remove");
  49. assignMetalogFileAction->setIcon(removeIcon);
  50. graphMenu->addAction(assignMetalogFileAction);
  51. }
  52. ProjectManager::~ProjectManager()
  53. {
  54. }
  55. void ProjectManager::prepareMenu(const QPoint& pos) {
  56. qDebug() << "TestMenu";
  57. QTreeWidgetItem* item = treeWidget->itemAt(pos);
  58. qDebug() << item->text(0) << " " << item->type();
  59. switch (item->type()) {
  60. case Types::Graph:
  61. graphMenu->exec(treeWidget->mapToGlobal(pos));
  62. break;
  63. case Types::GraphManger:
  64. break;
  65. case Types::LogFile:
  66. metalogFileMenu->exec(treeWidget->mapToGlobal(pos));
  67. break;
  68. case Types::LogManger:
  69. filesMenu->exec(treeWidget->mapToGlobal(pos));
  70. break;
  71. default:
  72. break;
  73. }
  74. }
  75. FileTreeItem::FileTreeItem(QTreeWidget* parent, const QStringList& strings, RunData* rundata, std::list<RunData>* list, int type)
  76. : QTreeWidgetItem(parent, strings, type), list(list), rundata(rundata)
  77. {
  78. }
  79. void FileTreeItem::remove()
  80. {
  81. qDebug() << "Remove";
  82. // Remove from graphs
  83. //Remove from List
  84. //list->remove(*rundata);
  85. //Delete self
  86. delete this;
  87. }