version text (int, int) => (QString)
This commit is contained in:
parent
99462cf0b3
commit
a35c9f8ffb
6
nut.pri
6
nut.pri
|
|
@ -22,7 +22,8 @@ HEADERS += \
|
||||||
$$PWD/src/table.h \
|
$$PWD/src/table.h \
|
||||||
$$PWD/src/database.h \
|
$$PWD/src/database.h \
|
||||||
$$PWD/src/database_p.h \
|
$$PWD/src/database_p.h \
|
||||||
$$PWD/src/dbgeography.h
|
$$PWD/src/dbgeography.h \
|
||||||
|
$$PWD/src/serializableobject.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/src/tableset.cpp \
|
$$PWD/src/tableset.cpp \
|
||||||
|
|
@ -40,4 +41,5 @@ SOURCES += \
|
||||||
$$PWD/src/wherephrase.cpp \
|
$$PWD/src/wherephrase.cpp \
|
||||||
$$PWD/src/table.cpp \
|
$$PWD/src/table.cpp \
|
||||||
$$PWD/src/database.cpp \
|
$$PWD/src/database.cpp \
|
||||||
$$PWD/src/dbgeography.cpp
|
$$PWD/src/dbgeography.cpp \
|
||||||
|
$$PWD/src/serializableobject.cpp
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,7 @@ class ChangeLogTable : public Table
|
||||||
|
|
||||||
NUT_DECLARE_FIELD(QString, data, data, setData)
|
NUT_DECLARE_FIELD(QString, data, data, setData)
|
||||||
|
|
||||||
NUT_DECLARE_FIELD(int, versionMajor, versionMajor, setVersionMajor)
|
NUT_DECLARE_FIELD(QString, version, version, setVersion)
|
||||||
|
|
||||||
NUT_DECLARE_FIELD(int, versionMinor, versionMinor, setVersionMinor)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ChangeLogTable();
|
ChangeLogTable();
|
||||||
|
|
|
||||||
|
|
@ -136,17 +136,13 @@ bool DatabasePrivate::updateDatabase()
|
||||||
|
|
||||||
if (db.lastError().type() == QSqlError::NoError) {
|
if (db.lastError().type() == QSqlError::NoError) {
|
||||||
|
|
||||||
q->databaseUpdated(last.versionMajor(), last.versionMinor(),
|
q->databaseUpdated(last.version(), current.version());
|
||||||
current.versionMajor(), current.versionMinor());
|
|
||||||
QString versionText = QString::number(current.versionMajor()) + "_"
|
|
||||||
+ QString::number(current.versionMinor());
|
|
||||||
|
|
||||||
for (int i = 0; i < q->metaObject()->methodCount(); i++) {
|
for (int i = 0; i < q->metaObject()->methodCount(); i++) {
|
||||||
QMetaMethod m = q->metaObject()->method(i);
|
QMetaMethod m = q->metaObject()->method(i);
|
||||||
if (m.name() == "update" + versionText) {
|
if (m.name() == "update" + current.version()) {
|
||||||
m.invoke(q, Qt::DirectConnection,
|
m.invoke(q, Qt::DirectConnection,
|
||||||
Q_ARG(int, current.versionMajor()),
|
Q_ARG(QString, current.version()));
|
||||||
Q_ARG(int, current.versionMinor()));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -187,11 +183,14 @@ bool DatabasePrivate::getCurrectScheema()
|
||||||
tables.insert(ciName.split(" ").at(1), ci.value());
|
tables.insert(ciName.split(" ").at(1), ci.value());
|
||||||
|
|
||||||
if (ciName == __nut_DB_VERSION) {
|
if (ciName == __nut_DB_VERSION) {
|
||||||
|
currentModel.setVersion(QString(ci.value()));
|
||||||
|
|
||||||
|
/* TODO: remove
|
||||||
QStringList version
|
QStringList version
|
||||||
= QString(ci.value()).replace("\"", "").split('.');
|
= QString(ci.value()).replace("\"", "").split('.');
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
if (version.length() == 1) {
|
if (version.length() == 1) {
|
||||||
currentModel.setVersionMajor(version.at(0).toInt(&ok));
|
currentModel.setVersion(version.at(0).toInt(&ok));
|
||||||
} else if (version.length() == 2) {
|
} else if (version.length() == 2) {
|
||||||
currentModel.setVersionMajor(version.at(0).toInt(&ok));
|
currentModel.setVersionMajor(version.at(0).toInt(&ok));
|
||||||
currentModel.setVersionMinor(version.at(1).toInt(&ok));
|
currentModel.setVersionMinor(version.at(1).toInt(&ok));
|
||||||
|
|
@ -199,7 +198,7 @@ bool DatabasePrivate::getCurrectScheema()
|
||||||
|
|
||||||
if (!ok)
|
if (!ok)
|
||||||
qFatal("NUT_DB_VERSION macro accept version in format 'x' or "
|
qFatal("NUT_DB_VERSION macro accept version in format 'x' or "
|
||||||
"'x[.y]' only, and x,y must be integer values\n");
|
"'x[.y]' only, and x,y must be integer values\n");*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -270,8 +269,7 @@ bool DatabasePrivate::storeScheemaInDB()
|
||||||
|
|
||||||
ChangeLogTable *changeLog = new ChangeLogTable();
|
ChangeLogTable *changeLog = new ChangeLogTable();
|
||||||
changeLog->setData(QJsonDocument(current.toJson()).toJson());
|
changeLog->setData(QJsonDocument(current.toJson()).toJson());
|
||||||
changeLog->setVersionMajor(current.versionMajor());
|
changeLog->setVersion(current.version());
|
||||||
changeLog->setVersionMinor(current.versionMinor());
|
|
||||||
changeLogs->append(changeLog);
|
changeLogs->append(changeLog);
|
||||||
q->saveChanges();
|
q->saveChanges();
|
||||||
changeLog->deleteLater();
|
changeLog->deleteLater();
|
||||||
|
|
@ -443,13 +441,10 @@ SqlGeneratorBase *Database::sqlGenertor() const
|
||||||
return d->sqlGenertor;
|
return d->sqlGenertor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Database::databaseUpdated(int oldMajor, int oldMinor, int newMajor,
|
void Database::databaseUpdated(QString oldVersion, QString newVersion)
|
||||||
int newMinor)
|
|
||||||
{
|
{
|
||||||
Q_UNUSED(oldMajor);
|
Q_UNUSED(oldVersion);
|
||||||
Q_UNUSED(oldMinor);
|
Q_UNUSED(newVersion);
|
||||||
Q_UNUSED(newMajor);
|
|
||||||
Q_UNUSED(newMinor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,8 +71,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//remove minor version
|
//remove minor version
|
||||||
virtual void databaseUpdated(int oldMajor, int oldMinor, int newMajor,
|
virtual void databaseUpdated(QString oldVersion, QString newVersion);
|
||||||
int newMinor);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setDatabaseName(QString databaseName);
|
void setDatabaseName(QString databaseName);
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,12 @@ NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
QMap<QString, DatabaseModel*> DatabaseModel::_models;
|
QMap<QString, DatabaseModel*> DatabaseModel::_models;
|
||||||
|
|
||||||
DatabaseModel::DatabaseModel(const QString &name) : QList<TableModel*>(), _databaseClassName(name), _versionMajor(0), _versionMinor(0)
|
DatabaseModel::DatabaseModel(const QString &name) : QList<TableModel*>(), _databaseClassName(name), _version(QString::null)
|
||||||
{
|
{
|
||||||
_models.insert(name, this);
|
_models.insert(name, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseModel::DatabaseModel(const DatabaseModel &other) : QList<TableModel*>(other), _versionMajor(0), _versionMinor(0)
|
DatabaseModel::DatabaseModel(const DatabaseModel &other) : QList<TableModel*>(other), _version(QString::null)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -145,24 +145,14 @@ DatabaseModel DatabaseModel::fromJson(QJsonObject &json)
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DatabaseModel::versionMajor() const
|
QString DatabaseModel::version() const
|
||||||
{
|
{
|
||||||
return _versionMajor;
|
return _version;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseModel::setVersionMajor(int versionMajor)
|
void DatabaseModel::setVersion(QString version)
|
||||||
{
|
{
|
||||||
_versionMajor = versionMajor;
|
_version = version;
|
||||||
}
|
|
||||||
|
|
||||||
int DatabaseModel::versionMinor() const
|
|
||||||
{
|
|
||||||
return _versionMinor;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DatabaseModel::setVersionMinor(int versionMinor)
|
|
||||||
{
|
|
||||||
_versionMinor = versionMinor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DatabaseModel::remove(const QString &tableName)
|
bool DatabaseModel::remove(const QString &tableName)
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ struct RelationModel;
|
||||||
class DatabaseModel : public QList<TableModel *>
|
class DatabaseModel : public QList<TableModel *>
|
||||||
{
|
{
|
||||||
QString _databaseClassName;
|
QString _databaseClassName;
|
||||||
int _versionMajor, _versionMinor;
|
QString _version;
|
||||||
static QMap<QString, DatabaseModel *> _models;
|
static QMap<QString, DatabaseModel *> _models;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -53,11 +53,8 @@ public:
|
||||||
static DatabaseModel fromJson(QJsonObject &json);
|
static DatabaseModel fromJson(QJsonObject &json);
|
||||||
QJsonObject toJson() const;
|
QJsonObject toJson() const;
|
||||||
|
|
||||||
int versionMajor() const;
|
QString version() const;
|
||||||
void setVersionMajor(int versionMajor);
|
void setVersion(QString version);
|
||||||
|
|
||||||
int versionMinor() const;
|
|
||||||
void setVersionMinor(int versionMinor);
|
|
||||||
|
|
||||||
bool remove(const QString &tableName);
|
bool remove(const QString &tableName);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
NUT_BEGIN_NAMESPACE
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
DbGeography::DbGeography(QObject *parent)
|
DbGeography::DbGeography(QObject *parent) : m_longitude(0), m_latitude(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -33,6 +33,20 @@ DbGeography::DbGeography(const DbGeography &other)
|
||||||
setLongitude(other.longitude());
|
setLongitude(other.longitude());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DbGeography::DbGeography(const QVariant &value)
|
||||||
|
{
|
||||||
|
QStringList parts = value.toString().split(',');
|
||||||
|
if (parts.count() == 2) {
|
||||||
|
setLongitude(parts[0].toDouble());
|
||||||
|
setLatitude(parts[1].toDouble());
|
||||||
|
} else {
|
||||||
|
qWarning("Input value for DbGeography is invalid: %s",
|
||||||
|
qPrintable(value.toString()));
|
||||||
|
setLongitude(0);
|
||||||
|
setLatitude(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
qreal DbGeography::latitude() const
|
qreal DbGeography::latitude() const
|
||||||
{
|
{
|
||||||
return m_latitude;
|
return m_latitude;
|
||||||
|
|
@ -59,6 +73,11 @@ void DbGeography::setLongitude(qreal longitude)
|
||||||
m_longitude = longitude;
|
m_longitude = longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*QVariant Nut::DbGeography::operator QVariant()
|
||||||
|
{
|
||||||
|
return QVariant::fromValue(QString("%1,%2").arg(longitude()).arg(latitude()));
|
||||||
|
}*/
|
||||||
|
|
||||||
QString DbGeography::toString()
|
QString DbGeography::toString()
|
||||||
{
|
{
|
||||||
return QString("%1,%2").arg(longitude()).arg(latitude());
|
return QString("%1,%2").arg(longitude()).arg(latitude());
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/qglobal.h>
|
#include <QtCore/qglobal.h>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
NUT_BEGIN_NAMESPACE
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
|
@ -35,6 +36,7 @@ class NUT_EXPORT DbGeography //: public QObject
|
||||||
public:
|
public:
|
||||||
explicit DbGeography(QObject *parent = 0);
|
explicit DbGeography(QObject *parent = 0);
|
||||||
DbGeography(const DbGeography &other);
|
DbGeography(const DbGeography &other);
|
||||||
|
DbGeography(const QVariant &value);
|
||||||
|
|
||||||
qreal latitude() const;
|
qreal latitude() const;
|
||||||
qreal longitude() const;
|
qreal longitude() const;
|
||||||
|
|
@ -42,16 +44,14 @@ public:
|
||||||
void setLatitude(qreal latitude);
|
void setLatitude(qreal latitude);
|
||||||
void setLongitude(qreal longitude);
|
void setLongitude(qreal longitude);
|
||||||
|
|
||||||
|
//QVariant operator QVariant();
|
||||||
|
|
||||||
QString toString();
|
QString toString();
|
||||||
void fromString(const QString &s);
|
void fromString(const QString &s);
|
||||||
};
|
};
|
||||||
|
|
||||||
NUT_END_NAMESPACE
|
NUT_END_NAMESPACE
|
||||||
|
|
||||||
#ifdef NUT_NAMESPACE
|
Q_DECLARE_METATYPE(NUT_WRAP_NAMESPACE(DbGeography))
|
||||||
Q_DECLARE_METATYPE(NUT_NAMESPACE::DbGeography)
|
|
||||||
#else
|
|
||||||
Q_DECLARE_METATYPE(DbGeography)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // DBGEOGRAPHY_H
|
#endif // DBGEOGRAPHY_H
|
||||||
|
|
|
||||||
|
|
@ -33,17 +33,6 @@
|
||||||
# define NUT_EXPORT Q_DECL_EXPORT
|
# define NUT_EXPORT Q_DECL_EXPORT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef NUT_NAMESPACE
|
|
||||||
//TODO: remove unused macro
|
|
||||||
# define __NUT_NAMESPACE_PERFIX NUT_NAMESPACE::
|
|
||||||
# define NUT_WRAP_NAMESPACE(x) NUT_NAMESPACE::x
|
|
||||||
#else
|
|
||||||
//TODO: remove unused macro
|
|
||||||
# define __NUT_NAMESPACE_PERFIX
|
|
||||||
# define NUT_WRAP_NAMESPACE(x) x
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Database
|
// Database
|
||||||
//TODO: remove minor version
|
//TODO: remove minor version
|
||||||
#define NUT_DB_VERSION(major, minor) Q_CLASSINFO(QT_STRINGIFY(__nut_NAME_PERFIX __nut_DB_VERSION), QT_STRINGIFY(#major "." #minor))
|
#define NUT_DB_VERSION(major, minor) Q_CLASSINFO(QT_STRINGIFY(__nut_NAME_PERFIX __nut_DB_VERSION), QT_STRINGIFY(#major "." #minor))
|
||||||
|
|
|
||||||
|
|
@ -46,9 +46,11 @@
|
||||||
#ifdef NUT_NAMESPACE
|
#ifdef NUT_NAMESPACE
|
||||||
# define NUT_BEGIN_NAMESPACE namespace NUT_NAMESPACE{
|
# define NUT_BEGIN_NAMESPACE namespace NUT_NAMESPACE{
|
||||||
# define NUT_END_NAMESPACE }
|
# define NUT_END_NAMESPACE }
|
||||||
|
# define NUT_WRAP_NAMESPACE(x) NUT_NAMESPACE::x
|
||||||
#else
|
#else
|
||||||
# define NUT_BEGIN_NAMESPACE
|
# define NUT_BEGIN_NAMESPACE
|
||||||
# define NUT_END_NAMESPACE
|
# define NUT_END_NAMESPACE
|
||||||
|
# define NUT_WRAP_NAMESPACE(x) x
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // DEFINES_P_H
|
#endif // DEFINES_P_H
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include "serializableobject.h"
|
||||||
|
|
||||||
|
SerializableObject::SerializableObject()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef SERIALIZABLEOBJECT_H
|
||||||
|
#define SERIALIZABLEOBJECT_H
|
||||||
|
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
class SerializableObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SerializableObject();
|
||||||
|
|
||||||
|
virtual void load(const QVariant &value) = 0;
|
||||||
|
virtual QVariant save() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SERIALIZABLEOBJECT_H
|
||||||
Loading…
Reference in New Issue