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/database.h \
|
||||
$$PWD/src/database_p.h \
|
||||
$$PWD/src/dbgeography.h
|
||||
$$PWD/src/dbgeography.h \
|
||||
$$PWD/src/serializableobject.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/src/tableset.cpp \
|
||||
|
|
@ -40,4 +41,5 @@ SOURCES += \
|
|||
$$PWD/src/wherephrase.cpp \
|
||||
$$PWD/src/table.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(int, versionMajor, versionMajor, setVersionMajor)
|
||||
|
||||
NUT_DECLARE_FIELD(int, versionMinor, versionMinor, setVersionMinor)
|
||||
NUT_DECLARE_FIELD(QString, version, version, setVersion)
|
||||
|
||||
public:
|
||||
ChangeLogTable();
|
||||
|
|
|
|||
|
|
@ -136,17 +136,13 @@ bool DatabasePrivate::updateDatabase()
|
|||
|
||||
if (db.lastError().type() == QSqlError::NoError) {
|
||||
|
||||
q->databaseUpdated(last.versionMajor(), last.versionMinor(),
|
||||
current.versionMajor(), current.versionMinor());
|
||||
QString versionText = QString::number(current.versionMajor()) + "_"
|
||||
+ QString::number(current.versionMinor());
|
||||
q->databaseUpdated(last.version(), current.version());
|
||||
|
||||
for (int i = 0; i < q->metaObject()->methodCount(); i++) {
|
||||
QMetaMethod m = q->metaObject()->method(i);
|
||||
if (m.name() == "update" + versionText) {
|
||||
if (m.name() == "update" + current.version()) {
|
||||
m.invoke(q, Qt::DirectConnection,
|
||||
Q_ARG(int, current.versionMajor()),
|
||||
Q_ARG(int, current.versionMinor()));
|
||||
Q_ARG(QString, current.version()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -187,11 +183,14 @@ bool DatabasePrivate::getCurrectScheema()
|
|||
tables.insert(ciName.split(" ").at(1), ci.value());
|
||||
|
||||
if (ciName == __nut_DB_VERSION) {
|
||||
currentModel.setVersion(QString(ci.value()));
|
||||
|
||||
/* TODO: remove
|
||||
QStringList version
|
||||
= QString(ci.value()).replace("\"", "").split('.');
|
||||
bool ok = false;
|
||||
if (version.length() == 1) {
|
||||
currentModel.setVersionMajor(version.at(0).toInt(&ok));
|
||||
currentModel.setVersion(version.at(0).toInt(&ok));
|
||||
} else if (version.length() == 2) {
|
||||
currentModel.setVersionMajor(version.at(0).toInt(&ok));
|
||||
currentModel.setVersionMinor(version.at(1).toInt(&ok));
|
||||
|
|
@ -199,7 +198,7 @@ bool DatabasePrivate::getCurrectScheema()
|
|||
|
||||
if (!ok)
|
||||
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();
|
||||
changeLog->setData(QJsonDocument(current.toJson()).toJson());
|
||||
changeLog->setVersionMajor(current.versionMajor());
|
||||
changeLog->setVersionMinor(current.versionMinor());
|
||||
changeLog->setVersion(current.version());
|
||||
changeLogs->append(changeLog);
|
||||
q->saveChanges();
|
||||
changeLog->deleteLater();
|
||||
|
|
@ -443,13 +441,10 @@ SqlGeneratorBase *Database::sqlGenertor() const
|
|||
return d->sqlGenertor;
|
||||
}
|
||||
|
||||
void Database::databaseUpdated(int oldMajor, int oldMinor, int newMajor,
|
||||
int newMinor)
|
||||
void Database::databaseUpdated(QString oldVersion, QString newVersion)
|
||||
{
|
||||
Q_UNUSED(oldMajor);
|
||||
Q_UNUSED(oldMinor);
|
||||
Q_UNUSED(newMajor);
|
||||
Q_UNUSED(newMinor);
|
||||
Q_UNUSED(oldVersion);
|
||||
Q_UNUSED(newVersion);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -71,8 +71,7 @@ public:
|
|||
|
||||
protected:
|
||||
//remove minor version
|
||||
virtual void databaseUpdated(int oldMajor, int oldMinor, int newMajor,
|
||||
int newMinor);
|
||||
virtual void databaseUpdated(QString oldVersion, QString newVersion);
|
||||
|
||||
public slots:
|
||||
void setDatabaseName(QString databaseName);
|
||||
|
|
|
|||
|
|
@ -27,12 +27,12 @@ NUT_BEGIN_NAMESPACE
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int DatabaseModel::versionMajor() const
|
||||
QString DatabaseModel::version() const
|
||||
{
|
||||
return _versionMajor;
|
||||
return _version;
|
||||
}
|
||||
|
||||
void DatabaseModel::setVersionMajor(int versionMajor)
|
||||
void DatabaseModel::setVersion(QString version)
|
||||
{
|
||||
_versionMajor = versionMajor;
|
||||
}
|
||||
|
||||
int DatabaseModel::versionMinor() const
|
||||
{
|
||||
return _versionMinor;
|
||||
}
|
||||
|
||||
void DatabaseModel::setVersionMinor(int versionMinor)
|
||||
{
|
||||
_versionMinor = versionMinor;
|
||||
_version = version;
|
||||
}
|
||||
|
||||
bool DatabaseModel::remove(const QString &tableName)
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ struct RelationModel;
|
|||
class DatabaseModel : public QList<TableModel *>
|
||||
{
|
||||
QString _databaseClassName;
|
||||
int _versionMajor, _versionMinor;
|
||||
QString _version;
|
||||
static QMap<QString, DatabaseModel *> _models;
|
||||
|
||||
public:
|
||||
|
|
@ -53,11 +53,8 @@ public:
|
|||
static DatabaseModel fromJson(QJsonObject &json);
|
||||
QJsonObject toJson() const;
|
||||
|
||||
int versionMajor() const;
|
||||
void setVersionMajor(int versionMajor);
|
||||
|
||||
int versionMinor() const;
|
||||
void setVersionMinor(int versionMinor);
|
||||
QString version() const;
|
||||
void setVersion(QString version);
|
||||
|
||||
bool remove(const QString &tableName);
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
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());
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
return m_latitude;
|
||||
|
|
@ -59,6 +73,11 @@ void DbGeography::setLongitude(qreal longitude)
|
|||
m_longitude = longitude;
|
||||
}
|
||||
|
||||
/*QVariant Nut::DbGeography::operator QVariant()
|
||||
{
|
||||
return QVariant::fromValue(QString("%1,%2").arg(longitude()).arg(latitude()));
|
||||
}*/
|
||||
|
||||
QString DbGeography::toString()
|
||||
{
|
||||
return QString("%1,%2").arg(longitude()).arg(latitude());
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#include "defines.h"
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/qglobal.h>
|
||||
#include <QVariant>
|
||||
|
||||
NUT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -35,6 +36,7 @@ class NUT_EXPORT DbGeography //: public QObject
|
|||
public:
|
||||
explicit DbGeography(QObject *parent = 0);
|
||||
DbGeography(const DbGeography &other);
|
||||
DbGeography(const QVariant &value);
|
||||
|
||||
qreal latitude() const;
|
||||
qreal longitude() const;
|
||||
|
|
@ -42,16 +44,14 @@ public:
|
|||
void setLatitude(qreal latitude);
|
||||
void setLongitude(qreal longitude);
|
||||
|
||||
//QVariant operator QVariant();
|
||||
|
||||
QString toString();
|
||||
void fromString(const QString &s);
|
||||
};
|
||||
|
||||
NUT_END_NAMESPACE
|
||||
|
||||
#ifdef NUT_NAMESPACE
|
||||
Q_DECLARE_METATYPE(NUT_NAMESPACE::DbGeography)
|
||||
#else
|
||||
Q_DECLARE_METATYPE(DbGeography)
|
||||
#endif
|
||||
Q_DECLARE_METATYPE(NUT_WRAP_NAMESPACE(DbGeography))
|
||||
|
||||
#endif // DBGEOGRAPHY_H
|
||||
|
|
|
|||
|
|
@ -33,17 +33,6 @@
|
|||
# define NUT_EXPORT Q_DECL_EXPORT
|
||||
#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
|
||||
//TODO: remove minor version
|
||||
#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
|
||||
# define NUT_BEGIN_NAMESPACE namespace NUT_NAMESPACE{
|
||||
# define NUT_END_NAMESPACE }
|
||||
# define NUT_WRAP_NAMESPACE(x) NUT_NAMESPACE::x
|
||||
#else
|
||||
# define NUT_BEGIN_NAMESPACE
|
||||
# define NUT_END_NAMESPACE
|
||||
# define NUT_WRAP_NAMESPACE(x) x
|
||||
#endif
|
||||
|
||||
#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