TSP Solver and Generator
tspmodel.h
Go to the documentation of this file.
1 
28 #ifndef TSPMODEL_H
29 #define TSPMODEL_H
30 
31 #include "globals.h"
32 
33 #include <QAbstractTableModel>
34 #include <QDataStream>
35 #include <QVector>
36 
42 {
43  Q_OBJECT
44 
45 public:
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);
59 
60 signals:
66  void numCitiesChanged(int);
67 
68 private:
69  QSettings *settings;
71  quint16 nCities;
72  bool loadError(QDataStream::Status);
73  bool loadTSPT(QDataStream *);
74  bool loadZKT(QDataStream *);
75  double rand(int, int) const;
76 };
77 
78 #endif // TSPMODEL_H
bool saveTask(const QString &fname)
Saves current task to fname.
Definition: tspmodel.cpp:238
void numCitiesChanged(int)
This signal is emitted whenever the number of cities in the task changes.
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
void clear()
Resets the table, setting all its elements to 0.
Definition: tspmodel.cpp:47
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Sets the role data for the item at index to value.
Definition: tspmodel.cpp:329
Contains TSPSG global defines.
void setNumCities(int n)
Sets number of cities in the current task to n.
Definition: tspmodel.cpp:360
int rowCount(const QModelIndex &parent=QModelIndex()) const
Returns the row count in the table.
Definition: tspmodel.cpp:226
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Returns the data for the given role and section in the header with the specified orientation.
Definition: tspmodel.cpp:123
quint16 numCities() const
Returns the number of cities.
Definition: tspmodel.cpp:189
int columnCount(const QModelIndex &parent=QModelIndex()) const
Returns the column count in the table.
Definition: tspmodel.cpp:64
bool loadTask(const QString &fname)
Loads a task from fname.
Definition: tspmodel.cpp:141
CTSPModel(QObject *parent=0)
Class constructor.
Definition: tspmodel.cpp:39
void randomize()
Randomizes the table by setting all its values to random ones.
Definition: tspmodel.cpp:201
Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
Definition: tspmodel.cpp:106
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Returns the data stored under the given role for the item referred to by the index.
Definition: tspmodel.cpp:77
QObject * parent() const
This class implements table model for manipulating a task.
Definition: tspmodel.h:41
typedef ItemFlags