MorphoGraphX  2.0-1-227
LabelEditorDlg.hpp
Go to the documentation of this file.
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 
26 class LabelModel : public QAbstractListModel
27 {
28 public:
29  LabelModel(std::vector<mgx::Colorf>* colors);
30 
31  int rowCount(const QModelIndex& parent = QModelIndex()) const;
32  int columnCount(const QModelIndex& /*parent*/ = QModelIndex()) const {
33  return 1;
34  }
35 
36  Qt::ItemFlags flags(const QModelIndex& index) const;
37 
38  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
39  bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
40 
41  void apply();
42  void reset();
43 
44  void makeGray();
45  void makeRandom();
46 
47  void setNbColors(int n);
48 
49  bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex());
50  bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());
51 
52 protected:
53  std::vector<mgx::Colorf>* toChange;
54  std::vector<mgx::Colorf> localCopy;
55 };
56 
57 namespace Ui {
58 class LabelEditorDlg;
59 } // namespace Ui
60 
61 class LabelEditorDlg : public QDialog {
62  Q_OBJECT
63 public:
64  LabelEditorDlg(std::vector<mgx::Colorf>* colors, QWidget* parent);
66 
67 public slots:
68  void importLabels();
69  void exportLabels();
70  bool importLabels(QString filename);
71  bool exportLabels(QString filename);
72  void makeLabelCurrent();
73  void selectLabel();
74  void setCurrentLabel(int label);
75 
76 protected slots:
77  void on_buttonBox_clicked(QAbstractButton* btn);
79  void on_labelsView_doubleClicked(const QModelIndex& idx);
80  void on_labelsView_customContextMenuRequested(const QPoint& pos);
82  void on_makeGray_clicked();
83  void on_makeRandom_clicked();
84  void changeNbItems();
85 
86 signals:
87  void update();
88  void selectLabel(int label, int repeat, bool replaceSelection);
89  void makeLabelCurrent(int label);
90 
91 protected:
94  Ui::LabelEditorDlg* ui;
95  QPushButton* importButton, *exportButton;
97 };
98 
99 #endif // LABELEDITORDLG_HPP
LabelEditorDlg::on_makeRandom_clicked
void on_makeRandom_clicked()
LabelEditorDlg
Definition: LabelEditorDlg.hpp:61
LabelModel::setData
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
LabelEditorDlg::on_labelsView_customContextMenuRequested
void on_labelsView_customContextMenuRequested(const QPoint &pos)
LabelEditorDlg::_model
LabelModel * _model
Definition: LabelEditorDlg.hpp:93
LabelModel::columnCount
int columnCount(const QModelIndex &=QModelIndex()) const
Definition: LabelEditorDlg.hpp:32
LabelModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const
LabelEditorDlg::importButton
QPushButton * importButton
Definition: LabelEditorDlg.hpp:95
LabelEditorDlg::importLabels
void importLabels()
n
#define n
Definition: Eigenvalues.hpp:36
LabelModel::makeRandom
void makeRandom()
LabelModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const
LabelEditorDlg::selectLabel
void selectLabel()
LabelModel::apply
void apply()
LabelModel::removeRows
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
LabelEditorDlg::on_buttonBox_clicked
void on_buttonBox_clicked(QAbstractButton *btn)
LabelEditorDlg::on_setNbColors_clicked
void on_setNbColors_clicked()
LabelModel::toChange
std::vector< mgx::Colorf > * toChange
Definition: LabelEditorDlg.hpp:53
LabelModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
LabelEditorDlg::currentLabel
int currentLabel
Definition: LabelEditorDlg.hpp:92
LabelEditorDlg::LabelEditorDlg
LabelEditorDlg(std::vector< mgx::Colorf > *colors, QWidget *parent)
LabelEditorDlg::setCurrentLabel
void setCurrentLabel(int label)
LabelModel::setNbColors
void setNbColors(int n)
LabelModel::makeGray
void makeGray()
LabelEditorDlg::changeNbItems
void changeNbItems()
LabelModel::localCopy
std::vector< mgx::Colorf > localCopy
Definition: LabelEditorDlg.hpp:54
LabelEditorDlg::~LabelEditorDlg
~LabelEditorDlg()
LabelModel::insertRows
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex())
LabelEditorDlg::on_showCurrent_clicked
void on_showCurrent_clicked()
LabelEditorDlg::selectedLabel
int selectedLabel
Definition: LabelEditorDlg.hpp:92
Ui
Definition: ColorEditDlg.hpp:59
LabelEditorDlg::makeLabelCurrentAction
QAction * makeLabelCurrentAction
Definition: LabelEditorDlg.hpp:96
Misc.hpp
LabelEditorDlg::on_labelsView_doubleClicked
void on_labelsView_doubleClicked(const QModelIndex &idx)
LabelEditorDlg::exportLabels
void exportLabels()
Color.hpp
LabelEditorDlg::ui
Ui::LabelEditorDlg * ui
Definition: LabelEditorDlg.hpp:94
LabelEditorDlg::selectLabelAction
QAction * selectLabelAction
Definition: LabelEditorDlg.hpp:96
LabelEditorDlg::makeLabelCurrent
void makeLabelCurrent()
LabelEditorDlg::on_makeGray_clicked
void on_makeGray_clicked()
LabelModel::reset
void reset()
LabelModel
Definition: LabelEditorDlg.hpp:26
LabelModel::LabelModel
LabelModel(std::vector< mgx::Colorf > *colors)
LabelEditorDlg::exportButton
QPushButton * exportButton
Definition: LabelEditorDlg.hpp:95
LabelEditorDlg::update
void update()