1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released      *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission.     *
5  ******************************************************************************************************/
6 
7 #ifndef DLG_SETTINGS_CURVE_LIST_H
8 #define DLG_SETTINGS_CURVE_LIST_H
9 
10 #include "DlgSettingsAbstractBase.h"
11 #include <QItemSelection>
12 #include <QModelIndex>
13 #include <QString>
14 
15 class CurveNameList;
16 class QGridLayout;
17 class QListView;
18 class QPushButton;
19 class QStandardItemModel;
20 class QTableView;
21 class QTextStream;
22 
23 /// Dialog for editing curve names settings.
24 class DlgSettingsCurveList : public DlgSettingsAbstractBase
25 {
26   Q_OBJECT;
27 
28 public:
29   /// Single constructor.
30   DlgSettingsCurveList(MainWindow &mainWindow);
31   virtual ~DlgSettingsCurveList();
32 
33   virtual void createOptionalSaveDefault (QHBoxLayout *layout);
34   virtual QWidget *createSubPanel ();
35   void load (CmdMediator &cmdMediator);
36   virtual void setSmallDialogs (bool smallDialogs);
37 
38 public slots:
39   /// Cleanup after rows have been removed in the model. We remove the corresponding rows in the QListView
40   void slotRowsAboutToBeRemoved (const QModelIndex &parent, int rowFirst, int rowLast);
41 
42 private slots:
43   void slotDataChanged (const QModelIndex &topLeft,
44                         const QModelIndex &bottomRight,
45                         const QVector<int> &roles);
46   void slotNew ();
47   void slotRemove ();
48   void slotResetDefault();
49   void slotSaveDefault();
50 
51 protected:
52   virtual void handleOk ();
53 
54 private:
55 
56   void appendCurveName (const QString &curveNameNew,
57                         const QString &curveNameOriginal,
58                         int numPoints);
59   void createButtons (QGridLayout *layout, int &row);
60   void createListCurves (QGridLayout *layout, int &row);
61   bool endsWithNumber (const QString &str) const;
62   void insertCurveName (int row,
63                         const QString &curveNameNew,
64                         const QString &curveNameOriginal,
65                         int numPoints);
66   int newRowFromSelection () const;
67   QString nextCurveName () const; // Pick good curve name to go at currentRow()
68   int numberAtEnd (const QString &str) const;
69   unsigned int numPointsForSelectedCurves () const;
70   void printStream (QTextStream &str) const; // Debugging method
71   void removeSelectedCurves();
72   void selectCurveName (const QString &curveWanted);
73   void updateControls ();
74 
75   CurveNameList *m_curveNameList; // Model for m_listCurves
76 
77   QListView *m_listCurves; // Use QListView instead of QListWidget so validators can be used
78 
79   QPushButton *m_btnAdd;
80   QPushButton *m_btnRemove;
81   QPushButton *m_btnRename;
82 
83   QPushButton *m_btnResetDefault;
84   QPushButton *m_btnSaveDefault;
85 
86 };
87 
88 #endif // DLG_SETTINGS_CURVE_LIST_H
89