redmineitemtree.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef REDMINEITEMTREE_H
  2. #define REDMINEITEMTREE_H
  3. #include <QObject>
  4. #include <QMutex>
  5. #include <QJsonArray>
  6. #include <QTreeWidgetItem>
  7. #include <QComboBox>
  8. #include <QMutex>
  9. #include <QTimer>
  10. #include <redmineitemtreedata.h>
  11. class RedmineItemTree;
  12. typedef void ( *widgetItemSetTextFunct_t ) ( QWidget *initiator, QTreeWidgetItem *widgetItem, QJsonObject item, RedmineItemTree *tree, int level );
  13. typedef void ( *comboBoxAddItemFunct_t ) ( QComboBox *widgetItem, QJsonObject item );
  14. typedef bool ( *itemFilterFunct_t ) ( QWidget *initiator, QJsonObject item );
  15. class RedmineItemTree : public QObject
  16. {
  17. Q_OBJECT
  18. public:
  19. RedmineItemTree();
  20. void set ( QJsonArray array );
  21. QList<QJsonObject> get();
  22. QJsonObject get ( int item_id );
  23. QJsonObject get ( QTreeWidgetItem *widgetItem );
  24. QList<QJsonObject> getchildren ( int item_id );
  25. bool isDescendant ( int descendant_id, int ancestor_id );
  26. void filter ( QWidget *initiator, itemFilterFunct_t filterFunct );
  27. void display ( QTreeWidget *widget, QWidget *initiator, widgetItemSetTextFunct_t setTextFunct );
  28. void display ( QComboBox *widget, QWidget *initiator, comboBoxAddItemFunct_t addItemFunct );
  29. RedmineItemTreeData filtered;
  30. public slots:
  31. void display_retry();
  32. void filter_retry();
  33. private:
  34. void clear();
  35. void add ( QJsonObject jsonObj );
  36. void widgetItemResetRecursive ( int item_id );
  37. void widgetItemReset ( int item_id );
  38. void widgetItemsResetIfUpdated ( int item_id, QJsonObject item );
  39. void display_recursive ( QTreeWidgetItem *widgetItem, QWidget *initiator, widgetItemSetTextFunct_t setTextFunct, QJsonObject item, int level, QHash <int, int> &toremove_ids );
  40. void display_child ( QTreeWidgetItem *parent, QWidget *initiator, widgetItemSetTextFunct_t setTextFunct, QJsonObject child, int level, QHash <int, int> &toremove_ids );
  41. void display_topOne ( QTreeWidget *widget, QWidget *initiator, widgetItemSetTextFunct_t setTextFunct, int pos, QHash <int, int> &toremove_ids );
  42. RedmineItemTreeData real;
  43. RedmineItemTreeData filtered_old;
  44. QHash<int, QTreeWidgetItem*> id2widgetItem;
  45. QHash<int, QJsonObject> row2item;
  46. QHash<QTreeWidgetItem *, QJsonObject> widgetItem2item;
  47. struct {
  48. QTreeWidget *widget;
  49. QWidget *initiator;
  50. widgetItemSetTextFunct_t setTextFunct;
  51. } displayRetryArgs;
  52. struct {
  53. QWidget *initiator;
  54. itemFilterFunct_t filterFunct;
  55. } filterRetryArgs;
  56. QMutex displayMutex;
  57. QMutex displayExceptionMutex;
  58. QTimer displayRetryTimer;
  59. QTimer filterRetryTimer;
  60. };
  61. #endif // REDMINEITEMTREE_H