vdirectorytree.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef VDIRECTORYTREE_H
  2. #define VDIRECTORYTREE_H
  3. #include <QTreeWidget>
  4. #include <QJsonObject>
  5. class VDirectoryTree : public QTreeWidget
  6. {
  7. Q_OBJECT
  8. public:
  9. explicit VDirectoryTree(QWidget *parent = 0);
  10. signals:
  11. void currentDirectoryChanged(QJsonObject itemJson);
  12. public slots:
  13. void setTreePath(const QString& path);
  14. private slots:
  15. // Read config file and pdate the subtree of @item in the directory tree.
  16. // If @item has no child, we will call updateDirectoryTreeOne() to update it.
  17. // Otherwise, we will loop all its direct-children and try to populate it if
  18. // it has not been populated yet.
  19. void updateItemSubtree(QTreeWidgetItem *item);
  20. void contextMenuRequested(QPoint pos);
  21. void newSiblingDirectory();
  22. void newSubDirectory();
  23. void newRootDirectory();
  24. void deleteDirectory();
  25. void currentDirectoryItemChanged(QTreeWidgetItem *currentItem);
  26. private:
  27. // Clean and pdate the TreeWidget according to treePath
  28. void updateDirectoryTree();
  29. // Update the top-level items of the directory tree. Will not clean the tree at first.
  30. void updateDirectoryTreeTopLevel();
  31. // Update one directory, going into @depth levels. Not cleaning the tree item at first,
  32. // so you must ensure @parent has no child before calling this function.
  33. void updateDirectoryTreeOne(QTreeWidgetItem &parent, int depth);
  34. // Validate if a directory is valid
  35. bool validatePath(const QString &path);
  36. // Fill the QTreeWidgetItem according to its QJsonObject.
  37. // @relative_path is the path related to treePath.
  38. void fillDirectoryTreeItem(QTreeWidgetItem &item, QJsonObject itemJson, const QString &relativePath);
  39. void initActions();
  40. QTreeWidgetItem* createDirectoryAndUpdateTree(QTreeWidgetItem *parent, const QString &name,
  41. const QString &description);
  42. void deleteDirectoryAndUpdateTree(QTreeWidgetItem *item);
  43. // If @name conflict with the children's names of @parent.
  44. bool isConflictNameWithChildren(const QTreeWidgetItem *parent, const QString &name);
  45. QTreeWidgetItem* insertDirectoryTreeItem(QTreeWidgetItem *parent, QTreeWidgetItem *preceding,
  46. const QJsonObject &newItem);
  47. void removeDirectoryTreeItem(QTreeWidgetItem *item);
  48. // The path of the directory tree root
  49. QString treePath;
  50. // Actions
  51. QAction *newRootDirAct;
  52. QAction *newSiblingDirAct;
  53. QAction *newSubDirAct;
  54. QAction *deleteDirAct;
  55. };
  56. #endif // VDIRECTORYTREE_H