FreeDebks  1.0.3
 All Classes Files Functions Variables Friends Pages
FdModelResults.hpp
Go to the documentation of this file.
1 // --------------------------------------------------------------------
2 // Copyright © 2011-2013 Mathieu Schopfer
3 //
4 // This file is part of FreeDebks.
5 //
6 // FreeDebks is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // FreeDebks is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with FreeDebks. If not, see <http://www.gnu.org/licenses/>.
18 // --------------------------------------------------------------------
19 
20 #ifndef FDMODELRESULTS_HPP
21 #define FDMODELRESULTS_HPP
22 
23 #include <QAbstractTableModel>
24 #include <QUndoStack>
25 #include <QtXml>
26 
27 #include "dataDefinitions.hpp"
28 
30 
37 class FdModelResults : public QAbstractTableModel
38 {
39 Q_OBJECT
40 
41 friend class FdResultsSetData;
42 friend class FdResultsRemove;
43 friend class FdResultsDragDrop;
44 
45 private:
47  QList<FdItemResults_p> mResults;
48  void init();
49 
50 protected:
51  QUndoStack* mStack;
52 
53 public:
54  explicit FdModelResults(FdSubWindow* parent);
55  FdModelResults(FdSubWindow* parent, QDomElement& results);
56  FdModelResults(FdSubWindow* parent, const FdModelResults* model);
57  QVariant data(const FdItemResults_p calculation, ResultsColumn column) const;
58  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
59  void setData(FdItemResults_p calculation, ResultsColumn column, const QVariant &value);
60  bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
61  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
62  Qt::ItemFlags flags(const QModelIndex &index) const;
63  Qt::DropActions supportedDropActions() const;
64  QStringList mimeTypes() const;
65  QMimeData* mimeData(const QModelIndexList &indexes) const;
66  bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
67  bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
68  int rowCount(const QModelIndex &parent = QModelIndex()) const;
69  int columnCount(const QModelIndex &parent = QModelIndex()) const;
70 
71  void insertCalculation(FdItemResults_p calculation, int row);
72  void insertCalculations(QList<FdItemResults_p> calculations, int row);
73  void removeCalculation(FdItemResults_p calculation);
74  void removeCalculations(QList<FdItemResults_p> calculations);
75  QAction* redo();
76  QAction* undo();
77 
78  bool idExists(QString id) const;
79  FdItemResults_p item(QString id) const;
80  FdItemResults_p item(int row) const;
81  QList<FdItemResults_p> items() const;
82  QModelIndexList entryByPartialText(QString text) const;
83  bool isValid(QString calculation) const;
84  double parse(QString calculation) const;
85  double parseItem(QString element) const;
86  QDomElement toXml(QDomDocument& document) const;
87 
88  static QStack<QString> infixToPostfix(QString expr);
89  static int opPriority(QString op);
90 
91 public slots:
92  QModelIndex addCalculation(const QModelIndex& selected);
93  void removeSelected(const QList<int>& rows);
94  void recomputeResults();
95 };
96 
97 #endif // FDMODELRESULTS_HPP