MorphoGraphX
LabelEditorDlg.hpp
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2015 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef LABELEDITORDLG_HPP
12 #define LABELEDITORDLG_HPP
13 
14 #include <Config.hpp>
15 
16 #include <Color.hpp>
17 #include <Misc.hpp>
18 
19 #include <QAbstractListModel>
20 #include <vector>
21 #include <QDialog>
22 
23 class QAbstractButton;
24 class QPoint;
25 
27 public:
28  LabelModel(std::vector<mgx::Colorf>* colors);
29 
30  int rowCount(const QModelIndex& parent = QModelIndex()) const;
31  int columnCount(const QModelIndex& /*parent*/ = QModelIndex()) const {
32  return 1;
33  }
34 
35  Qt::ItemFlags flags(const QModelIndex& index) const;
36 
37  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
38  bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
39 
40  void apply();
41  void reset();
42 
43  void makeGray();
44  void makeRandom();
45 
46  void setNbColors(int n);
47 
48  bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex());
49  bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());
50 
51 protected:
52  std::vector<mgx::Colorf>* toChange;
53  std::vector<mgx::Colorf> localCopy;
54 };
55 
56 namespace Ui {
57 class LabelEditorDlg;
58 } // namespace Ui
59 
60 class LabelEditorDlg : public QDialog {
61  Q_OBJECT
62 public:
63  LabelEditorDlg(std::vector<mgx::Colorf>* colors, QWidget* parent);
64  ~LabelEditorDlg();
65 
66 public slots:
67  void importLabels();
68  void exportLabels();
69  bool importLabels(QString filename);
70  bool exportLabels(QString filename);
71  void makeLabelCurrent();
72  void selectLabel();
73  void setCurrentLabel(int label);
74 
75 protected slots:
76  void on_buttonBox_clicked(QAbstractButton* btn);
77  void on_setNbColors_clicked();
78  void on_labelsView_doubleClicked(const QModelIndex& idx);
79  void on_labelsView_customContextMenuRequested(const QPoint& pos);
80  void on_showCurrent_clicked();
81  void on_makeGray_clicked();
82  void on_makeRandom_clicked();
83  void changeNbItems();
84 
85 signals:
86  void update();
87  void selectLabel(int label, int repeat, bool replaceSelection);
88  void makeLabelCurrent(int label);
89 
90 protected:
91  int currentLabel, selectedLabel;
92  LabelModel* _model;
93  Ui::LabelEditorDlg* ui;
94  QPushButton* importButton, *exportButton;
95  QAction* selectLabelAction, *makeLabelCurrentAction;
96 };
97 
98 #endif // LABELEDITORDLG_HPP
Definition: LabelEditorDlg.hpp:56
Misc.
index(int row, int column=0, const QModelIndex &parent=QModelIndex()
Defines the Color class template.
Definition: LabelEditorDlg.hpp:60
Definition: LabelEditorDlg.hpp:26