Commit 985db507 authored by LE BRETON Come's avatar LE BRETON Come

Adds test framework, plus abstraction and plugins for widgets. Not a

final version.
parent 85c198c9
......@@ -72,6 +72,13 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS "ON")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
## ###################################################################
## Test setup
## ###################################################################
include(CTest)
enable_testing()
## ###################################################################
## Dependencies - cmake
## ###################################################################
......@@ -82,11 +89,13 @@ include(GenerateExportHeader)
## Dependencies - external
## #################################################################
find_package(Qt5 REQUIRED COMPONENTS Core WebSockets Widgets Xml)
find_package(Qt5 REQUIRED COMPONENTS Core WebSockets Widgets Xml Test)
find_package(dtkCore REQUIRED)
find_package(dtkFonts REQUIRED)
find_package(dtkLog REQUIRED)
include_directories(${dtkCore_INCLUDE_DIRS})
include_directories(${dtkFonts_INCLUDE_DIRS})
include_directories(${dtkLog_INCLUDE_DIRS})
......@@ -100,12 +109,17 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories(${CMAKE_BINARY_DIR})
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${CMAKE_SOURCE_DIR}/src/dtkWidgets)
include_directories(${CMAKE_SOURCE_DIR}/tst)
include_directories(${CMAKE_SOURCE_DIR}/tst/dtkWidgets)
include_directories(${CMAKE_SOURCE_DIR}/plugins)
## ###################################################################
## Input
## ###################################################################
add_subdirectory(src)
add_subdirectory(tst)
add_subdirectory(plugins)
add_subdirectory(exp)
## ###################################################################
......
## ###################################################################
## Dependencies - internal
## #################### ################################################
include_directories(dtkWidgetsSpinBox)
## #################################################################
## Inputs
## #################################################################
add_subdirectory(dtkWidgetsSpinBox)
## Version: $Id$
##
######################################################################
##
### Commentary:
##
######################################################################
##
### Change Log:
##
######################################################################
##
### Code:
## ###################################################################
## Build rules
## ###################################################################
project(dtkWidgetsSpinBox)
add_definitions(-DQT_PLUGIN)
add_library(${PROJECT_NAME} SHARED
dtkWidgetsSpinBoxPlugin.h
dtkWidgetsSpinBoxPlugin.cpp
dtkWidgetsSpinBox.h
dtkWidgetsSpinBox.cpp)
## ###################################################################
## Link rules
## ###################################################################
target_link_libraries(${PROJECT_NAME} Qt5::Core)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} dtkCore)
target_link_libraries(${PROJECT_NAME} dtkLog)
target_link_libraries(${PROJECT_NAME} dtkWidgets)
## #################################################################
## Export header file
## #################################################################
generate_export_header(${PROJECT_NAME}
EXPORT_FILE_NAME "${PROJECT_NAME}Export.h")
add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different "${${PROJECT_NAME}_BINARY_DIR}/${PROJECT_NAME}Export.h" "${CMAKE_BINARY_DIR}"
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different "${${PROJECT_NAME}_BINARY_DIR}/${PROJECT_NAME}Export.h" "${CMAKE_BINARY_DIR}/${PROJECT_NAME}Export")
set(${PROJECT_NAME}_HEADERS
${${PROJECT_NAME}_HEADERS}
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}Export"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}Export.h")
## #################################################################
## Install rules
## #################################################################
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION plugins/${DTK_CURRENT_LAYER}
LIBRARY DESTINATION plugins/${DTK_CURRENT_LAYER}
ARCHIVE DESTINATION plugins/${DTK_CURRENT_LAYER})
######################################################################
### CMakeLists.txt ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsSpinBox.h"
#include <dtkLog>
#include <dtkCoreParameter>
class dtkWidgetsSpinBoxPrivate
{
public:
QMetaObject::Connection connection;
dtkCoreParameter<double> *parameter = nullptr;
public:
QDoubleSpinBox *spin_box = nullptr;
public:
void connect(void);
};
void dtkWidgetsSpinBoxPrivate::connect(void)
{
QObject::connect(parameter, &dtk::d_real::valueChanged, [=] (QVariant v) {
double value = v.value<dtk::d_real>().value();
spin_box->setValue(value);
});
QObject::connect(spin_box, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=] (double v) {
parameter->setValue(v);
});
}
// ///////////////////////////////////////////////////////////////////
dtkWidgetsSpinBox::dtkWidgetsSpinBox(QWidget* parent) : dtkWidgetsParameterDouble(parent), d(new dtkWidgetsSpinBoxPrivate)
{
// d->connection = connect(&dtk::widgets::factory(), &dtkCorePluginWidgetManager::added, [=] (const QVariant& v, QWidget *w) {
// if (w != this) {
// dtkTrace() << Q_FUNC_INFO << "Mismatch widget";
// return;
// }
// dtkBrepVolumeMesher *m = v.value<dtkBrepVolumeMesher *>();
// if (!m) {
// dtkTrace() << Q_FUNC_INFO << "Wrong concept";
// return;
// }
// d->mesher = dynamic_cast<dtkWidgetsSpinBox *>(m);
// if (!d->mesher) {
// dtkTrace() << Q_FUNC_INFO << "Wrong implementation";
// return;
// }
d->connect();
// });
}
dtkWidgetsSpinBox::~dtkWidgetsSpinBox(void)
{
// QObject::disconnect(d->connection);
delete d;
}
//
// dtkWidgetsSpinBoxWidget.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <QtWidgets>
#include <dtkWidgets/dtkWidgetsParameter>
class dtkWidgetsSpinBox : public dtkWidgetsParameterDouble
{
Q_OBJECT
public:
dtkWidgetsSpinBox(QWidget* parent = 0);
virtual ~dtkWidgetsSpinBox(void);
/* public: */
/* virtual void connect(dtkCoreParameter<double> *parameter); */
private:
class dtkWidgetsSpinBoxPrivate *d;
};
// ///////////////////////////////////////////////////////////////////
inline dtkWidgetsParameterDouble *dtkWidgetsSpinBoxCreator(void)
{
qDebug() << Q_FUNC_INFO;
return new dtkWidgetsSpinBox();
}
//
// dtkWidgetsSpinBox.h ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsSpinBoxPlugin.h"
#include "dtkWidgetsSpinBox.h"
#include <dtkCoreWidgets/dtkCoreWidgets>
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsSpinBoxPlugin
// ///////////////////////////////////////////////////////////////////
void dtkWidgetsSpinBoxPlugin::initialize(void)
{
qDebug() << Q_FUNC_INFO;
dtk::widgets::parameterDouble::pluginFactory().record("dtkWidgetsSpinBoxPlugin", dtkWidgetsSpinBoxCreator);
}
void dtkWidgetsSpinBoxPlugin::uninitialize(void)
{
}
// ///////////////////////////////////////////////////////////////////
// Plugin meta data
// ///////////////////////////////////////////////////////////////////
DTK_DEFINE_PLUGIN(dtkWidgetsSpinBox)
//
// dtkWidgetsSpinBoxPlugin.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <QtCore>
#include <dtkWidgets/dtkWidgetsParameter>
class dtkWidgetsSpinBoxPlugin : public dtkWidgetsParameterDoublePlugin
{
Q_OBJECT
Q_INTERFACES(dtkWidgetsParameterDoublePlugin);
Q_PLUGIN_METADATA(IID "fr.inria.dtkWidgetsSpinBoxPlugin" FILE "dtkWidgetsSpinBoxPlugin.json")
public:
dtkWidgetsSpinBoxPlugin(void) {}
~dtkWidgetsSpinBoxPlugin(void) {}
public:
void initialize(void);
void uninitialize(void);
};
//
// dtkWidgetsSpinBoxPlugin.h ends here
{
"name" : "dtkWidgetsSpinBoxPlugin",
"concept" : "dtkWidgetsParameterDouble",
"version" : "0.0.1",
"dependencies" : []
}
......@@ -21,6 +21,7 @@ project(dtkWidgets VERSION ${dtkWidgets_VERSION})
set(${PROJECT_NAME}_HEADERS
dtkApplication.h
dtkWidgets
dtkWidgets.h
dtkWidgetsColorButton
dtkWidgetsColorButton.h
dtkWidgetsController
......@@ -57,6 +58,8 @@ set(${PROJECT_NAME}_HEADERS
dtkWidgetsOverlayPaneSlider.h
dtkWidgetsOverlayRope
dtkWidgetsOverlayRope.h
dtkWidgetsParameter
dtkWidgetsParameter.h
dtkWidgetsSettings
dtkWidgetsSettings.h
dtkWidgetsStylesheetParser
......@@ -66,6 +69,7 @@ set(${PROJECT_NAME}_HEADERS
set(${PROJECT_NAME}_SOURCES
dtkApplication.cpp
dtkWidgets.cpp
dtkWidgetsColorButton.cpp
dtkWidgetsController.cpp
dtkWidgetsLayout.cpp
......@@ -83,6 +87,7 @@ set(${PROJECT_NAME}_SOURCES
dtkWidgetsOverlayPaneManager.cpp
dtkWidgetsOverlayPaneSlider.cpp
dtkWidgetsOverlayRope.cpp
dtkWidgetsParameter.cpp
dtkWidgetsSettings.cpp
dtkWidgetsStylesheetParser.cpp
dtkWidgetsWidget.cpp)
......@@ -100,6 +105,7 @@ target_link_libraries(${PROJECT_NAME} Qt5::WebSockets)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} Qt5::Xml)
target_link_libraries(${PROJECT_NAME} dtkCore)
target_link_libraries(${PROJECT_NAME} dtkFonts)
target_link_libraries(${PROJECT_NAME} dtkLog)
......@@ -125,6 +131,22 @@ set(${PROJECT_NAME}_HEADERS
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}Export"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}Export.h")
## ###################################################################
## Config file
## ###################################################################
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.h.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.h")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.h.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config")
set(${PROJECT_NAME}_HEADERS
${${PROJECT_NAME}_HEADERS}
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.h")
## ###################################################################
## Install rules - files
## ###################################################################
......
#include "dtkApplication.h"
#include "dtkWidgets.h"
#include "dtkWidgetsColorButton.h"
#include "dtkWidgetsController.h"
#include "dtkWidgetsHUD.h"
......
#include "dtkWidgets.h"
#include <dtkWidgetsConfig>
#include <QtCore>
// /////////////////////////////////////////////////////////////////
// Layer methods implementations
// /////////////////////////////////////////////////////////////////
namespace dtk {
namespace widgets {
DTK_DEFINE_LAYER_MANAGER;
void initialize(const QString& path)
{
QString realpath = path;
QStringList pathslist;
if (path.isEmpty()) {
// dtkWidgetsSettings geo_settings;
QSettings geo_settings;
geo_settings.beginGroup("widgets");
realpath = geo_settings.value("plugins").toString();
qDebug() << "realpath" << realpath;
geo_settings.endGroup();
if (realpath.isEmpty()) {
realpath = QDir(DTK_WIDGETS_INSTALL_PREFIX).filePath("plugins/");
dtkDebug() << "no plugin path configured for dtkWidgets, use default:" << realpath ;
}
pathslist = realpath.split(":");
qDebug() << "pathslist" << pathslist;
}
else {
pathslist = realpath.split(":");
}
foreach (const QString &v_path, pathslist) {
manager().initialize(v_path);
}
// ///////////////////////////////////////////////////////////////////
// Initializes default plugins
// ///////////////////////////////////////////////////////////////////
// dtkWidgets::blabla::pluginFactory().record("blabla", blablaCreator);
}
void setVerboseLoading(bool b)
{
manager().setVerboseLoading(b);
}
void setAutoLoading(bool auto_load)
{
manager().setAutoLoading(auto_load);
}
void uninitialize(void)
{
manager().uninitialize();
}
}
}
#pragma once
#include<dtkWidgetsExport.h>
#include <dtkCore>
// ///////////////////////////////////////////////////////////////////
// Layer methods declarations
// ///////////////////////////////////////////////////////////////////
namespace dtk {
namespace widgets {
DTKWIDGETS_EXPORT dtkCoreLayerManager& manager(void);
DTKWIDGETS_EXPORT void initialize(const QString& path = QString());
DTKWIDGETS_EXPORT void setVerboseLoading(bool b);
DTKWIDGETS_EXPORT void setAutoLoading(bool auto_loading);
DTKWIDGETS_EXPORT void uninitialize(void);
}
}
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <QString>
static const QString DTK_WIDGETS_INSTALL_PREFIX = "@CMAKE_INSTALL_PREFIX@";
//
// dtkWidgetsConfig.h.in ends here
#include "dtkWidgetsParameter.h"
\ No newline at end of file
#include "dtkWidgetsParameter.h"
#include "dtkWidgets.h"
namespace dtk {
namespace widgets {
DTK_DEFINE_CONCEPT(dtkWidgetsParameterDouble, parameterDouble, dtk::widgets);
}
}
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <dtkWidgetsExport>
#include <QtWidgets>
#include <dtkCore>
#include <dtkCore/dtkCoreParameter>
class DTKWIDGETS_EXPORT dtkWidgetsParameterInt : public QWidget
{
public:
virtual void connect(dtkCoreParameter<int> *) = 0;
};
class DTKWIDGETS_EXPORT dtkWidgetsParameterDouble : public QWidget
{
public:
dtkWidgetsParameterDouble(QWidget *parent) : QWidget(parent) {};
/* public: */
/* virtual void connect(dtkCoreParameter<double> *) = 0; */
};
DTK_DECLARE_OBJECT(dtkWidgetsParameterDouble*);
DTK_DECLARE_PLUGIN(dtkWidgetsParameterDouble, DTKWIDGETS_EXPORT);
DTK_DECLARE_PLUGIN_FACTORY(dtkWidgetsParameterDouble, DTKWIDGETS_EXPORT);
DTK_DECLARE_PLUGIN_MANAGER(dtkWidgetsParameterDouble, DTKWIDGETS_EXPORT);
// /////////////////////////////////////////////////////////////////
// Register to dtkDiscretegeometry layer
// /////////////////////////////////////////////////////////////////
namespace dtk {
namespace widgets {
DTK_DECLARE_CONCEPT(dtkWidgetsParameterDouble, DTKWIDGETS_EXPORT, parameterDouble);
}
}
//
// dtkWidgetsParameter.h ends here
include_directories(./)
add_subdirectory(dtkWidgets)
## Version: $Id$
##
######################################################################
##
### Commentary:
##
######################################################################
##
### Change Log:
##
######################################################################
##
### Code:
project(dtkWidgetsTests)
## ###################################################################
## Build tree setup
## ###################################################################
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
## ###################################################################
## Input
## ###################################################################
set(${PROJECT_NAME}_HEADERS
dtkWidgetsParameterTest.h
)
set(${PROJECT_NAME}_SOURCES
dtkWidgetsParameterTest.cpp
)
## ###################################################################
## Input - introspected
## ###################################################################
create_test_sourcelist(
${PROJECT_NAME}_SOURCES_TST
${PROJECT_NAME}.cpp
${${PROJECT_NAME}_SOURCES})
## ###################################################################
## Build rules
## ###################################################################
add_executable(${PROJECT_NAME}
${${PROJECT_NAME}_SOURCES_TST}
${${PROJECT_NAME}_SOURCES})
## ###################################################################
## Link rules
## ###################################################################
target_link_libraries(${PROJECT_NAME} dtkWidgets)
target_link_libraries(${PROJECT_NAME} dtkCore)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} Qt5::Test)
## ###################################################################
## Test rules
## ###################################################################
add_test(dtkWidgetsParameterTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME} dtkWidgetsParameterTest)
######################################################################
### CMakeLists.txt ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsParameterTest.h"
#include <dtkWidgetsTest>
#include <dtkCore/dtkCoreParameter>
#include <dtkWidgets/dtkWidgets>
#include <dtkWidgets/dtkWidgetsParameter>
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsParameterTestCasePrivate
{
};
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
dtkWidgetsParameterTestCase::dtkWidgetsParameterTestCase(void) : d(new dtkWidgetsParameterTestCasePrivate)
{
dtkLogger::instance().attachConsole();
dtkLogger::instance().setLevel("trace");
dtk::widgets::setVerboseLoading(true);
dtk::widgets::initialize("");
}
dtkWidgetsParameterTestCase::~dtkWidgetsParameterTestCase(void)
{
delete d;
}
void dtkWidgetsParameterTestCase::initTestCase(void)
{
}
void dtkWidgetsParameterTestCase::init(void)
{
}
void dtkWidgetsParameterTestCase::testBasic(void)
{
dtk::d_real real_parameter;
dtkWidgetsParameterDouble *spin_box = dtk::widgets::parameterDouble::pluginFactory().create("dtkWidgetsSpinBoxPlugin");
qDebug() << "spin_box" << spin_box;
// QWidget *spin_box = real_parameter->create("spin_box");
// QVERIFY(spin_box);
// QVariant var = concept->output();
}
void dtkWidgetsParameterTestCase::cleanup(void)
{