Permalink
Browse files

Lua UI + creation unit tests

  • Loading branch information...
feragon committed Jul 5, 2016
1 parent 43dc089 commit 01d7996a01bafe6eb33768156f559c1be55a47b8
View
@@ -1,8 +1,8 @@
#include "luainterface.h"
LuaInterface::LuaInterface() {
_L = luaL_newstate();
_L = LuaIntf::LuaState::newState();
luaL_openlibs(_L);
luaOpenQtBridge(_L);
lua_openlckernel(_L);
@@ -12,21 +12,14 @@ LuaInterface::LuaInterface() {
LuaInterface::~LuaInterface() {
_luaQObjects.clear();
lua_close(_L);
_L.close();
}
void LuaInterface::initLua() {
std::string out;
QString luaFile = QCoreApplication::applicationDirPath() + "/path.lua";
int s = luaL_dofile(_L, luaFile.toStdString().c_str());
if (s != 0) {
out.append(lua_tostring(_L, -1));
lua_pop(_L, 1);
}
std::cout << out << std::endl;
_L.doFile(luaFile.toStdString().c_str());
}
bool LuaInterface::luaConnect(
@@ -88,3 +81,10 @@ bool LuaInterface::qtConnect(QObject *sender, std::string signalName, QObject *r
return QMetaObject::connect(sender, signalId, receiver, slotId);
}
void LuaInterface::hideUI(bool hidden) {
LuaIntf::Lua::setGlobal(_L, "hideUI", hidden);
}
LuaIntf::LuaState LuaInterface::luaState() {
return _L;
}
View
@@ -45,7 +45,11 @@ class LuaInterface {
static std::shared_ptr<QWidget> loadUiFile(const char* fileName);
private:
lua_State* _L;
void hideUI(bool hidden);
LuaIntf::LuaState luaState();
private:
LuaIntf::LuaState _L;
std::vector<LuaQObject_SPtr> _luaQObjects;
};
View
@@ -6,4 +6,14 @@ file(
"package.path = package.path .. ';${CMAKE_CURRENT_LIST_DIR}/?.lua' \n"
"ui_path='${PROJECT_SOURCE_DIR}/lcUI/ui' \n"
"require 'ui.init'"
)
)
if(WITH_UNITTESTS)
file(
WRITE
"${PROJECT_BINARY_DIR}/unittest/path.lua"
"package.path = package.path .. ';${CMAKE_CURRENT_LIST_DIR}/?.lua' \n"
"ui_path='${PROJECT_SOURCE_DIR}/lcUI/ui' \n"
"require 'ui.init'"
)
endif()
@@ -112,7 +112,9 @@ end
function LWPolylineOperations:close()
if(not self.finished) then
active_widget():tempEntities():removeEntity(self.lwPolyline)
if(self.lwPolyline ~= nil) then
active_widget():tempEntities():removeEntity(self.lwPolyline)
end
self.finished = true
self:createLWPolyline()
View
@@ -17,29 +17,29 @@ function cli_get_text(getText)
cliCommand:returnText(getText)
end
local function command(command)
function command(command)
commands[command:toStdString()]()
end
local function coordinate(coordinate)
function coordinate(coordinate)
event.trigger("point", coordinate)
end
local function relativeCoordinate(relative)
function relativeCoordinate(relative)
local absolute = lastPoint:add(relative)
message("-> " .. "x=" .. absolute:x() .. " y=" .. absolute:y() .. " z=" .. absolute:z())
event.trigger("point", absolute)
end
local function number(number)
function number(number)
event.trigger("number", number)
end
local function setLastPoint(point)
lastPoint = point
end
local function text(text)
function text(text)
event.trigger("text", text:toStdString())
end
@@ -74,9 +74,11 @@ function create_main_window()
add_commandline()
add_toolbar()
if(hideUI ~= true) then
add_toolbar()
mainWindow:showMaximized()
mainWindow:showMaximized()
end
new_file()
end
View
@@ -1,26 +1,30 @@
local function remove_operation_group()
local tab = toolbar:tabByName("Quick Access")
local group = tab:groupByName("Current operation")
if(group ~= nil) then
tab:removeGroup(group)
if(hideUI ~= true) then
local tab = toolbar:tabByName("Quick Access")
local group = tab:groupByName("Current operation")
if(group ~= nil) then
tab:removeGroup(group)
end
end
active_widget():viewer():setOperationActive(false)
end
local function finish_operation()
function finish_operation()
if(op[active_widget().id] ~= nil) then
op[active_widget().id]:close()
end
end
local function create_cancel_button()
local tab = toolbar:tabByName("Quick Access")
local operationGroup = tab:addGroup("Current operation")
if(hideUI ~= true) then
local tab = toolbar:tabByName("Quick Access")
local operationGroup = tab:addGroup("Current operation")
local cancelButton = create_button("", ":/icons/quit.svg")
tab:addButton(operationGroup, cancelButton, 0, 0, 1, 1)
luaInterface:luaConnect(cancelButton, "pressed()", finish_operation)
local cancelButton = create_button("", ":/icons/quit.svg")
tab:addButton(operationGroup, cancelButton, 0, 0, 1, 1)
luaInterface:luaConnect(cancelButton, "pressed()", finish_operation)
end
end
local function new_operation()
@@ -92,20 +96,22 @@ function create_lw_polyline()
finish_operation()
create_cancel_button()
local tab = toolbar:tabByName("Quick Access")
local group = tab:groupByName("Current operation")
local lineButton = create_button("", ":/icons/linesnormal.png")
tab:addButton(group, lineButton, 0, 1, 1, 1)
luaInterface:luaConnect(lineButton, "pressed()", function()
op[active_widget().id]:createLine()
end)
local arcButton = create_button("", ":/icons/arc.svg")
tab:addButton(group, arcButton, 1, 1, 1, 1)
luaInterface:luaConnect(arcButton, "pressed()", function()
op[active_widget().id]:createArc()
end)
if(hideUI ~= true) then
local tab = toolbar:tabByName("Quick Access")
local group = tab:groupByName("Current operation")
local lineButton = create_button("", ":/icons/linesnormal.png")
tab:addButton(group, lineButton, 0, 1, 1, 1)
luaInterface:luaConnect(lineButton, "pressed()", function()
op[active_widget().id]:createLine()
end)
local arcButton = create_button("", ":/icons/arc.svg")
tab:addButton(group, arcButton, 1, 1, 1, 1)
luaInterface:luaConnect(arcButton, "pressed()", function()
op[active_widget().id]:createArc()
end)
end
op[active_widget().id] = LWPolylineOperations(active_widget().id)
end
View
@@ -50,11 +50,15 @@ if(WITH_QTUI)
set(src
${src}
ui/testtoolbar.cpp)
ui/testtoolbar.cpp
ui/testluaui.cpp)
include_directories("${CMAKE_SOURCE_DIR}/lcUI")
include_directories("${CMAKE_SOURCE_DIR}/lcviewerqt")
endif(WITH_QTUI)
include_directories("${CMAKE_SOURCE_DIR}/lckernel")
include_directories("${CMAKE_SOURCE_DIR}/lcadluascript")
include_directories("${CMAKE_SOURCE_DIR}/lcviewernoqt")
include_directories("${CMAKE_SOURCE_DIR}/lcDXFDWG")
add_executable(lcunittest ${src} ${hdrs})
target_link_libraries(lcunittest lckernel lcviewernoqt gtest ${EXTRA_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${LOG4CXX_LIBRARIES})
Oops, something went wrong.

0 comments on commit 01d7996

Please sign in to comment.