TSP Solver and Generator
|
This class implements table model for manipulating a task. More...
#include <tspmodel.h>
Signals | |
void | numCitiesChanged (int) |
This signal is emitted whenever the number of cities in the task changes. | |
Public Member Functions | |
CTSPModel (QObject *parent=0) | |
Class constructor. | |
void | clear () |
Resets the table, setting all its elements to 0. | |
int | columnCount (const QModelIndex &parent=QModelIndex()) const |
Returns the column count in the table. | |
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. | |
Qt::ItemFlags | flags (const QModelIndex &index) const |
Returns the item flags for the given index. | |
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. | |
bool | loadTask (const QString &fname) |
Loads a task from fname. | |
quint16 | numCities () const |
Returns the number of cities. | |
void | randomize () |
Randomizes the table by setting all its values to random ones. | |
int | rowCount (const QModelIndex &parent=QModelIndex()) const |
Returns the row count in the table. | |
bool | saveTask (const QString &fname) |
Saves current task to fname. | |
bool | setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) |
Sets the role data for the item at index to value. | |
void | setNumCities (int n) |
Sets number of cities in the current task to n. |
This class implements table model for manipulating a task.
CTSPModel::CTSPModel | ( | QObject * | parent = 0 | ) |
Class constructor.
parent | The parent of the table model. |
void CTSPModel::clear | ( | ) |
Resets the table, setting all its elements to 0.
int CTSPModel::columnCount | ( | const QModelIndex & | parent = QModelIndex() | ) | const |
Returns the column count in the table.
Actually, this function returns the number of cities in the current task.
Reimplemented from QAbstractItemModel.
QVariant CTSPModel::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.
index | An item index to get data from. |
role | The role to get data for. |
Reimplemented from QAbstractItemModel.
Qt::ItemFlags CTSPModel::flags | ( | const QModelIndex & | index | ) | const [virtual] |
Returns the item flags for the given index.
index | An item index to get flags from. |
Reimplemented from QAbstractItemModel.
QVariant CTSPModel::headerData | ( | int | section, |
Qt::Orientation | orientation, | ||
int | role = Qt::DisplayRole |
||
) | const [virtual] |
Returns the data for the given role and section in the header with the specified orientation.
section | The section to get header data for. |
orientation | The orientation to get header data for. |
role | The role to get header data for. |
For horizontal headers, the section number corresponds to the column number of items shown beneath it. For vertical headers, the section number typically to the row number of items shown alongside it.
Reimplemented from QAbstractItemModel.
bool CTSPModel::loadTask | ( | const QString & | fname | ) |
Loads a task from fname.
fname | The name of the file to be loaded. |
true
on success, otherwise false
.quint16 CTSPModel::numCities | ( | ) | const |
Returns the number of cities.
void CTSPModel::numCitiesChanged | ( | int | ) | [signal] |
This signal is emitted whenever the number of cities in the task changes.
void CTSPModel::randomize | ( | ) |
Randomizes the table by setting all its values to random ones.
Uses TSPSG settings to determine random values range.
int CTSPModel::rowCount | ( | const QModelIndex & | parent = QModelIndex() | ) | const |
Returns the row count in the table.
Actually, this function returns the number of cities in the current task.
Reimplemented from QAbstractItemModel.
bool CTSPModel::saveTask | ( | const QString & | fname | ) |
Saves current task to fname.
fname | The name of the file to seve to. |
true
on success, otherwise false
.bool CTSPModel::setData | ( | const QModelIndex & | index, |
const QVariant & | value, | ||
int | role = Qt::EditRole |
||
) | [virtual] |
Sets the role data for the item at index to value.
index | The index of the item to set data at. |
value | The value of the item data to be set. |
role | The role of the item to set data for. |
true
on success, otherwise false
.Reimplemented from QAbstractItemModel.
void CTSPModel::setNumCities | ( | int | n | ) |
Sets number of cities in the current task to n.
n | Number of cities to set to. |