[2bbe924ad8] | 1 | /*! |
---|
| 2 | * \file tspmodel.h |
---|
[21c03af787] | 3 | * \author Copyright © 2007-2013 Oleksii Serdiuk <contacts[at]oleksii[dot]name> |
---|
[2bbe924ad8] | 4 | * |
---|
[7ba743d983] | 5 | * $Id: $Format:%h %ai %an$ $ |
---|
| 6 | * $URL: http://tspsg.info/ $ |
---|
[2bbe924ad8] | 7 | * |
---|
| 8 | * \brief Defines CTSPModel class. |
---|
| 9 | * |
---|
| 10 | * <b>TSPSG: TSP Solver and Generator</b> |
---|
| 11 | * |
---|
| 12 | * This file is part of TSPSG. |
---|
| 13 | * |
---|
| 14 | * TSPSG is free software: you can redistribute it and/or modify |
---|
| 15 | * it under the terms of the GNU General Public License as published by |
---|
| 16 | * the Free Software Foundation, either version 3 of the License, or |
---|
| 17 | * (at your option) any later version. |
---|
| 18 | * |
---|
| 19 | * TSPSG is distributed in the hope that it will be useful, |
---|
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 22 | * GNU General Public License for more details. |
---|
| 23 | * |
---|
| 24 | * You should have received a copy of the GNU General Public License |
---|
| 25 | * along with TSPSG. If not, see <http://www.gnu.org/licenses/>. |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | #ifndef TSPMODEL_H |
---|
| 29 | #define TSPMODEL_H |
---|
| 30 | |
---|
| 31 | #include "globals.h" |
---|
| 32 | |
---|
[07e43cf61a] | 33 | #include <QAbstractTableModel> |
---|
| 34 | #include <QDataStream> |
---|
| 35 | #include <QVector> |
---|
| 36 | |
---|
[2bbe924ad8] | 37 | /*! |
---|
| 38 | * \brief This class implements table model for manipulating a task. |
---|
[21c03af787] | 39 | * \author Copyright © 2007-2013 Oleksii Serdiuk <contacts[at]oleksii[dot]name> |
---|
[2bbe924ad8] | 40 | */ |
---|
| 41 | class CTSPModel: public QAbstractTableModel |
---|
| 42 | { |
---|
[9eb63a1598] | 43 | Q_OBJECT |
---|
[2bbe924ad8] | 44 | |
---|
| 45 | public: |
---|
[9eb63a1598] | 46 | CTSPModel(QObject *parent = 0); |
---|
| 47 | void clear(); |
---|
| 48 | int columnCount(const QModelIndex &parent = QModelIndex()) const; |
---|
| 49 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
---|
| 50 | Qt::ItemFlags flags(const QModelIndex &index) const; |
---|
| 51 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; |
---|
| 52 | bool loadTask(const QString &fname); |
---|
| 53 | quint16 numCities() const; |
---|
| 54 | void randomize(); |
---|
| 55 | int rowCount(const QModelIndex &parent = QModelIndex()) const; |
---|
| 56 | bool saveTask(const QString &fname); |
---|
| 57 | bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); |
---|
| 58 | void setNumCities(int n); |
---|
[2bbe924ad8] | 59 | |
---|
| 60 | signals: |
---|
[9eb63a1598] | 61 | /*! |
---|
| 62 | * \brief This signal is emitted whenever the number of cities in the task changes. |
---|
| 63 | * |
---|
| 64 | * \sa setNumCities() |
---|
| 65 | */ |
---|
| 66 | void numCitiesChanged(int); |
---|
[2bbe924ad8] | 67 | |
---|
| 68 | private: |
---|
[9eb63a1598] | 69 | QSettings *settings; |
---|
| 70 | QVector<QVector<double> > table; |
---|
| 71 | quint16 nCities; |
---|
| 72 | bool loadError(QDataStream::Status); |
---|
| 73 | bool loadTSPT(QDataStream *); |
---|
| 74 | bool loadZKT(QDataStream *); |
---|
| 75 | double rand(int, int) const; |
---|
[2bbe924ad8] | 76 | }; |
---|
| 77 | |
---|
| 78 | #endif // TSPMODEL_H |
---|