Index: src/tspmodel.cpp
===================================================================
--- src/tspmodel.cpp	(revision 2f915f19f2f69c8a5ed7887fe6055c10eceb97fa)
+++ src/tspmodel.cpp	(revision 2f915f19f2f69c8a5ed7887fe6055c10eceb97fa)
@@ -0,0 +1,107 @@
+/*
+ *  TSPSG - TSP Solver and Generator
+ *  Copyright (C) 2007 L¸ppa <lacontacts[at]gmail[dot]com>
+ *
+ *  $Id$
+ *  $URL$
+ *
+ *  This file is part of TSPSG.
+ *
+ *  TSPSG is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  TSPSG is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with TSPSG.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "tspmodel.h"
+#include <QTGui>
+
+CTSPModel::CTSPModel(QObject *parent)
+	: QAbstractTableModel(parent), randMin(1), randMax(10)
+{
+}
+
+int CTSPModel::rand(int min, int max)
+{
+	return min + (int)(((float)qrand() / RAND_MAX) * max);
+}
+
+int CTSPModel::rowCount(const QModelIndex &) const
+{
+	return nCities;
+}
+
+int CTSPModel::columnCount(const QModelIndex &) const
+{
+	return nCities;
+}
+
+QVariant CTSPModel::headerData(int section, Qt::Orientation, int role) const
+{
+	if (role == Qt::DisplayRole)
+		return trUtf8("Ãîðîä %1").arg(section + 1);
+	return QVariant();
+}
+
+QVariant CTSPModel::data(const QModelIndex &index, int role) const
+{
+	if (!index.isValid())
+		return QVariant();
+	if (role == Qt::TextAlignmentRole)
+		return int(Qt::AlignCenter);
+	else if (role == Qt::DisplayRole) {
+		if (index.row() == index.column())
+			return trUtf8("---");
+		if (index.row() < nCities && index.column() < nCities)
+			return table.at(index.row())->at(index.column());
+		else
+			return QVariant();
+	}
+	return QVariant();
+}
+
+bool CTSPModel::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+	return true;
+}
+
+Qt::ItemFlags CTSPModel::flags(const QModelIndex &index) const
+{
+Qt::ItemFlags flags = QAbstractItemModel::flags(index);
+	if (index.row() == index.column())
+		flags |= Qt::ItemIsEditable;
+	return flags;
+}
+
+int CTSPModel::numCities() const
+{
+	return nCities;
+}
+
+void CTSPModel::setNumCities(int n)
+{
+	if (n > nCities) {
+		foreach(QList<double> *row,table) {
+			for (int k = nCities; k < n; k++)
+				row->append(rand(randMin,randMax));
+		}
+		for (int k = nCities; k < n; k++) {
+QList<double> *row = new QList<double>[n];
+			foreach(double cell,*row)
+				cell = rand(randMin,randMax);
+			table.append(row);
+		}
+	} else if (n < nCities) {
+		// TODO: Shrinking table
+	}
+	nCities = n;
+}
+
Index: src/tspmodel.h
===================================================================
--- src/tspmodel.h	(revision 2f915f19f2f69c8a5ed7887fe6055c10eceb97fa)
+++ src/tspmodel.h	(revision 2f915f19f2f69c8a5ed7887fe6055c10eceb97fa)
@@ -0,0 +1,51 @@
+/*
+ *  TSPSG - TSP Solver and Generator
+ *  Copyright (C) 2007 L¸ppa <lacontacts[at]gmail[dot]com>
+ *
+ *  $Id$
+ *  $URL$
+ *
+ *  This file is part of TSPSG.
+ *
+ *  TSPSG is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  TSPSG is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with TSPSG.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TSPMODEL_H
+#define TSPMODEL_H
+
+#include <QAbstractTableModel>
+
+class CTSPModel: public QAbstractTableModel
+{
+	Q_OBJECT
+public:
+	CTSPModel(QObject *parent = 0);
+	int rowCount(const QModelIndex &) const;
+	int columnCount(const QModelIndex &) const;
+	QVariant headerData(int, Qt::Orientation, int) const;
+	QVariant data(const QModelIndex &, int) const;
+	bool setData(const QModelIndex &, const QVariant &, int);
+	Qt::ItemFlags flags(const QModelIndex &) const;
+	int numCities() const;
+	void setNumCities(int);
+	int randMin;
+	int randMax;
+private:
+	QList<QList<double> *> table;
+	int nCities;
+	int rand(int, int);
+};
+
+#endif // TSPMODEL_H
+
Index: tspsg.pro
===================================================================
--- tspsg.pro	(revision e664262f7daeea9cf5efbaa2671e7bb27f76650c)
+++ tspsg.pro	(revision 2f915f19f2f69c8a5ed7887fe6055c10eceb97fa)
@@ -1,4 +1,4 @@
 ######################################################################
-# Automatically generated by qmake (2.01a) ?? 20. ??? 18:37:06 2007
+# Automatically generated by qmake (2.01a) ?? 30. ??? 22:14:47 2007
 ######################################################################
 
@@ -9,9 +9,10 @@
 
 # Input
-HEADERS += src/mainwindow.h src/settingsdialog.h src/tspsolver.h
+HEADERS += src/mainwindow.h src/settingsdialog.h src/tspmodel.h src/tspsolver.h
 FORMS += ui/mainwindow.ui ui/settingsdialog.ui
 SOURCES += src/main.cpp \
            src/mainwindow.cpp \
            src/settingsdialog.cpp \
+           src/tspmodel.cpp \
            src/tspsolver.cpp
 RESOURCES += resources/tspsg.qrc
