diff --git a/ChangeLog b/ChangeLog index 9ff2772..8ce8ef9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ QDjango 0.6.0 (UNRELEASED) + * Remove support for QtScript. * Make tests runnable using "make check". * Fix build errors on Windows. * Clarify return values of createTable(s) and dropTable(s). diff --git a/README.md b/README.md index 8a9781b..802e85d 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Qt 4 on Debian: Qt 5 on Debian: - sudo apt-get install qtbase5-dev qtscript5-dev + sudo apt-get install qtbase5-dev Qt 4 on Mac OS X: @@ -61,4 +61,4 @@ Fast forward cursors are used by default. This greatly improves performance, and - Connection pooling must be enabled in your [ODBC manager](http://www.unixodbc.org/doc/conn_pool.html) - You must enable Multiple Active Result Sets in the QODBC driver using "MARS_Connection=Yes" in the connection string -- You must enable connection pooling in the QODBC driver using the "SQL_ATTR_CONNECTION_POOLING" attribute \ No newline at end of file +- You must enable connection pooling in the QODBC driver using the "SQL_ATTR_CONNECTION_POOLING" attribute diff --git a/doc/Doxyfile b/doc/Doxyfile index 15a7a68..1404f03 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -574,7 +574,7 @@ WARN_LOGFILE = # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = database.doc http.doc index.doc models.doc queries.doc script.doc ../src/db ../src/http ../src/script +INPUT = database.doc http.doc index.doc models.doc queries.doc ../src/db ../src/http # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is diff --git a/doc/index.doc b/doc/index.doc index f033dcc..979258c 100644 --- a/doc/index.doc +++ b/doc/index.doc @@ -26,5 +26,4 @@ \sa Database \sa Http - \sa Script */ diff --git a/doc/script.doc b/doc/script.doc deleted file mode 100644 index 23f2874..0000000 --- a/doc/script.doc +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2010-2015 Jeremy Lainé - * Contact: https://github.com/jlaine/qdjango - * - * This file is part of the QDjango Library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - */ - -/*! - -\defgroup Script - -\brief Scripting support for models - -The QDjangoScript class makes it easy to access your models from QtScript. - -\section making-scriptable Making your models scriptable - -You can register a model with a QScriptEngine instance as follows: - -\code -#include -#include - -Q_DECLARE_METATYPE(QDjangoQuerySet) - -QScriptEngine *engine = new QScriptEngine; -QDjangoScript::registerWhere(engine); -QDjangoScript::registerModel(engine); -\endcode - -\section scripting-models Using your models from a script - -Because QDjango makes use of Qt's property system, all model fields can -automatically be accessed from QtScript. -For instance if you declared a \c User model, you can run the following code: - -\code -// create a user instance and save it to database -user = new User(); -user.username = "someuser"; -user.password = "somepassword"; -user.save(); - -// remove the user from database -user.remove(); -\endcode - -You can also perform database queries: - -\code -// filter users whose username is "foouser" and password is "foopass" -qs = User.objects.filter({'username': 'foouser', 'password': 'foopass'}); - -// iterate over the results -for (var i = 0; i < qs.size(); i++) { - user = qs.at(i); - print("found " + user.username); -} - -// remove all matching users from database -qs.remove(); -\endcode - -*/ diff --git a/examples/examples.pro b/examples/examples.pro index 024c1b7..7c90321 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS = http-server script-console +SUBDIRS = http-server diff --git a/examples/script-console/script-console.cpp b/examples/script-console/script-console.cpp deleted file mode 100644 index 8de094f..0000000 --- a/examples/script-console/script-console.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (C) 2010-2015 Jeremy Lainé - * Contact: https://github.com/jlaine/qdjango - * - * This file is part of the QDjango Library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "QDjango.h" -#include "QDjangoScript.h" - -#include "auth-models.h" - -static bool wantsToQuit; - -Q_DECLARE_METATYPE(QDjangoQuerySet) -Q_DECLARE_METATYPE(QDjangoQuerySet) -Q_DECLARE_METATYPE(QDjangoQuerySet) - -static QScriptValue qtscript_dir(QScriptContext *ctx, QScriptEngine *eng) -{ - QObject *obj = ctx->argument(0).toQObject(); - if (obj) - { - const QMetaObject* meta = obj->metaObject(); - for(int i = meta->propertyOffset(); i < meta->propertyCount(); ++i) - qDebug() << meta->property(i).name(); - } - return eng->undefinedValue(); -} - -static QScriptValue qtscript_load(QScriptContext *ctx, QScriptEngine *eng) -{ - QString name = ctx->argument(0).toString(); - eng->importExtension(name); - return eng->undefinedValue(); -} - -static QScriptValue qtscript_quit(QScriptContext *ctx, QScriptEngine *eng) -{ - Q_UNUSED(ctx); - wantsToQuit = true; - return eng->undefinedValue(); -} - -static QScriptValue qtscript_syncdb(QScriptContext *ctx, QScriptEngine *eng) -{ - Q_UNUSED(ctx); - QDjango::createTables(); - return eng->undefinedValue(); -} - -static void interactive(QScriptEngine *eng) -{ - QScriptValue global = eng->globalObject(); - if (!global.property(QLatin1String("dir")).isValid()) - global.setProperty(QLatin1String("dir"), eng->newFunction(qtscript_dir)); - if (!global.property(QLatin1String("load")).isValid()) - global.setProperty(QLatin1String("load"), eng->newFunction(qtscript_load)); - if (!global.property(QLatin1String("quit")).isValid()) - global.setProperty(QLatin1String("quit"), eng->newFunction(qtscript_quit)); - if (!global.property(QLatin1String("syncdb")).isValid()) - global.setProperty(QLatin1String("syncdb"), eng->newFunction(qtscript_syncdb)); - wantsToQuit = false; - - QTextStream qin(stdin, QIODevice::ReadOnly); - - const char *qscript_prompt = "qdjango> "; - const char *dot_prompt = ".... "; - const char *prompt = qscript_prompt; - - QString code; - - printf("Commands:\n" - "\tdir(obj) : print the object's properties\n" - "\tload() : loads a QtScript extension\n" - "\tquit() : exits console\n" - "\tsyncdb() : creates database tables\n"); - - forever { - QString line; - - printf("%s", prompt); - fflush(stdout); - - line = qin.readLine(); - if (line.isNull()) - break; - - code += line; - code += QLatin1Char('\n'); - - if (line.trimmed().isEmpty()) { - continue; - - } else if (! eng->canEvaluate(code)) { - prompt = dot_prompt; - - } else { - QScriptValue result = eng->evaluate(code, QLatin1String("typein")); - - code.clear(); - prompt = qscript_prompt; - - if (! result.isUndefined()) - fprintf(stderr, "%s\n", qPrintable(result.toString())); - - if (wantsToQuit) - break; - } - } -} - -void usage() -{ - fprintf(stderr, "Usage: qdjango-console [options]\n\n"); - fprintf(stderr, "Options:\n"); - fprintf(stderr, "-d use \n"); - fprintf(stderr, "-p add to plugins search path\n"); -} - -int main(int argc, char *argv[]) -{ - QString databaseName(":memory:"); - - /* Create application */ - QCoreApplication app(argc, argv); - - /* Parse command line arguments */ - for (int i = 1; i < argc; i++) - { - if (!strcmp(argv[i], "-h")) - { - usage(); - return EXIT_SUCCESS; - } else if (!strcmp(argv[i], "-d")) { - if (i == argc - 1 || !strlen(argv[i+1]) || argv[i+1][0] == '-') - { - fprintf(stderr, "Option -d requires an argument\n"); - usage(); - return EXIT_FAILURE; - } - databaseName = QString::fromLocal8Bit(argv[++i]); - } else if (!strcmp(argv[i], "-p")) { - if (i == argc - 1 || !strlen(argv[i+1]) || argv[i+1][0] == '-') - { - fprintf(stderr, "Option -p requires an argument\n"); - usage(); - return EXIT_FAILURE; - } - app.setLibraryPaths(app.libraryPaths() << QString::fromLocal8Bit(argv[++i])); - } - } - - /* Open database */ - QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); - db.setDatabaseName(databaseName); - if (!db.open()) - { - fprintf(stderr, "Could not access database '%s'\n", databaseName.toLocal8Bit().constData()); - return EXIT_FAILURE; - } - QDjango::setDatabase(db); - - /* Run interactive shell */ - QScriptEngine *engine = new QScriptEngine(); - QDjangoScript::registerWhere(engine); - QDjangoScript::registerModel(engine); - QDjangoScript::registerModel(engine); - QDjangoScript::registerModel(engine); - - qDebug() << "Available extensions: " << engine->availableExtensions(); - interactive(engine); - - return EXIT_SUCCESS; -} - diff --git a/examples/script-console/script-console.pro b/examples/script-console/script-console.pro deleted file mode 100644 index 8b334f7..0000000 --- a/examples/script-console/script-console.pro +++ /dev/null @@ -1,12 +0,0 @@ -include(../../qdjango.pri) - -QT += script sql - -TARGET = qdjango-script-console - -INCLUDEPATH += ../../tests/db $$QDJANGO_INCLUDEPATH -LIBS += \ - -L../../src/db $$QDJANGO_DB_LIBS \ - -L../../src/script $$QDJANGO_SCRIPT_LIBS -HEADERS += ../../tests/db/auth-models.h -SOURCES += script-console.cpp ../../tests/db/auth-models.cpp diff --git a/qdjango.pri b/qdjango.pri index 2d8ed2e..269d0a1 100644 --- a/qdjango.pri +++ b/qdjango.pri @@ -11,10 +11,9 @@ isEmpty(QDJANGO_LIBRARY_TYPE) { } # Libraries for apps which use QDjango -QDJANGO_INCLUDEPATH = $$PWD/src/db $$PWD/src/http $$PWD/src/script +QDJANGO_INCLUDEPATH = $$PWD/src/db $$PWD/src/http QDJANGO_DB_LIBS = -lqdjango-db QDJANGO_HTTP_LIBS = -lqdjango-http -QDJANGO_SCRIPT_LIBS = -lqdjango-script contains(QDJANGO_LIBRARY_TYPE,staticlib) { DEFINES += QDJANGO_STATIC } else { @@ -22,7 +21,6 @@ contains(QDJANGO_LIBRARY_TYPE,staticlib) { win32 { QDJANGO_DB_LIBS = -lqdjango-db0 QDJANGO_HTTP_LIBS = -lqdjango-http0 - QDJANGO_SCRIPT_LIBS = -lqdjango-script0 } DEFINES += QDJANGO_SHARED } diff --git a/src/script/QDjangoScript.cpp b/src/script/QDjangoScript.cpp deleted file mode 100644 index be6b02e..0000000 --- a/src/script/QDjangoScript.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (C) 2010-2015 Jeremy Lainé - * Contact: https://github.com/jlaine/qdjango - * - * This file is part of the QDjango Library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - */ - -#include -#include -#include -#include - -#include "QDjangoScript.h" -#include "QDjangoWhere.h" - -QDjangoWhere QDjangoWhereFromScriptValue(QScriptEngine *engine, const QScriptValue &obj) -{ - if (obj.prototype().equals(engine->defaultPrototype(qMetaTypeId()))) { - return engine->fromScriptValue(obj); - } - - QDjangoWhere where; - QScriptValueIterator it(obj); - while (it.hasNext()) { - it.next(); - QString key = it.name(); - QDjangoWhere::Operation op = QDjangoWhere::Equals; - if (key.endsWith(QLatin1String("__lt"))) { - key.chop(4); - op = QDjangoWhere::LessThan; - } - else if (key.endsWith(QLatin1String("__lte"))) { - key.chop(5); - op = QDjangoWhere::LessOrEquals; - } - else if (key.endsWith(QLatin1String("__gt"))) { - key.chop(4); - op = QDjangoWhere::GreaterThan; - } - else if (key.endsWith(QLatin1String("__gte"))) { - key.chop(5); - op = QDjangoWhere::GreaterOrEquals; - } - else if (key.endsWith(QLatin1String("__startswith"))) { - key.chop(12); - op = QDjangoWhere::StartsWith; - } - else if (key.endsWith(QLatin1String("__endswith"))) { - key.chop(10); - op = QDjangoWhere::EndsWith; - } - else if (key.endsWith(QLatin1String("__contains"))) { - key.chop(10); - op = QDjangoWhere::Contains; - } - else if (key.endsWith(QLatin1String("__in"))) { - key.chop(4); - op = QDjangoWhere::IsIn; - } - where = where && QDjangoWhere(key, op, it.value().toVariant()); - } - return where; -} - -static QScriptValue newWhere(QScriptContext *context, QScriptEngine *engine) -{ - QDjangoWhere where; - if (context->argumentCount() == 1 && context->argument(0).isObject()) { - where = QDjangoWhereFromScriptValue(engine, context->argument(0)); - } - return engine->toScriptValue(where); -} - -static QScriptValue whereAnd(QScriptContext *context, QScriptEngine *engine) -{ - QDjangoWhere q = engine->fromScriptValue(context->thisObject()); - QDjangoWhere other = QDjangoWhereFromScriptValue(engine, context->argument(0)); - return engine->toScriptValue(q && other); -} - -static QScriptValue whereOr(QScriptContext *context, QScriptEngine *engine) -{ - QDjangoWhere q = engine->fromScriptValue(context->thisObject()); - QDjangoWhere other = QDjangoWhereFromScriptValue(engine, context->argument(0)); - return engine->toScriptValue(q || other); -} - -static QScriptValue whereToString(QScriptContext *context, QScriptEngine *engine) -{ - QDjangoWhere q = engine->fromScriptValue(context->thisObject()); - return engine->toScriptValue(QLatin1String("Q(") + q.sql(QDjango::database()) + QLatin1String(")")); -} - -/** Makes the QDjangoWhere class available to the given QScriptEngine. - * - * \param engine - */ -void QDjangoScript::registerWhere(QScriptEngine *engine) -{ - QScriptValue whereProto = engine->newObject(); - whereProto.setProperty(QLatin1String("and"), engine->newFunction(whereAnd)); - whereProto.setProperty(QLatin1String("or"), engine->newFunction(whereOr)); - whereProto.setProperty(QLatin1String("toString"), engine->newFunction(whereToString)); - engine->setDefaultPrototype(qMetaTypeId(), whereProto); - - QScriptValue ctor = engine->newFunction(newWhere); - engine->globalObject().setProperty(QLatin1String("Q"), ctor, QScriptValue::ReadOnly); -} - diff --git a/src/script/QDjangoScript.h b/src/script/QDjangoScript.h deleted file mode 100644 index deaa32f..0000000 --- a/src/script/QDjangoScript.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2010-2015 Jeremy Lainé - * Contact: https://github.com/jlaine/qdjango - * - * This file is part of the QDjango Library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - */ - -#ifndef QDJANGO_SCRIPT_H -#define QDJANGO_SCRIPT_H - -#include -#include - -#include "QDjango.h" -#include "QDjangoQuerySet.h" -#include "QDjangoScript_p.h" - -Q_DECLARE_METATYPE(QDjangoWhere) - -/** \brief The QDjangoScript class provides static methods for making models - * scriptable. - * - * \ingroup Script - */ -class QDJANGO_SCRIPT_EXPORT QDjangoScript -{ -public: - template - static void registerModel(QScriptEngine *engine); - static void registerWhere(QScriptEngine *engine); -}; - -/** Makes a QDjangoModel class available to the given QScriptEngine. - * - * \param engine - */ -template -void QDjangoScript::registerModel(QScriptEngine *engine) -{ - QDjango::registerModel(); - - QScriptValue querysetProto = engine->newObject(); - querysetProto.setProperty("all", engine->newFunction(QDjangoQuerySet_all)); - querysetProto.setProperty("at", engine->newFunction(QDjangoQuerySet_at)); - querysetProto.setProperty("count", engine->newFunction(QDjangoQuerySet_count)); - querysetProto.setProperty("exclude", engine->newFunction(QDjangoQuerySet_exclude)); - querysetProto.setProperty("filter", engine->newFunction(QDjangoQuerySet_filter)); - querysetProto.setProperty("get", engine->newFunction(QDjangoQuerySet_get)); - querysetProto.setProperty("limit", engine->newFunction(QDjangoQuerySet_limit)); - querysetProto.setProperty("remove", engine->newFunction(QDjangoQuerySet_remove)); - querysetProto.setProperty("size", engine->newFunction(QDjangoQuerySet_size)); - querysetProto.setProperty("toString", engine->newFunction(QDjangoQuerySet_toString)); - engine->setDefaultPrototype(qMetaTypeId< QDjangoQuerySet >(), querysetProto); - - QDjangoQuerySet qs; - QScriptValue value = engine->newQMetaObject(&T::staticMetaObject, engine->newFunction(QDjangoModel_new)); - value.setProperty("objects", engine->toScriptValue(qs)); - engine->globalObject().setProperty(T::staticMetaObject.className(), value); -} - -#endif diff --git a/src/script/QDjangoScript_p.h b/src/script/QDjangoScript_p.h deleted file mode 100644 index 7bb067b..0000000 --- a/src/script/QDjangoScript_p.h +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) 2010-2015 Jeremy Lainé - * Contact: https://github.com/jlaine/qdjango - * - * This file is part of the QDjango Library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - */ - -#ifndef QDJANGO_SCRIPT_P_H -#define QDJANGO_SCRIPT_P_H - -#if defined(QDJANGO_SHARED) -# if defined(QDJANGO_SCRIPT_BUILD) -# define QDJANGO_SCRIPT_EXPORT Q_DECL_EXPORT -# else -# define QDJANGO_SCRIPT_EXPORT Q_DECL_IMPORT -# endif -#else -# define QDJANGO_SCRIPT_EXPORT -#endif - -#include "QDjangoWhere.h" -// -// W A R N I N G -// ------------- -// -// This file is not part of the QDjango API. -// - -QDJANGO_SCRIPT_EXPORT QDjangoWhere QDjangoWhereFromScriptValue(QScriptEngine *engine, const QScriptValue &obj); - -template -static QScriptValue QDjangoQuerySet_all(QScriptContext *context, QScriptEngine *engine) -{ - QDjangoQuerySet qs = engine->fromScriptValue< QDjangoQuerySet >(context->thisObject()); - return engine->toScriptValue(qs.all()); -} - -template -static QScriptValue QDjangoQuerySet_at(QScriptContext *context, QScriptEngine *engine) -{ - QDjangoQuerySet qs = engine->fromScriptValue< QDjangoQuerySet >(context->thisObject()); - //QDjangoQuerySet qs = context->thisObject().toVariant().value< QDjangoQuerySet >(); - int index = context->argument(0).toInteger(); - return engine->newQObject(qs.at(index), QScriptEngine::ScriptOwnership); -} - -template -static QScriptValue QDjangoQuerySet_count(QScriptContext *context, QScriptEngine *engine) -{ - QDjangoQuerySet qs = engine->fromScriptValue< QDjangoQuerySet >(context->thisObject()); - return QScriptValue(engine, qs.count()); -} - -template -static QScriptValue QDjangoQuerySet_exclude(QScriptContext *context, QScriptEngine *engine) -{ - QDjangoQuerySet qs = engine->fromScriptValue< QDjangoQuerySet >(context->thisObject()); - QDjangoWhere where = QDjangoWhereFromScriptValue(engine, context->argument(0)); - return engine->toScriptValue(qs.exclude(where)); -} - -template -static QScriptValue QDjangoQuerySet_filter(QScriptContext *context, QScriptEngine *engine) -{ - QDjangoQuerySet qs = engine->fromScriptValue< QDjangoQuerySet >(context->thisObject()); - QDjangoWhere where = QDjangoWhereFromScriptValue(engine, context->argument(0)); - return engine->toScriptValue(qs.filter(where)); -} - -template -static QScriptValue QDjangoQuerySet_get(QScriptContext *context, QScriptEngine *engine) -{ - QDjangoQuerySet qs = engine->fromScriptValue< QDjangoQuerySet >(context->thisObject()); - QDjangoWhere where = QDjangoWhereFromScriptValue(engine, context->argument(0)); - return engine->newQObject(qs.get(where), QScriptEngine::ScriptOwnership); -} - -template -static QScriptValue QDjangoQuerySet_limit(QScriptContext *context, QScriptEngine *engine) -{ - QDjangoQuerySet qs = engine->fromScriptValue< QDjangoQuerySet >(context->thisObject()); - const int pos = context->argument(0).toInteger(); - const int limit = (context->argumentCount() > 1) ? context->argument(1).toInteger() : 1; - return engine->toScriptValue(qs.limit(pos, limit)); -} - -template -static QScriptValue QDjangoQuerySet_remove(QScriptContext *context, QScriptEngine *engine) -{ - QDjangoQuerySet qs = engine->fromScriptValue< QDjangoQuerySet >(context->thisObject()); - return QScriptValue(engine, qs.remove()); -} - -template -static QScriptValue QDjangoQuerySet_size(QScriptContext *context, QScriptEngine *engine) -{ - QDjangoQuerySet qs = engine->fromScriptValue< QDjangoQuerySet >(context->thisObject()); - return QScriptValue(engine, qs.size()); -} - -template -static QScriptValue QDjangoQuerySet_toString(QScriptContext *context, QScriptEngine *engine) -{ - QDjangoQuerySet qs = engine->fromScriptValue< QDjangoQuerySet >(context->thisObject()); - return QScriptValue(engine, QString("QuerySet<%1>(%2)").arg(T::staticMetaObject.className(), qs.where().sql(QDjango::database()))); -} - -template -static QScriptValue QDjangoModel_new(QScriptContext *context, QScriptEngine *engine) -{ - Q_UNUSED(context); - return engine->newQObject(new T, QScriptEngine::ScriptOwnership); -} - -#endif diff --git a/src/script/script.pro b/src/script/script.pro deleted file mode 100644 index bba06c7..0000000 --- a/src/script/script.pro +++ /dev/null @@ -1,21 +0,0 @@ -include(../../qdjango.pri) - -QT -= gui -QT += script sql - -DEFINES += QDJANGO_SCRIPT_BUILD - -TARGET = qdjango-script -win32 { - DESTDIR = $$OUT_PWD -} - -INCLUDEPATH += ../db -LIBS += -L../db $$QDJANGO_DB_LIBS -HEADERS += QDjangoScript.h QDjangoScript_p.h -SOURCES += QDjangoScript.cpp - -# Installation -include(../src.pri) -headers.path = $$PREFIX/include/qdjango/script -QMAKE_PKGCONFIG_INCDIR = $$headers.path diff --git a/src/src.pro b/src/src.pro index 7e1cc35..48610f7 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,5 +1,5 @@ TEMPLATE = subdirs -SUBDIRS = db http script +SUBDIRS = db http CONFIG += ordered diff --git a/tests/script/qdjangoscript/qdjangoscript.pro b/tests/script/qdjangoscript/qdjangoscript.pro deleted file mode 100644 index e10a108..0000000 --- a/tests/script/qdjangoscript/qdjangoscript.pro +++ /dev/null @@ -1,10 +0,0 @@ -include(../../db/db.pri) - -QT += script - -TARGET = tst_qdjangoscript - -HEADERS += ../../db/auth-models.h -SOURCES += ../../db/auth-models.cpp tst_qdjangoscript.cpp - -LIBS += -L../../../src/script $$QDJANGO_SCRIPT_LIBS diff --git a/tests/script/qdjangoscript/tst_qdjangoscript.cpp b/tests/script/qdjangoscript/tst_qdjangoscript.cpp deleted file mode 100644 index 357b64e..0000000 --- a/tests/script/qdjangoscript/tst_qdjangoscript.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (C) 2010-2015 Jeremy Lainé - * Contact: https://github.com/jlaine/qdjango - * - * This file is part of the QDjango Library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - */ - -#include "QDjangoScript.h" - -#include "auth-models.h" -#include "util.h" - -Q_DECLARE_METATYPE(QDjangoQuerySet) - -/** Test QDjango scripting. - */ -class tst_QDjangoScript : public QObject -{ - Q_OBJECT - -private slots: - void initTestCase(); - void testWhereConstructor(); - void testWhereOperators(); - void testWhereToString(); - void testModel(); - void cleanupTestCase(); - -private: - QDjangoMetaModel metaModel; - QScriptEngine *engine; -}; - -void tst_QDjangoScript::cleanupTestCase() -{ - metaModel.dropTable(); - - delete engine; -} - -void tst_QDjangoScript::initTestCase() -{ - initialiseDatabase(); - - metaModel = QDjango::registerModel(); - QCOMPARE(metaModel.createTable(), true); - - engine = new QScriptEngine(this); - QDjangoScript::registerWhere(engine); - QDjangoScript::registerModel(engine); -} - -void tst_QDjangoScript::testWhereConstructor() -{ - QScriptValue result; - QDjangoWhere where; - - // equals - result = engine->evaluate("Q({'username': 'foobar'})"); - where = engine->fromScriptValue(result); - CHECKWHERE(where, QLatin1String("username = ?"), QVariantList() << "foobar"); - - // less than - result = engine->evaluate("Q({'username__lt': 'foobar'})"); - where = engine->fromScriptValue(result); - CHECKWHERE(where, QLatin1String("username < ?"), QVariantList() << "foobar"); - - // less than or equal to - result = engine->evaluate("Q({'username__lte': 'foobar'})"); - where = engine->fromScriptValue(result); - CHECKWHERE(where, QLatin1String("username <= ?"), QVariantList() << "foobar"); - - // greater than - result = engine->evaluate("Q({'username__gt': 'foobar'})"); - where = engine->fromScriptValue(result); - CHECKWHERE(where, QLatin1String("username > ?"), QVariantList() << "foobar"); - - // greater than or equal to - result = engine->evaluate("Q({'username__gte': 'foobar'})"); - where = engine->fromScriptValue(result); - CHECKWHERE(where, QLatin1String("username >= ?"), QVariantList() << "foobar"); - - QDjangoDatabase::DatabaseType databaseType = QDjangoDatabase::databaseType(QDjango::database()); - if (databaseType == QDjangoDatabase::MySqlServer) { - // starts with - result = engine->evaluate("Q({'username__startswith': 'foobar'})"); - where = engine->fromScriptValue(result); - CHECKWHERE(where, QLatin1String("username LIKE BINARY ?"), QVariantList() << "foobar%"); - - // ends with - result = engine->evaluate("Q({'username__endswith': 'foobar'})"); - where = engine->fromScriptValue(result); - CHECKWHERE(where, QLatin1String("username LIKE BINARY ?"), QVariantList() << "%foobar"); - - // contains - result = engine->evaluate("Q({'username__contains': 'foobar'})"); - where = engine->fromScriptValue(result); - CHECKWHERE(where, QLatin1String("username LIKE BINARY ?"), QVariantList() << "%foobar%"); - } else { - // starts with - result = engine->evaluate("Q({'username__startswith': 'foobar'})"); - where = engine->fromScriptValue(result); - CHECKWHERE(where, QLatin1String("username LIKE ?"), QVariantList() << "foobar%"); - - // ends with - result = engine->evaluate("Q({'username__endswith': 'foobar'})"); - where = engine->fromScriptValue(result); - CHECKWHERE(where, QLatin1String("username LIKE ?"), QVariantList() << "%foobar"); - - // contains - result = engine->evaluate("Q({'username__contains': 'foobar'})"); - where = engine->fromScriptValue(result); - CHECKWHERE(where, QLatin1String("username LIKE ?"), QVariantList() << "%foobar%"); - } - - // in - result = engine->evaluate("Q({'username__in': ['foobar', 'wiz']})"); - where = engine->fromScriptValue(result); - CHECKWHERE(where, QLatin1String("username IN (?, ?)"), QVariantList() << "foobar" << "wiz"); - - // double constructor - result = engine->evaluate("Q(Q({'username': 'foobar'}))"); - where = engine->fromScriptValue(result); - CHECKWHERE(where, QLatin1String("username = ?"), QVariantList() << "foobar"); -} - -void tst_QDjangoScript::testWhereOperators() -{ - QScriptValue result; - QDjangoWhere where; - - // AND operator - result = engine->evaluate("Q({'username': 'foobar'}).and(Q({'password': 'foopass'}))"); - where = engine->fromScriptValue(result); - CHECKWHERE(where, QLatin1String("username = ? AND password = ?"), QVariantList() << "foobar" << "foopass"); - - // OR operator - result = engine->evaluate("Q({'username': 'foobar'}).or(Q({'password': 'foopass'}))"); - where = engine->fromScriptValue(result); - CHECKWHERE(where, QLatin1String("username = ? OR password = ?"), QVariantList() << "foobar" << "foopass"); -} - -void tst_QDjangoScript::testWhereToString() -{ - QScriptValue result = engine->evaluate("Q({'username': 'foobar'}).toString()"); - QCOMPARE(result.toString(), QLatin1String("Q(username = ?)")); -} - -void tst_QDjangoScript::testModel() -{ - // create model instance - QScriptValue result = engine->evaluate("user = User();"); - User *user = qobject_cast(result.toQObject()); - QVERIFY(user != 0); - - // set properties - engine->evaluate("user.username = 'foobar';"); - QCOMPARE(user->username(), QLatin1String("foobar")); -} - -QTEST_MAIN(tst_QDjangoScript) -#include "tst_qdjangoscript.moc" diff --git a/tests/script/script.pro b/tests/script/script.pro deleted file mode 100644 index 49dff63..0000000 --- a/tests/script/script.pro +++ /dev/null @@ -1,2 +0,0 @@ -TEMPLATE = subdirs -SUBDIRS = qdjangoscript diff --git a/tests/tests.pri b/tests/tests.pri index 6c67821..5e0c655 100644 --- a/tests/tests.pri +++ b/tests/tests.pri @@ -5,5 +5,5 @@ QT += testlib CONFIG -= app_bundle CONFIG += testcase -QMAKE_RPATHDIR += $$OUT_PWD/../../../src/db $$OUT_PWD/../../../src/http $$OUT_PWD/../../../src/script +QMAKE_RPATHDIR += $$OUT_PWD/../../../src/db $$OUT_PWD/../../../src/http INCLUDEPATH += $$PWD $$QDJANGO_INCLUDEPATH diff --git a/tests/tests.pro b/tests/tests.pro index 32a7463..05961c1 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS = db http script +SUBDIRS = db http diff --git a/tests/travis/install-build-depends b/tests/travis/install-build-depends index aeaaaf7..d722605 100755 --- a/tests/travis/install-build-depends +++ b/tests/travis/install-build-depends @@ -7,6 +7,6 @@ if [ "$QT_SELECT" = "qt4" ]; then else sudo add-apt-repository -y ppa:ubuntu-sdk-team/ppa sudo apt-get update - sudo apt-get install qtbase5-dev qtscript5-dev libqt5sql5-mysql libqt5sql5-odbc libqt5sql5-psql libqt5sql5-sqlite + sudo apt-get install qtbase5-dev libqt5sql5-mysql libqt5sql5-odbc libqt5sql5-psql libqt5sql5-sqlite fi sudo apt-get install lcov odbcinst libmyodbc odbc-postgresql