vsortdialog.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef VSORTDIALOG_H
  2. #define VSORTDIALOG_H
  3. #include <QDialog>
  4. #include <QVector>
  5. #include <QTreeWidget>
  6. class QPushButton;
  7. class QDialogButtonBox;
  8. class QTreeWidget;
  9. class QDropEvent;
  10. // QTreeWidget won't emit the rowsMoved() signal after drag-and-drop.
  11. // VTreeWidget will emit rowsMoved() signal.
  12. class VTreeWidget : public QTreeWidget
  13. {
  14. Q_OBJECT
  15. public:
  16. explicit VTreeWidget(QWidget *p_parent = 0)
  17. : QTreeWidget(p_parent)
  18. {
  19. }
  20. protected:
  21. void dropEvent(QDropEvent *p_event) Q_DECL_OVERRIDE;
  22. signals:
  23. // Rows [@p_first, @p_last] were moved to @p_row.
  24. void rowsMoved(int p_first, int p_last, int p_row);
  25. };
  26. class VSortDialog : public QDialog
  27. {
  28. Q_OBJECT
  29. public:
  30. VSortDialog(const QString &p_title,
  31. const QString &p_info,
  32. QWidget *p_parent = 0);
  33. QTreeWidget *getTreeWidget() const;
  34. // Called after updating the m_treeWidget.
  35. void treeUpdated();
  36. // Get user data of column 0 from sorted items.
  37. QVector<QVariant> getSortedData() const;
  38. private:
  39. enum MoveOperation { Top, Up, Down, Bottom };
  40. private slots:
  41. void handleMoveOperation(MoveOperation p_op);
  42. private:
  43. void setupUI(const QString &p_title, const QString &p_info);
  44. VTreeWidget *m_treeWidget;
  45. QPushButton *m_topBtn;
  46. QPushButton *m_upBtn;
  47. QPushButton *m_downBtn;
  48. QPushButton *m_bottomBtn;
  49. QDialogButtonBox *m_btnBox;
  50. };
  51. inline QTreeWidget *VSortDialog::getTreeWidget() const
  52. {
  53. return m_treeWidget;
  54. }
  55. #endif // VSORTDIALOG_H