Commit 74086bb8 authored by Wouter's avatar Wouter

Port to Qt5/Grantlee 5

parent bcc89bcf
project(QJsonIntrospect)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
cmake_minimum_required(VERSION 3.0)
find_package(Qt4 4.6.0 COMPONENTS QtCore QtGui REQUIRED)
find_package(QJSON REQUIRED)
find_package(Grantlee REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_definitions(-DQT_USE_QSTRINGBUILDER)
find_package(Qt5Core REQUIRED)
find_package(Grantlee5 REQUIRED COMPONENTS Templates)
find_package(Qt5Gui)
find_package(Qt5Widgets)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
add_definitions(-DQT_USE_QSTRINGBUILDER)
include_directories(${QT_INCLUDES} ${QJSON_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${Grantlee_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(grantlee)
......
......@@ -5,7 +5,6 @@ set(QJsonIntrospect_CLI_SRCS
main.cpp
)
qt4_automoc(${libQJsonIntrospect_SRCS} ${QJsonIntrospect_CLI_SRCS} ${QJsonIntrospect_GUI_SRCS})
add_executable(qjsonintrospect-cli ${QJsonIntrospect_CLI_SRCS})
target_link_libraries(qjsonintrospect-cli ${QT_QTCORE_LIBRARY} ${QJSON_LIBRARIES} ${Grantlee_CORE_LIBRARIES} qjsonintrospect)
target_link_libraries(qjsonintrospect-cli
Qt5::Core Grantlee5::Templates qjsonintrospect)
......@@ -54,7 +54,7 @@ void IntrospectorCli::execute()
outDir = qApp->arguments().at(2);
QDir dirInfo(outDir);
if (!dirInfo.exists()) {
qFatal("Output directory not found: %s", qPrintable(file));
qFatal("Output directory not found: %s", qPrintable(outDir));
qApp->exit(1);
return;
}
......@@ -72,4 +72,4 @@ void IntrospectorCli::execute()
qApp->exit();
}
#include "cli/introspectorcli.moc"
#include "moc_introspectorcli.cpp"
# Find QJSON - JSON handling library for Qt
#
# This module defines
# QJSON_FOUND - whether the qsjon library was found
# QJSON_LIBRARIES - the qjson library
# QJSON_INCLUDE_DIR - the include path of the qjson library
#
if (QJSON_INCLUDE_DIR AND QJSON_LIBRARIES)
# Already in cache
set (QJSON_FOUND TRUE)
else (QJSON_INCLUDE_DIR AND QJSON_LIBRARIES)
if (NOT WIN32)
# use pkg-config to get the values of QJSON_INCLUDE_DIRS
# and QJSON_LIBRARY_DIRS to add as hints to the find commands.
include (FindPkgConfig)
pkg_check_modules (QJSON REQUIRED QJson>=0.5)
endif (NOT WIN32)
find_library (QJSON_LIBRARIES
NAMES
qjson
PATHS
${QJSON_LIBRARY_DIRS}
${LIB_INSTALL_DIR}
${KDE4_LIB_DIR}
)
find_path (QJSON_INCLUDE_DIR
NAMES
parser.h
PATH_SUFFIXES
qjson
PATHS
${QJSON_INCLUDE_DIRS}
${INCLUDE_INSTALL_DIR}
${KDE4_INCLUDE_DIR}
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(QJSON DEFAULT_MSG QJSON_LIBRARIES QJSON_INCLUDE_DIR)
endif (QJSON_INCLUDE_DIR AND QJSON_LIBRARIES)
include(${Grantlee_USE_FILE})
include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} ${Grantlee_INCLUDE_DIRS})
add_library(grantleecodegen MODULE
helpers.cpp
library.cpp
filters.cpp
evalto.cpp
switch.cpp
)
grantlee_adjust_plugin_name(grantleecodegen)
grantlee_add_plugin(grantleecodegen
helpers
library
filters
evalto
switch)
target_link_libraries(grantleecodegen
Grantlee5::Templates
)
install(TARGETS grantleecodegen
RUNTIME DESTINATION ${Grantlee_PLUGIN_DIR}/grantlee/${Grantlee_VERSION_MAJOR}.${Grantlee_VERSION_MINOR}
LIBRARY DESTINATION ${Grantlee_PLUGIN_DIR}/grantlee/${Grantlee_VERSION_MAJOR}.${Grantlee_VERSION_MINOR}
ARCHIVE DESTINATION ${Grantlee_LIBRARY_DIR}/grantlee/${Grantlee_VERSION_MAJOR}.${Grantlee_VERSION_MINOR}
RUNTIME DESTINATION /usr/lib/qt/plugins/grantlee/${Grantlee5_VERSION_MAJOR}.${Grantlee5_VERSION_MINOR}
LIBRARY DESTINATION /usr/lib/qt/plugins/grantlee/${Grantlee5_VERSION_MAJOR}.${Grantlee5_VERSION_MINOR}
ARCHIVE DESTINATION /usr/lib/qt/plugins/grantlee/${Grantlee5_VERSION_MAJOR}.${Grantlee5_VERSION_MINOR}
COMPONENT Devel
)
......@@ -63,7 +63,7 @@ void EvalToNode::setRenderList(NodeList renderList)
m_renderList = renderList;
}
void EvalToNode::render(OutputStream* stream, Context* c)
void EvalToNode::render(OutputStream* stream, Context* c) const
{
// Evaluate first part to temporary stream/string
QString evalResult;
......@@ -77,3 +77,5 @@ void EvalToNode::render(OutputStream* stream, Context* c)
m_renderList.render(stream, c);
c->pop();
}
#include "moc_evalto.cpp"
......@@ -44,7 +44,7 @@ public:
void setToEvalList(Grantlee::NodeList toEvalList );
void setRenderList(Grantlee::NodeList renderList);
void render( Grantlee::OutputStream *stream, Grantlee::Context *c );
virtual void render( Grantlee::OutputStream *stream, Grantlee::Context *c ) const;
private:
QString m_value;
......
......@@ -19,7 +19,7 @@
#include "library.h"
#include <QtCore/qplugin.h>
#include <QtCore/QtPlugin>
#include <grantlee/filter.h>
#include <grantlee/node.h>
......@@ -60,4 +60,4 @@ QJsonIntrospect::Codegen::Library::~Library()
{
}
Q_EXPORT_PLUGIN2("GrantleeCodegen", QJsonIntrospect::Codegen::Library);
#include "moc_library.cpp"
......@@ -28,7 +28,9 @@ namespace Codegen {
class Library : public QObject, public Grantlee::TagLibraryInterface
{
Q_OBJECT
Q_INTERFACES(Grantlee::TagLibraryInterface)
Q_PLUGIN_METADATA(IID "org.grantlee.TagLibraryInterface/1.0");
public:
Library(QObject *parent = 0);
......
......@@ -78,7 +78,7 @@ void SwitchNode::addCaseList(FilterExpression key, NodeList caseList)
m_casesList.append(QPair<Grantlee::FilterExpression, Grantlee::NodeList>(key, caseList));
}
void SwitchNode::render(OutputStream* stream, Context* c)
void SwitchNode::render(OutputStream* stream, Context* c) const
{
QVariant value = m_value.resolve(c);
......@@ -101,3 +101,5 @@ void SwitchNode::render(OutputStream* stream, Context* c)
renderList.render(stream, c);
}
#include "moc_switch.cpp"
......@@ -31,7 +31,7 @@ class SwitchNodeFactory : public Grantlee::AbstractNodeFactory
public:
virtual Grantlee::Node* getNode(const QString& tagContent, Grantlee::Parser* p) const;
};
......@@ -44,7 +44,7 @@ public:
void setDefaultList( Grantlee::NodeList defaultList );
void addCaseList(Grantlee::FilterExpression key, Grantlee::NodeList caseList);
void render( Grantlee::OutputStream *stream, Grantlee::Context *c );
virtual void render( Grantlee::OutputStream *stream, Grantlee::Context *c ) const;
private:
Grantlee::FilterExpression m_value;
......
......@@ -9,9 +9,8 @@ set(QJsonIntrospect_GUI_SRCS
main.cpp
)
qt4_wrap_ui(QJsonIntrospect_GUI_UIS introspectorgui.ui)
qt4_automoc(${QJsonIntrospect_GUI_SRCS})
qt5_wrap_ui(QJsonIntrospect_GUI_UIS introspectorgui.ui)
add_executable(qjsonintrospect-gui ${QJsonIntrospect_GUI_SRCS} ${QJsonIntrospect_GUI_UIS})
target_link_libraries(qjsonintrospect-gui ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QJSON_LIBRARIES} ${Grantlee_CORE_LIBRARIES} qjsonintrospect)
target_link_libraries(qjsonintrospect-gui
Qt5::Core Qt5::Widgets Grantlee5::Templates qjsonintrospect)
......@@ -25,10 +25,10 @@
#include <QtCore/QByteArray>
#include <QtCore/QFile>
#include <QtCore/QSettings>
#include <QtGui/QFileDialog>
#include <QtGui/QCompleter>
#include <QtGui/QFileSystemModel>
#include <QtGui/QMessageBox>
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QCompleter>
#include <QtWidgets/QFileSystemModel>
#include <QtWidgets/QMessageBox>
#include "gui/ui_introspectorgui.h"
#include "gui/typefilterproxymodel.h"
......@@ -141,7 +141,7 @@ void IntrospectorGui::load()
Q_FOREACH(QString id, sourceIds) {
ui->classSelect->addItem(id);
}
ui->classSelect->setCurrentIndex(0);
ui->classSelect->setEnabled(true);
ui->templateSelect->setEnabled(true);
......@@ -325,4 +325,4 @@ void IntrospectorGui::saveSettings() const
s.setValue("data/dataview/state", ui->dataView->header()->saveState());
}
#include "gui/introspectorgui.moc"
#include "moc_introspectorgui.cpp"
......@@ -20,8 +20,8 @@
#ifndef QJSONINTROSPECT_INTROSPECTGUI_H
#define QJSONINTROSPECT_INTROSPECTGUI_H
#include <QtGui/QMainWindow>
#include <QtGui/QItemSelection>
#include <QtWidgets/QMainWindow>
#include <QtCore/QItemSelection>
namespace Ui
{
......
#include <QtGui/QApplication>
#include <QtWidgets/QApplication>
#include "gui/introspectorgui.h"
......
......@@ -145,4 +145,4 @@ QModelIndex QVariantModel::index(int row, int column, const QModelIndex& parent)
}
}
#include "gui/qvariantmodel.moc"
#include "moc_qvariantmodel.cpp"
......@@ -35,4 +35,4 @@ bool TypeFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& so
sourceModel()->data(index1).toString().contains(filterRegExp()));
}
#include "gui/typefilterproxymodel.moc"
#include "moc_typefilterproxymodel.cpp"
......@@ -20,7 +20,7 @@
#ifndef QJSONINTROSPECT_TYPEFILTERPROXYMODEL_H
#define QJSONINTROSPECT_TYPEFILTERPROXYMODEL_H
#include <QtGui/QSortFilterProxyModel>
#include <QtCore/QSortFilterProxyModel>
namespace QJsonIntrospect {
......
......@@ -15,7 +15,6 @@ set(libQJsonIntrospect_SRCS
introspector.cpp
)
qt4_automoc(${libQJsonIntrospect_SRCS})
add_library(qjsonintrospect SHARED ${libQJsonIntrospect_SRCS})
target_link_libraries(qjsonintrospect ${QT_QTCORE_LIBRARY} ${QJSON_LIBRARIES} ${Grantlee_CORE_LIBRARIES} metacode)
target_link_libraries(qjsonintrospect
Qt5::Core Grantlee5::Templates metacode)
......@@ -51,4 +51,4 @@ void ArrayWriter::loadContext(Grantlee::Context* c)
c->insert("class", this->array());
}
#include "lib/arraywriter.moc"
#include "moc_arraywriter.cpp"
......@@ -47,4 +47,4 @@ ClassWriter::~ClassWriter()
}
#include "lib/classwriter.moc"
#include "moc_classwriter.cpp"
......@@ -240,4 +240,4 @@ CodeWriter::~CodeWriter()
}
}
#include "lib/codewriter.moc"
#include "moc_codewriter.cpp"
......@@ -283,4 +283,4 @@ Config::~Config()
{
}
#include "lib/config.moc"
#include "moc_config.cpp"
......@@ -5,6 +5,8 @@
#include <QtCore/QTimer>
#include <QtCore/QtDebug>
#include <QtCore/QMetaType>
#include <QtCore/QQueue>
#include <QtCore/QJsonDocument>
#include <qjson/parser.h>
#include <grantlee/metatype.h>
......@@ -44,27 +46,45 @@ Introspector::Introspector(QObject *parent)
// Metatype initialization
qRegisterMetaType<EnumVariable>();
Grantlee::registerMetaType<CodeWriter*>();
Grantlee::registerMetaType<ClassWriter*>();
Grantlee::registerMetaType<ArrayWriter*>();
Grantlee::registerMetaType<WrapperWriter*>();
Grantlee::registerMetaType<UnionWriter*>();
Grantlee::registerMetaType<ProjectWriter*>();
qRegisterMetaType<CodeWriter*>();
qRegisterMetaType<QList<CodeWriter*>>();
qRegisterMetaType<ClassWriter*>();
qRegisterMetaType<QList<ClassWriter*>>();
qRegisterMetaType<ArrayWriter*>();
qRegisterMetaType<QList<ArrayWriter*>>();
qRegisterMetaType<WrapperWriter*>();
qRegisterMetaType<QList<WrapperWriter*>>();
qRegisterMetaType<UnionWriter*>();
qRegisterMetaType<QList<UnionWriter*>>();
qRegisterMetaType<ProjectWriter*>();
qRegisterMetaType<QList<ProjectWriter*>>();
qRegisterMetaType<ClassMember*>();
qRegisterMetaType<QList<ClassMember*>>();
qRegisterMetaType<Type*>();
qRegisterMetaType<QList<Type*>>();
Grantlee::registerMetaType<ClassMember*>();
Grantlee::registerMetaType<Type*>();
Grantlee::registerMetaType<TypeReference>();
Grantlee::registerMetaType<Dependency>();
Grantlee::registerMetaType<Class*>();
Grantlee::registerMetaType<Field*>();
Grantlee::registerMetaType<Method*>();
Grantlee::registerMetaType<Property*>();
Grantlee::registerMetaType<QProperty*>();
Grantlee::registerMetaType<InnerType*>();
Grantlee::registerMetaType<Notification*>();
qRegisterMetaType<Class*>();
qRegisterMetaType<QList<Class*>>();
qRegisterMetaType<Field*>();
qRegisterMetaType<QList<Field*>>();
qRegisterMetaType<Method*>();
qRegisterMetaType<QList<Method*>>();
qRegisterMetaType<Property*>();
qRegisterMetaType<QList<Property*>>();
qRegisterMetaType<QProperty*>();
qRegisterMetaType<QList<QProperty*>>();
qRegisterMetaType<InnerType*>();
qRegisterMetaType<QList<InnerType*>>();
qRegisterMetaType<Notification*>();
qRegisterMetaType<QList<Notification*>>();
Grantlee::registerMetaType<Type::Inheritance>();
Grantlee::registerMetaType<EnumVariable>();
Grantlee::registerMetaType<Initializer*>();
qRegisterMetaType<Initializer*>();
qRegisterMetaType<QList<Initializer*>>();
// Load configuration
m_config = new Config(this);
......@@ -178,11 +198,12 @@ bool Introspector::load(const QString& file)
f.open(stdin, QIODevice::ReadOnly);
}
QJson::Parser p;
bool ok;
QVariantMap data = p.parse(&f, &ok).toMap();
if (!ok) {
qCritical("Parse error!");
QByteArray rawContent = f.readAll();
QJsonParseError error;
QJsonDocument doc = QJsonDocument::fromJson(rawContent, &error);
if (error.error != QJsonParseError::NoError) {
qCritical("Parse error: %s!", qPrintable(error.errorString()));
return false;
}
......@@ -190,6 +211,8 @@ bool Introspector::load(const QString& file)
m_codeItems.clear();
initTypeRegistry();
QVariantMap data = doc.toVariant().toMap();
m_projectId = data.contains("id") ? data.value("id").toString() : "";
m_projectName = data.contains("description") ? data.value("description").toString() : "";
m_projectVersion = data.contains("version") ? data.value("version").toString() : "";
......@@ -1153,4 +1176,4 @@ Introspector::~Introspector()
}
#include "lib/introspector.moc"
#include "moc_introspector.cpp"
......@@ -20,7 +20,5 @@ set(libMetacode_SRCS
uniontype.cpp
)
qt4_automoc(${libMetacode_SRCS})
add_library(metacode SHARED ${libMetacode_SRCS})
target_link_libraries(metacode ${QT_QTCORE_LIBRARY} ${Grantlee_CORE_LIBRARIES})
target_link_libraries(metacode Qt5::Core Grantlee5::Templates)
......@@ -57,4 +57,4 @@ Array::~Array()
{
}
#include "lib/metacode/array.moc"
#include "moc_array.cpp"
......@@ -19,6 +19,8 @@
#include "lib/metacode/class.h"
#include <QtCore/QQueue>
#include "lib/metacode/typeregistry.h"
#include "lib/metacode/classmember.h"
#include "lib/metacode/field.h"
......@@ -201,4 +203,4 @@ QJsonIntrospect::Class::~Class()
{
}
#include "lib/metacode/class.moc"
#include "moc_class.cpp"
......@@ -129,4 +129,4 @@ ClassMember::~ClassMember()
{
}
#include "lib/metacode/classmember.moc"
#include "moc_classmember.cpp"
......@@ -74,4 +74,4 @@ Constructor::~Constructor()
}
#include "lib/metacode/constructor.moc"
#include "moc_constructor.cpp"
......@@ -95,4 +95,4 @@ Field::~Field()
}
#include "lib/metacode/field.moc"
#include "moc_field.cpp"
......@@ -90,4 +90,4 @@ void Initializer::setType ( Type* type )
m_type = type;
}
#include "lib/metacode/initializer.moc"
#include "moc_initializer.cpp"
......@@ -56,4 +56,4 @@ InnerType::~InnerType()
}
#include "lib/metacode/innertype.moc"
#include "moc_innertype.cpp"
......@@ -126,4 +126,4 @@ Method::~Method()
}
#include "lib/metacode/method.moc"
#include "moc_method.cpp"
......@@ -37,4 +37,4 @@ Type::ProtectionLevel Notification::protectionLevel() const
}
#include "lib/metacode/notification.moc"
#include "moc_notification.cpp"
......@@ -172,4 +172,4 @@ Property::~Property()
}
#include "lib/metacode/property.moc"
#include "moc_property.cpp"
......@@ -97,4 +97,4 @@ bool QProperty::isQProperty() const
return true;
}
#include "lib/metacode/qproperty.moc"
#include "moc_qproperty.cpp"
......@@ -20,6 +20,7 @@
#include "lib/metacode/type.h"
#include <QtDebug>
#include <QtCore/QQueue>
#include "lib/metacode/typeregistry.h"
......@@ -346,4 +347,4 @@ Type::~Type()
}
#include "lib/metacode/type.moc"
#include "moc_type.cpp"
......@@ -212,7 +212,7 @@ QModelIndex TypeRegistry::index(int row, int column, const QModelIndex& parent)
}
if (!parent.isValid()) {
return createIndex(row, column, 0);
return createIndex(row, column, (void*)0);
}
Type *parentType = m_rows.at(parent.row());
......@@ -232,7 +232,7 @@ QModelIndex TypeRegistry::parent(const QModelIndex& child) const
// Find row of type
int row = m_rows.indexOf(parentType);
return createIndex(row, 0, 0);
return createIndex(row, 0, (void*)0);
}
int TypeRegistry::rowCount(const QModelIndex& parent) const
......@@ -458,7 +458,7 @@ QVariant TypeRegistry::wrapperData(WrapperType* wrapperData, const QModelIndex&
return QVariant();
}
}
return QVariant();
}
......@@ -475,4 +475,4 @@ TypeRegistry::~TypeRegistry()
{
}
#include "lib/metacode/typeregistry.moc"
#include "moc_typeregistry.cpp"
......@@ -65,4 +65,4 @@ UnionType::~UnionType()
{
}
#include "lib/metacode/uniontype.moc"
#include "moc_uniontype.cpp"
......@@ -121,4 +121,4 @@ WrapperType::~WrapperType()
{
}
#include "lib/metacode/wrappertype.moc"
#include "moc_wrappertype.cpp"
......@@ -64,4 +64,4 @@ ProjectWriter::~ProjectWriter()
{
}
#include "lib/projectwriter.moc"
#include "moc_projectwriter.cpp"
......@@ -53,4 +53,4 @@ UnionWriter::~UnionWriter()
{
}
#include "lib/unionwriter.moc"
#include "moc_unionwriter.cpp"
......@@ -53,4 +53,4 @@ WrapperWriter::~WrapperWriter()
{
}
#include "lib/wrapperwriter.moc"
#include "moc_wrapperwriter.cpp"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment