restore my error

This commit is contained in:
2020-08-25 22:38:34 +03:00
76 changed files with 10253 additions and 10981 deletions

View File

@@ -1,40 +1,40 @@
cmake_minimum_required(VERSION 3.0)
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
project(qad)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
if (NOT DEFINED ANDROID_PLATFORM)
find_package(OpenGL REQUIRED)
endif()
if (MINGW)
find_package(MinGW REQUIRED)
endif()
# Version
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/qad_version.h")
file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/qad_version.h")
endif()
#message(STATUS "Building QAD version ${QAD_VERSION} (${QAD_LIB_TYPE})")
file(GLOB CMAKES "cmake/*.cmake" "cmake/*.in")
if (LIB)
install(FILES ${CMAKES} DESTINATION ${CMAKE_ROOT}/Modules)
if (WIN32)
install(FILES ${QAD_VERSION_FILE} DESTINATION ${MINGW_INCLUDE}/qad)
else()
install(FILES ${QAD_VERSION_FILE} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/qad)
endif()
else()
install(FILES ${QAD_VERSION_FILE} DESTINATION include/qad)
endif()
add_subdirectory(libs)
if (UTILS)
add_subdirectory(utils)
endif()
copy_to_parent(qad_includes)
cmake_minimum_required(VERSION 3.0)
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
project(qad)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
if (NOT DEFINED ANDROID_PLATFORM)
find_package(OpenGL REQUIRED)
endif()
if (MINGW)
find_package(MinGW REQUIRED)
endif()
# Version
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/qad_version.h")
file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/qad_version.h")
endif()
#message(STATUS "Building QAD version ${QAD_VERSION} (${QAD_LIB_TYPE})")
file(GLOB CMAKES "cmake/*.cmake" "cmake/*.in")
if (LIB)
install(FILES ${CMAKES} DESTINATION ${CMAKE_ROOT}/Modules)
if (WIN32)
install(FILES ${QAD_VERSION_FILE} DESTINATION ${MINGW_INCLUDE}/qad)
else()
install(FILES ${QAD_VERSION_FILE} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/qad)
endif()
else()
install(FILES ${QAD_VERSION_FILE} DESTINATION include/qad)
endif()
add_subdirectory(libs)
if (UTILS)
add_subdirectory(utils)
endif()
copy_to_parent(qad_includes)

View File

@@ -1,811 +1,811 @@
#[[
find_qt([<Module1> <Module2> ...] [Qt4] [Qt5])
Find Qt4 or/and Qt5 packages
If Qt4/5 found, set
* Qt<4/5>_ROOT var to Qt root dir
* Qt<4/5>_BIN var to Qt binary dir
* Qt<4/5>_PLUGINS_DIR var to Qt plugins dir
* Qt<4/5>_LANG_DIR var to Qt translations dir
qt_sources(<src_out_var> [NO_DEFAULT] [DIR <dir>] [<regexp> ...])
Collect all sources, optionally in directory <dir> and
Additional filters <regexp>. By default filter files with regexps
"*.h", "*.hpp", "*.c", "*.cpp", "*.ui", "*.qrc", "*.rc", "*.ts" and "lang/*.ts".
Default filters disabled with option NO_DEFAULT
qt_wrap(<file0> <file1> ... [HDRS <hrd_var>] [CPPS <cpp_var>] [QMS <qm_var>])
Prepare sources for compile
Store headers to <hrd_var>, all wrapped Qt4 files to <cpp_var>_Qt4 and Qt5 files to <cpp_var>_Qt5
version are automatic detected after find_qt() call
qt_add_executable(<name> [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL] source1 [source2 ...])
Add executables for founded Qt versions, target names is <name><TARGET_SUFFIX_Qt?>
All needed Qt includes automatic added to corresponding targets
<source> cant be CPPS variable passed to qt_wrap() or some list or filename
qt_add_library(<name> [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL] source1 [source2 ...])
Add library for founded Qt versions, target names is <name><TARGET_SUFFIX_Qt?>
All needed Qt includes automatic added to corresponding targets
<source> cant be CPPS variable passed to qt_wrap() or some list or filename
qt_target_link_libraries(<name> ... <item> ...)
Link targets for founded Qt versions, target names is <name><TARGET_SUFFIX_Qt?>
All needed Qt libraries automatic added to corresponding targets
if QT_MULTILIB_LIST contains some linking library, to it name automatic
add <MULTILIB_SUFFIX_Qt?> or individual <MULTILIB_>libname<_SUFFIX_Qt?>
qt_target_compile_definitions(<name> ...)
Syntax similar to original "target_compile_definitions()"
Specify compile definitions to use when compiling a given <name>
qt_target_include_directories(<name> ...)
Syntax similar to original "target_include_directories()"
Add include directories to a target
qt_install(...)
Syntax similar to original "install()"
Install targets for founded Qt versions
if DESTINATION set to "QtBin" files will be installed
to corresponding Qt binary directory
if DESTINATION set to "QtLang" files will be installed
to corresponding Qt translation directory
if DESTINATION starts with "QtPlugins" files will be installed
to corresponding Qt plugins directory
Add LANG type for first argument - in this case you should
specify variable name, not variable value!
e.g. "qt_install(LANG my_QM DESTINATION QtLang)"
qt_install_lang(<name> DESTINATION <dir> [PATHS <path0> [<path1>] [...] ])
Search Qt translations for all <name> dependencies
in Qt<?>_LANG_DIR for <name>_LANG languages
and install them to <dir>. PATH are additional search paths.
You should use "set_lang()" macro before this action
qt_get_target(<name> <var> [Qt4 | Qt5])
Write real <name> Qt target name to <var>
If Qt4 or Qt5 specified, search for this version,
otherwise returns greatest version
qt_get_targets(<name> <var>)
Write all real <name> Qt target names to <var>
qt_generate_export_header(<name> ...)
Call generate_export_header on Qt multitarget
]]
cmake_policy(SET CMP0011 NEW) # don`t affect includer policies
cmake_policy(SET CMP0020 NEW) # Automatically link Qt executables to qtmain target on Windows
if (POLICY CMP0057)
cmake_policy(SET CMP0057 NEW) # Support if() IN_LIST
endif()
if (POLICY CMP0074)
cmake_policy(SET CMP0074 OLD) # ignore <PackageName>_ROOT variables
endif()
set(__qt_bug_modules "UiTools")
set(_QT_VERSIONS_ 4 5)
foreach(_v ${_QT_VERSIONS_})
if (NOT DEFINED TARGET_SUFFIX_Qt${_v})
set(TARGET_SUFFIX_Qt${_v} "${_v}")
set(MULTILIB_SUFFIX_Qt${_v} "${_v}")
endif()
set(MOC_INC_Qt${_v})
endforeach()
if (NOT DEFINED QT_MULTILIB_LIST)
set(QT_MULTILIB_LIST)
endif()
#set(TARGET_SUFFIX_Qt4 "")
macro(find_qt)
set(_QCOMP)
foreach(_v ${_QT_VERSIONS_})
set(_NEED${_v} 0)
set(LOCAL_FOUND${_v} 0)
set(MOC_INC_Qt${_v})
set(Qt${_v}_INCLUDES)
set(Qt${_v}_LIBRARIES)
set(Qt${_v}_ROOT)
set(Qt${_v}_BIN)
set(Qt${_v}_PLUGINS_DIR)
set(Qt${_v}_LANG_DIR)
endforeach()
set(_NEED_SOME 0)
set(_QUIET)
foreach(_i ${ARGN})
set(_FOUND_NEED 0)
foreach(_v ${_QT_VERSIONS_})
if ("x${_i}" STREQUAL "xQt${_v}")
set(_NEED${_v} 1)
set(_NEED_SOME 1)
set(_FOUND_NEED 1)
endif()
if ("x${_i}" STREQUAL "xQUIET")
set(_QUIET QUIET)
endif()
endforeach()
if (NOT _FOUND_NEED)
list(APPEND _QCOMP "${_i}")
endif()
endforeach()
if (NOT _NEED_SOME)
foreach(_v ${_QT_VERSIONS_})
set(_NEED${_v} 1)
endforeach()
endif()
list(REMOVE_DUPLICATES _QCOMP)
if (_NEED4)
find_package(Qt4 ${_QUIET})
if (Qt4_FOUND)
set(LOCAL_FOUND4 1)
get_filename_component(Qt4_BIN ${QT_QMAKE_EXECUTABLE} PATH)
set(Qt4_INCLUDES ${QT_INCLUDES})
foreach(m ${_QCOMP})
string(TOUPPER "${m}" _um)
#message("${QT_QT${_um}_FOUND}")
if (${QT_QT${_um}_FOUND})
list(APPEND Qt4_LIBRARIES ${QT_QT${_um}_LIBRARY})
endif()
endforeach()
set(Qt4_PLUGINS_DIR ${QT_PLUGINS_DIR})
set(Qt4_LANG_DIR ${Qt4_BIN}/../translations)
set(Qt4_ROOT "${Qt4_BIN}/../")
endif()
endif()
if (_NEED5)
#set(_MSG 1)
#if (Qt5_FOUND)
# set(_MSG 0)
#endif()
find_package(Qt5 COMPONENTS Core LinguistTools UiPlugin Widgets ${_QCOMP} ${_QUIET})
if (DEFINED ANDROID_PLATFORM)
set(CMAKE_SHARED_MODULE_SUFFIX_CXX ".so")
set(CMAKE_SHARED_LIBRARY_SUFFIX_CXX ".so")
set(CMAKE_SHARED_MODULE_SUFFIX_C ".so")
set(CMAKE_SHARED_LIBRARY_SUFFIX_C ".so")
endif()
if (Qt5_FOUND)
set(LOCAL_FOUND5 1)
set(_Qt5Modules)
foreach(m ${_QCOMP})
if (${Qt5${m}_FOUND})
set(__lib ${Qt5${m}_LIBRARIES})
if (DEFINED ANDROID_PLATFORM)
if (m IN_LIST __qt_bug_modules)
get_target_property(__lib Qt5::${m} LOCATION)
endif()
endif()
list(APPEND _Qt5Modules ${m})
list(APPEND Qt5_INCLUDES ${Qt5${m}_INCLUDE_DIRS})
list(APPEND Qt5_LIBRARIES ${__lib})
endif()
endforeach()
#get_property(_up_dir TARGET Qt5::UiPlugin PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
#message("${_up_dir}")
#if (NOT "x${_up_dir}" STREQUAL "x")
# list(APPEND Qt5_INCLUDES ${_up_dir})
#endif()
get_target_property(_Qt5_qmake Qt5::qmake LOCATION)
get_filename_component(Qt5_BIN ${_Qt5_qmake} PATH)
foreach(_p ${Qt5Gui_PLUGINS})
get_target_property(_l ${_p} LOCATION)
get_filename_component(_l ${_l} DIRECTORY)
string(FIND "${_l}" "/" _ind REVERSE)
string(SUBSTRING "${_l}" 0 ${_ind} _l)
set(Qt5_PLUGINS_DIR ${_l})
#message("Qt5: plugins dir: ${Qt5_PLUGINS_DIR}")
break()
endforeach()
string(FIND "${Qt5_BIN}" "/" _ind REVERSE)
string(SUBSTRING "${Qt5_BIN}" 0 ${_ind} Qt5_ROOT)
if ("x${Qt5_PLUGINS_DIR}" STREQUAL "x")
set(Qt5_PLUGINS_DIR "${Qt5_ROOT}/plugins")
endif()
if (APPLE)
list(APPEND MOC_INC_Qt5 "-F${Qt5_ROOT}/lib")
endif()
set(Qt5_LANG_DIR ${Qt5_BIN}/../translations)
if (NOT _QT5_MSG)
message(STATUS "Found Qt5: ${_Qt5_qmake} (version \"${Qt5_VERSION}\")")
set(_QT5_MSG 1 CACHE BOOL "msg_qt5" FORCE)
#message(STATUS "Found Qt5 modules: ${_Qt5Modules}")
endif()
endif()
endif()
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v})
foreach(_p ${Qt${_v}_INCLUDES})
list(APPEND MOC_INC_Qt${_v} "-I${_p}")
#message("${_p}")
endforeach()
endif()
#message("${MOC_INC_Qt${_v}}")
endforeach()
endmacro()
macro(qt_sources OUT)
set(${OUT})
set(_DIR "")
set(_IS_DIR 0)
set(_NO_DEFAULT 0)
set(_DEFAULT)
set(_REGEXP)
set(_REGEXP_WD)
foreach(_i ${ARGN})
if (_IS_DIR)
set(_DIR "${_i}")
set(_IS_DIR 0)
elseif ("x${_i}" STREQUAL "xDIR")
set(_IS_DIR 1)
elseif ("x${_i}" STREQUAL "xNO_DEFAULT")
set(_NO_DEFAULT 1)
else()
list(APPEND _REGEXP ${_i})
endif()
endforeach()
if (NOT "x${_DIR}" STREQUAL "x")
#file(TO_CMAKE_PATH "${_DIR}//" _DIR)
string(REPLACE "\\" "/" _DIR "${_DIR}/")
string(REPLACE "//" "/" _DIR "${_DIR}")
endif()
foreach(_i ${_REGEXP})
list(APPEND _REGEXP_WD "${_DIR}${_i}")
endforeach()
if (NOT _NO_DEFAULT)
set(_DEFAULT "${_DIR}*.h" "${_DIR}*.hpp" "${_DIR}*.c" "${_DIR}*.cpp" "${_DIR}*.ui" "${_DIR}*.qrc" "${_DIR}*.rc" "${_DIR}*.ts" "${_DIR}lang/*.ts")
endif()
#message("${_DEFAULT}, ${_REGEXP_WD}")
file(GLOB ${OUT} ${_DEFAULT} ${_REGEXP_WD})
endmacro()
macro(qt_wrap)
set(HDR_VAR)
set(CPP_VAR)
set(QM_VAR)
set(_HDR_ARG 0)
set(_CPP_ARG 0)
set(_QM_ARG 0)
set(WAS_HDR_ARG 0)
set(WAS_CPP_ARG 0)
set(WAS_QM_ARG 0)
set(FILE_LIST)
foreach(_i ${ARGN})
if (_HDR_ARG)
set(HDR_VAR ${_i})
set(WAS_HDR_ARG 1)
set(_HDR_ARG 0)
elseif (_CPP_ARG)
set(CPP_VAR ${_i})
set(WAS_CPP_ARG 1)
set(_CPP_ARG 0)
elseif (_QM_ARG)
set(QM_VAR ${_i})
set(WAS_QM_ARG 1)
set(_QM_ARG 0)
elseif ("x${_i}" STREQUAL "xHDRS")
set(_HDR_ARG 1)
elseif ("x${_i}" STREQUAL "xCPPS")
set(_CPP_ARG 1)
elseif ("x${_i}" STREQUAL "xQMS")
set(_QM_ARG 1)
else()
list(APPEND FILE_LIST "${_i}")
endif()
endforeach()
foreach(_v ${_QT_VERSIONS_})
set(CPP${_v}_VAR)
set(QM${_v}_VAR)
if (LOCAL_FOUND${_v})
if (WAS_CPP_ARG)
set(CPP${_v}_VAR ${CPP_VAR}_Qt${_v})
endif()
if (WAS_QM_ARG)
set(QM${_v}_VAR ${QM_VAR}_Qt${_v})
endif()
endif()
endforeach()
#message("found 4: ${LOCAL_FOUND4}, 5: ${LOCAL_FOUND5}")
#message("has HRDS: ${WAS_HDR_ARG}: ${HDR_VAR}")
#message("has CPPS4: ${WAS_CPP_ARG}: ${CPP4_VAR}")
#message("has CPPS5: ${WAS_CPP_ARG}: ${CPP5_VAR}")
#message("files: ${FILE_LIST}")
set(H_LIST)
set(CPP_LIST)
set(UI_LIST)
set(RES_LIST)
set(RC_LIST)
set(TS_LIST)
foreach(_i ${FILE_LIST})
get_filename_component(_EXT "${_i}" EXT)
#message("${_EXT}")
if (NOT ("x${_EXT}" STREQUAL "x"))
if (("x${_EXT}" STREQUAL "x.h") OR ("x${_EXT}" STREQUAL "x.hpp"))
list(APPEND H_LIST "${_i}")
#message("header")
endif()
if (("x${_EXT}" STREQUAL "x.c") OR ("x${_EXT}" STREQUAL "x.cpp") OR ("x${_EXT}" STREQUAL "x.cxx"))
list(APPEND CPP_LIST "${_i}")
#message("source")
endif()
if ("x${_EXT}" STREQUAL "x.ui")
list(APPEND UI_LIST "${_i}")
endif()
if ("x${_EXT}" STREQUAL "x.qrc")
list(APPEND RES_LIST "${_i}")
endif()
if ("x${_EXT}" STREQUAL "x.rc")
list(APPEND RC_LIST "${_i}")
endif()
if ("x${_EXT}" STREQUAL "x.ts")
list(APPEND TS_LIST "${_i}")
endif()
endif()
endforeach()
if (WAS_HDR_ARG)
set(${HDR_VAR})
list(APPEND ${HDR_VAR} ${H_LIST})
endif()
set(SRC_CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v} AND WAS_CPP_ARG)
set(CMAKE_CURRENT_BINARY_DIR ${SRC_CMAKE_CURRENT_BINARY_DIR}/qt${_v})
set(${CPP${_v}_VAR})
if (WAS_QM_ARG)
set(${QM${_v}_VAR})
endif()
set(MOCS${_v})
set(CUIS${_v})
set(CRES${_v})
if (${_v} EQUAL 4)
qt4_wrap_cpp(MOCS${_v} ${H_LIST} OPTIONS -nw ${MOC_INC_Qt4})
qt4_wrap_ui(CUIS${_v} ${UI_LIST})
qt4_add_resources(CRES${_v} ${RES_LIST})
if (WAS_QM_ARG)
set(${QM${_v}_VAR} "")
qt4_add_translation(${QM${_v}_VAR} ${TS_LIST})
endif()
elseif (${_v} EQUAL 5)
qt5_wrap_cpp(MOCS${_v} ${H_LIST} OPTIONS -nw ${MOC_INC_Qt5})
qt5_wrap_ui(CUIS${_v} ${UI_LIST})
qt5_add_resources(CRES${_v} ${RES_LIST})
if (WAS_QM_ARG)
set(${QM${_v}_VAR} "")
qt5_add_translation(${QM${_v}_VAR} ${TS_LIST})
endif()
else()
# Qt6 ...
endif()
#message("${${QM${_v}_VAR}}")
list(APPEND ${CPP${_v}_VAR} ${CPP_LIST})
list(APPEND ${CPP${_v}_VAR} ${RC_LIST})
list(APPEND ${CPP${_v}_VAR} ${MOCS${_v}})
list(APPEND ${CPP${_v}_VAR} ${CUIS${_v}})
list(APPEND ${CPP${_v}_VAR} ${CRES${_v}})
if (WAS_QM_ARG)
list(APPEND ${CPP${_v}_VAR} ${${QM${_v}_VAR}})
endif()
#message("${${QM${_v}_VAR}}")
endif()
endforeach()
set(CMAKE_CURRENT_BINARY_DIR ${SRC_CMAKE_CURRENT_BINARY_DIR})
endmacro()
macro(_qt_split_add_args _P _A)
set(${_P})
set(${_A})
foreach(_i ${ARGN})
if (NOT ("x${${_i}_Qt${_v}}" STREQUAL "x"))
list(APPEND ${_A} ${${_i}_Qt${_v}})
elseif (("x${_i}" STREQUAL "xWIN32") OR
("x${_i}" STREQUAL "xMACOSX_BUNDLE") OR
("x${_i}" STREQUAL "xSTATIC") OR
("x${_i}" STREQUAL "xSHARED") OR
("x${_i}" STREQUAL "xMODULE") OR
("x${_i}" STREQUAL "xEXCLUDE_FROM_ALL"))
list(APPEND ${_P} ${_i})
elseif ("x${${_i}}" STREQUAL "x")
list(APPEND ${_A} ${_i})
else()
list(APPEND ${_A} ${${_i}})
endif()
endforeach()
endmacro()
macro(__qt_set_defines _NAME _T)
target_compile_definitions(${_T} PRIVATE "__TARGET_NAME__=\"${_NAME}\"")
target_compile_definitions(${_T} PRIVATE "__TARGET_LABEL__=\"${${_NAME}_LABEL}\"")
target_compile_definitions(${_T} PRIVATE "__TARGET_COMPANY__=\"${${_NAME}_COMPANY}\"")
target_compile_definitions(${_T} PRIVATE "__TARGET_VERSION__=\"${${_NAME}_VERSION}\"")
endmacro()
macro(qt_add_executable _NAME)
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v})
_qt_split_add_args(_PREF _ARGS ${ARGN})
if(APPLE)
set(_PREV_CIND "${CMAKE_INSTALL_NAME_DIR}")
set(CMAKE_INSTALL_NAME_DIR "@rpath")
else()
if(NOT WIN32)
set(CMAKE_INSTALL_RPATH "\$ORIGIN;\$ORIGIN/lib")
endif()
endif()
set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}})
add_executable(${_TARGET} ${_PREF} ${_ARGS})
set(_${_NAME}_is_qt 1)
target_include_directories(${_TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/qt${_v} ${Qt${_v}_INCLUDES})
__qt_set_defines(${_NAME} ${_TARGET})
if(APPLE)
set(CMAKE_INSTALL_NAME_DIR "${_PREV_CIND}")
endif()
# # Apple crosscompiling rpath patch
# if (APPLE AND CMAKE_CROSSCOMPILING AND CMAKE_MACOSX_RPATH)
# foreach(_RP ${CMAKE_INSTALL_RPATH})
# add_custom_command(TARGET ${_TARGET} POST_BUILD
# COMMAND "${CMAKE_INSTALL_NAME_TOOL}"
# "-add_rpath" "${_RP}"
# "$<TARGET_FILE_DIR:${_TARGET}>/$<TARGET_FILE_NAME:${_TARGET}>"
# COMMENT "Add to ${_TARGET} rpath \"${_RP}\"")
# endforeach()
# endif()
#list(APPEND _ALL_TARGETS "${_TARGET}")
#set(_ALL_TARGETS ${_ALL_TARGETS} PARENT_SCOPE)
endif()
endforeach()
endmacro()
macro(qt_add_library _NAME)
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v})
_qt_split_add_args(_PREF _ARGS ${ARGN})
if(APPLE)
set(_PREV_CIND "${CMAKE_INSTALL_NAME_DIR}")
set(CMAKE_INSTALL_NAME_DIR "@rpath")
else()
if(NOT WIN32)
set(CMAKE_INSTALL_RPATH "\$ORIGIN;\$ORIGIN/lib")
endif()
endif()
set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}})
add_library(${_TARGET} ${_PREF} ${_ARGS})
set(_${_NAME}_is_qt 1)
target_include_directories(${_TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/qt${_v} ${Qt${_v}_INCLUDES})
__qt_set_defines(${_NAME} ${_TARGET})
#message("add lib: \"${_TARGET}\"")
if(APPLE)
set(CMAKE_INSTALL_NAME_DIR "${_PREV_CIND}")
endif()
# # Apple crosscompiling rpath patch
# if (APPLE AND CMAKE_CROSSCOMPILING AND CMAKE_MACOSX_RPATH)
# foreach(_RP ${CMAKE_INSTALL_RPATH})
# add_custom_command(TARGET ${_TARGET} POST_BUILD
# COMMAND "${CMAKE_INSTALL_NAME_TOOL}"
# "-add_rpath" "${_RP}"
# "$<TARGET_FILE_DIR:${_TARGET}>/$<TARGET_FILE_NAME:${_TARGET}>"
# COMMENT "Add to ${_TARGET} rpath \"${_RP}\"")
# endforeach()
# endif()
list(APPEND _ALL_TARGETS "${_TARGET}")
set(_ALL_TARGETS ${_ALL_TARGETS} PARENT_SCOPE)
endif()
endforeach()
endmacro()
macro(_qt_multitarget_suffix_ _OUT _IN _v)
string(REPLACE ":" "_" _in_str "${_IN}")
if (NOT "x${MULTILIB_${_in_str}_SUFFIX_Qt${_v}}" STREQUAL "x")
set(${_OUT} "${MULTILIB_${_in_str}_SUFFIX_Qt${_v}}")
else()
set(${_OUT} "${MULTILIB_SUFFIX_Qt${_v}}")
endif()
endmacro()
macro(qt_target_link_libraries _NAME)
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v})
set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}})
set(_ARGS)
foreach(_i ${ARGN})
set(_ind -1)
list(FIND QT_MULTILIB_LIST "${_i}" _ind)
if (_ind GREATER -1)
_qt_multitarget_suffix_(_TS ${_i} ${_v})
#message(STATUS "${_i} in MULTILIB_LIST, suffix = ${_TS}")
list(APPEND _ARGS ${_i}${_TS})
else()
list(APPEND _ARGS ${_i})
endif()
endforeach()
target_link_libraries(${_TARGET} ${Qt${_v}_LIBRARIES} ${_ARGS})
#message("link ${_TARGET}: ${Qt${_v}_LIBRARIES} ${_ARGS}")
endif()
endforeach()
endmacro()
macro(qt_target_compile_definitions _NAME)
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v})
set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}})
target_compile_definitions(${_TARGET} ${ARGN})
endif()
endforeach()
endmacro()
macro(qt_target_include_directories _NAME)
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v})
set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}})
target_include_directories(${_TARGET} ${ARGN})
endif()
endforeach()
endmacro()
macro(qt_install)
set(_prev_inst)
set(__add_args)
#message("command: ${ARGN}")
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v})
set(_INST_LIST)
set(_IS_TARGET 0)
set(_IS_FILES 0)
set(_IS_DEST 0)
set(_IS_LANG 0)
set(_INVALID 0)
foreach(_i ${ARGN})
if ("x${_i}" STREQUAL "xQtLang")
set(_IS_LANG 1)
endif()
endforeach()
foreach(_i ${ARGN})
if (_IS_TARGET)
set(_IS_TARGET 0)
set(__target ${_i})
if (_${_i}_is_qt)
set(__target ${_i}${TARGET_SUFFIX_Qt${_v}})
endif()
if (DEFINED ANDROID_PLATFORM)
get_target_property(_TT ${__target} TYPE)
if ("x${_TT}" STREQUAL "xEXECUTABLE")
list(APPEND __add_args EXCLUDE_FROM_ALL)
endif()
endif()
list(APPEND _INST_LIST ${__target})
elseif (_IS_FILES)
set(_IS_FILES 0)
if (_IS_LANG)
if (("x${${_i}_Qt${_v}}" STREQUAL "x") OR ("x${_i}" STREQUAL "xDESTINATION"))
set(_INVALID 1)
else()
list(APPEND _INST_LIST ${${_i}_Qt${_v}})
endif()
else()
list(APPEND _INST_LIST ${_i})
endif()
else()
if (_IS_DEST)
set(_IS_DEST 0)
if ("x${_i}" STREQUAL "xQtBin")
list(APPEND _INST_LIST "${Qt${_v}_BIN}")
elseif ("x${_i}" STREQUAL "xQtLang")
list(APPEND _INST_LIST "${Qt${_v}_LANG_DIR}")
else()
set(_ind -1)
string(FIND "${_i}" "QtPlugins" _ind)
if (_ind GREATER -1)
string(REPLACE "QtPlugins" "${Qt${_v}_PLUGINS_DIR}" _o "${_i}")
list(APPEND _INST_LIST "${_o}")
else()
string(REPLACE "\\" "/" _o "${_i}")
list(APPEND _INST_LIST ${_o})
endif()
endif()
else()
set(_ii ${_i})
if ("x${_i}" STREQUAL "xTARGETS")
set(_IS_TARGET 1)
elseif ("x${_i}" STREQUAL "xFILES")
set(_IS_FILES 1)
elseif ("x${_i}" STREQUAL "xDESTINATION")
set(_IS_DEST 1)
elseif ("x${_i}" STREQUAL "xLANG")
set(_IS_FILES 1)
set(_IS_LANG 1)
set(_ii "FILES")
endif()
list(APPEND _INST_LIST ${_ii})
endif()
endif()
endforeach()
if (NOT _INVALID)
if (NOT ("x${_prev_inst}" STREQUAL "x${_INST_LIST}"))
#message("install: ${_INST_LIST}")
install(${_INST_LIST} ${__add_args})
set(_prev_inst "${_INST_LIST}")
endif()
endif()
endif()
endforeach()
endmacro()
macro(qt_install_lang _NAME)
set(_prev_inst)
#message("command: ${ARGN}")
set(_PATHS)
set(_DEST)
if(CMAKE_CROSSCOMPILING)
list(APPEND _PATHS "${CMAKE_PREFIX_PATH}/lang")
endif()
set(_cur_arg)
set(__args "DESTINATION;PATHS")
foreach(_i ${ARGN})
if (_i IN_LIST __args)
set(_cur_arg "${_i}")
elseif("${_cur_arg}" STREQUAL "DESTINATION")
set(_DEST "${_i}")
elseif("${_cur_arg}" STREQUAL "PATHS")
list(APPEND _PATHS "${_i}")
endif()
endforeach()
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v})
set(_target)
if (_${_NAME}_is_qt)
set(_target ${_NAME}${TARGET_SUFFIX_Qt${_v}})
endif()
get_target_property(_LL ${_target} LINK_LIBRARIES)
foreach (_L ${_LL})
get_filename_component(_libname "${_L}" NAME_WE)
#message("depend on ${_libname}")
if ("${_libname}" MATCHES "Qt${_v}::.*")
string(SUBSTRING "${_libname}" 5 -1 _libname)
string(TOLOWER "${_libname}" _libname)
#message("qt lib \"${_libname}\"")
list(APPEND _qt_libs qt${_libname})
else()
if ("${_libname}" MATCHES "lib.*")
string(LENGTH ${_libname} _sl)
math(EXPR _sl ${_sl}-3)
string(SUBSTRING ${_libname} 3 ${_sl} _libname)
endif()
if ("${_libname}" MATCHES "qad_.*${_v}")
string(LENGTH ${_libname} _sl)
math(EXPR _sl ${_sl}-1)
string(SUBSTRING ${_libname} 0 ${_sl} _libname)
#message("qad lib \"${_libname}\"")
list(APPEND _qt_libs ${_libname})
endif()
endif()
endforeach()
if (NOT "x${_qt_libs}" STREQUAL "x")
list(APPEND _qt_libs "qtbase")
foreach (_i ${${PROJECT_NAME}_LANG})
foreach (_l ${_qt_libs})
unset(_qm_path CACHE)
find_file(_qm_path "${_l}_${_i}.qm" PATHS "${Qt${_v}_LANG_DIR}" ${_PATHS} NO_DEFAULT_PATH)
if (EXISTS "${_qm_path}")
install(FILES ${_qm_path} DESTINATION "${_DEST}")
#message("qm = \"${_qm_path}\"")
endif()
endforeach()
endforeach()
endif()
endif()
endforeach()
endmacro()
macro(qt_get_target _NAME _OUT)
set(${_OUT})
set(_ver)
foreach(_i ${ARGN})
foreach(_v ${_QT_VERSIONS_})
if ("x${_i}" STREQUAL "xQt${_v}")
set(_ver ${_v})
break()
endif()
endforeach()
if (NOT "x${_ver}" STREQUAL "x")
break()
endif()
endforeach()
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v} AND (("x${_ver}" STREQUAL "x") OR ((NOT "x${_ver}" STREQUAL "x") AND ("x${_ver}" STREQUAL "x${_v}"))))
set(${_OUT} ${_NAME}${TARGET_SUFFIX_Qt${_v}})
endif()
endforeach()
endmacro()
macro(qt_get_targets _NAME _OUT)
set(${_OUT})
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v})
list(APPEND ${_OUT} ${_NAME}${TARGET_SUFFIX_Qt${_v}})
endif()
endforeach()
endmacro()
macro(qt_generate_export_header _NAME)
qt_get_target(${_NAME} _some_target)
qt_get_target(${_NAME} _targets)
foreach(_t ${_targets})
set_target_properties(${_t} PROPERTIES DEFINE_SYMBOL ${_NAME}_EXPORTS)
endforeach()
set_target_properties(${_some_target} PROPERTIES DEFINE_SYMBOL ${_NAME}_EXPORTS)
generate_export_header(${_some_target} BASE_NAME "${_NAME}" ${ARGN})
endmacro()
#[[
find_qt([<Module1> <Module2> ...] [Qt4] [Qt5])
Find Qt4 or/and Qt5 packages
If Qt4/5 found, set
* Qt<4/5>_ROOT var to Qt root dir
* Qt<4/5>_BIN var to Qt binary dir
* Qt<4/5>_PLUGINS_DIR var to Qt plugins dir
* Qt<4/5>_LANG_DIR var to Qt translations dir
qt_sources(<src_out_var> [NO_DEFAULT] [DIR <dir>] [<regexp> ...])
Collect all sources, optionally in directory <dir> and
Additional filters <regexp>. By default filter files with regexps
"*.h", "*.hpp", "*.c", "*.cpp", "*.ui", "*.qrc", "*.rc", "*.ts" and "lang/*.ts".
Default filters disabled with option NO_DEFAULT
qt_wrap(<file0> <file1> ... [HDRS <hrd_var>] [CPPS <cpp_var>] [QMS <qm_var>])
Prepare sources for compile
Store headers to <hrd_var>, all wrapped Qt4 files to <cpp_var>_Qt4 and Qt5 files to <cpp_var>_Qt5
version are automatic detected after find_qt() call
qt_add_executable(<name> [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL] source1 [source2 ...])
Add executables for founded Qt versions, target names is <name><TARGET_SUFFIX_Qt?>
All needed Qt includes automatic added to corresponding targets
<source> cant be CPPS variable passed to qt_wrap() or some list or filename
qt_add_library(<name> [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL] source1 [source2 ...])
Add library for founded Qt versions, target names is <name><TARGET_SUFFIX_Qt?>
All needed Qt includes automatic added to corresponding targets
<source> cant be CPPS variable passed to qt_wrap() or some list or filename
qt_target_link_libraries(<name> ... <item> ...)
Link targets for founded Qt versions, target names is <name><TARGET_SUFFIX_Qt?>
All needed Qt libraries automatic added to corresponding targets
if QT_MULTILIB_LIST contains some linking library, to it name automatic
add <MULTILIB_SUFFIX_Qt?> or individual <MULTILIB_>libname<_SUFFIX_Qt?>
qt_target_compile_definitions(<name> ...)
Syntax similar to original "target_compile_definitions()"
Specify compile definitions to use when compiling a given <name>
qt_target_include_directories(<name> ...)
Syntax similar to original "target_include_directories()"
Add include directories to a target
qt_install(...)
Syntax similar to original "install()"
Install targets for founded Qt versions
if DESTINATION set to "QtBin" files will be installed
to corresponding Qt binary directory
if DESTINATION set to "QtLang" files will be installed
to corresponding Qt translation directory
if DESTINATION starts with "QtPlugins" files will be installed
to corresponding Qt plugins directory
Add LANG type for first argument - in this case you should
specify variable name, not variable value!
e.g. "qt_install(LANG my_QM DESTINATION QtLang)"
qt_install_lang(<name> DESTINATION <dir> [PATHS <path0> [<path1>] [...] ])
Search Qt translations for all <name> dependencies
in Qt<?>_LANG_DIR for <name>_LANG languages
and install them to <dir>. PATH are additional search paths.
You should use "set_lang()" macro before this action
qt_get_target(<name> <var> [Qt4 | Qt5])
Write real <name> Qt target name to <var>
If Qt4 or Qt5 specified, search for this version,
otherwise returns greatest version
qt_get_targets(<name> <var>)
Write all real <name> Qt target names to <var>
qt_generate_export_header(<name> ...)
Call generate_export_header on Qt multitarget
]]
cmake_policy(SET CMP0011 NEW) # don`t affect includer policies
cmake_policy(SET CMP0020 NEW) # Automatically link Qt executables to qtmain target on Windows
if (POLICY CMP0057)
cmake_policy(SET CMP0057 NEW) # Support if() IN_LIST
endif()
if (POLICY CMP0074)
cmake_policy(SET CMP0074 OLD) # ignore <PackageName>_ROOT variables
endif()
set(__qt_bug_modules "UiTools")
set(_QT_VERSIONS_ 4 5)
foreach(_v ${_QT_VERSIONS_})
if (NOT DEFINED TARGET_SUFFIX_Qt${_v})
set(TARGET_SUFFIX_Qt${_v} "${_v}")
set(MULTILIB_SUFFIX_Qt${_v} "${_v}")
endif()
set(MOC_INC_Qt${_v})
endforeach()
if (NOT DEFINED QT_MULTILIB_LIST)
set(QT_MULTILIB_LIST)
endif()
#set(TARGET_SUFFIX_Qt4 "")
macro(find_qt)
set(_QCOMP)
foreach(_v ${_QT_VERSIONS_})
set(_NEED${_v} 0)
set(LOCAL_FOUND${_v} 0)
set(MOC_INC_Qt${_v})
set(Qt${_v}_INCLUDES)
set(Qt${_v}_LIBRARIES)
set(Qt${_v}_ROOT)
set(Qt${_v}_BIN)
set(Qt${_v}_PLUGINS_DIR)
set(Qt${_v}_LANG_DIR)
endforeach()
set(_NEED_SOME 0)
set(_QUIET)
foreach(_i ${ARGN})
set(_FOUND_NEED 0)
foreach(_v ${_QT_VERSIONS_})
if ("x${_i}" STREQUAL "xQt${_v}")
set(_NEED${_v} 1)
set(_NEED_SOME 1)
set(_FOUND_NEED 1)
endif()
if ("x${_i}" STREQUAL "xQUIET")
set(_QUIET QUIET)
endif()
endforeach()
if (NOT _FOUND_NEED)
list(APPEND _QCOMP "${_i}")
endif()
endforeach()
if (NOT _NEED_SOME)
foreach(_v ${_QT_VERSIONS_})
set(_NEED${_v} 1)
endforeach()
endif()
list(REMOVE_DUPLICATES _QCOMP)
if (_NEED4)
find_package(Qt4 ${_QUIET})
if (Qt4_FOUND)
set(LOCAL_FOUND4 1)
get_filename_component(Qt4_BIN ${QT_QMAKE_EXECUTABLE} PATH)
set(Qt4_INCLUDES ${QT_INCLUDES})
foreach(m ${_QCOMP})
string(TOUPPER "${m}" _um)
#message("${QT_QT${_um}_FOUND}")
if (${QT_QT${_um}_FOUND})
list(APPEND Qt4_LIBRARIES ${QT_QT${_um}_LIBRARY})
endif()
endforeach()
set(Qt4_PLUGINS_DIR ${QT_PLUGINS_DIR})
set(Qt4_LANG_DIR ${Qt4_BIN}/../translations)
set(Qt4_ROOT "${Qt4_BIN}/../")
endif()
endif()
if (_NEED5)
#set(_MSG 1)
#if (Qt5_FOUND)
# set(_MSG 0)
#endif()
find_package(Qt5 COMPONENTS Core LinguistTools UiPlugin Widgets ${_QCOMP} ${_QUIET})
if (DEFINED ANDROID_PLATFORM)
set(CMAKE_SHARED_MODULE_SUFFIX_CXX ".so")
set(CMAKE_SHARED_LIBRARY_SUFFIX_CXX ".so")
set(CMAKE_SHARED_MODULE_SUFFIX_C ".so")
set(CMAKE_SHARED_LIBRARY_SUFFIX_C ".so")
endif()
if (Qt5_FOUND)
set(LOCAL_FOUND5 1)
set(_Qt5Modules)
foreach(m ${_QCOMP})
if (${Qt5${m}_FOUND})
set(__lib ${Qt5${m}_LIBRARIES})
if (DEFINED ANDROID_PLATFORM)
if (m IN_LIST __qt_bug_modules)
get_target_property(__lib Qt5::${m} LOCATION)
endif()
endif()
list(APPEND _Qt5Modules ${m})
list(APPEND Qt5_INCLUDES ${Qt5${m}_INCLUDE_DIRS})
list(APPEND Qt5_LIBRARIES ${__lib})
endif()
endforeach()
#get_property(_up_dir TARGET Qt5::UiPlugin PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
#message("${_up_dir}")
#if (NOT "x${_up_dir}" STREQUAL "x")
# list(APPEND Qt5_INCLUDES ${_up_dir})
#endif()
get_target_property(_Qt5_qmake Qt5::qmake LOCATION)
get_filename_component(Qt5_BIN ${_Qt5_qmake} PATH)
foreach(_p ${Qt5Gui_PLUGINS})
get_target_property(_l ${_p} LOCATION)
get_filename_component(_l ${_l} DIRECTORY)
string(FIND "${_l}" "/" _ind REVERSE)
string(SUBSTRING "${_l}" 0 ${_ind} _l)
set(Qt5_PLUGINS_DIR ${_l})
#message("Qt5: plugins dir: ${Qt5_PLUGINS_DIR}")
break()
endforeach()
string(FIND "${Qt5_BIN}" "/" _ind REVERSE)
string(SUBSTRING "${Qt5_BIN}" 0 ${_ind} Qt5_ROOT)
if ("x${Qt5_PLUGINS_DIR}" STREQUAL "x")
set(Qt5_PLUGINS_DIR "${Qt5_ROOT}/plugins")
endif()
if (APPLE)
list(APPEND MOC_INC_Qt5 "-F${Qt5_ROOT}/lib")
endif()
set(Qt5_LANG_DIR ${Qt5_BIN}/../translations)
if (NOT _QT5_MSG)
message(STATUS "Found Qt5: ${_Qt5_qmake} (version \"${Qt5_VERSION}\")")
set(_QT5_MSG 1 CACHE BOOL "msg_qt5" FORCE)
#message(STATUS "Found Qt5 modules: ${_Qt5Modules}")
endif()
endif()
endif()
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v})
foreach(_p ${Qt${_v}_INCLUDES})
list(APPEND MOC_INC_Qt${_v} "-I${_p}")
#message("${_p}")
endforeach()
endif()
#message("${MOC_INC_Qt${_v}}")
endforeach()
endmacro()
macro(qt_sources OUT)
set(${OUT})
set(_DIR "")
set(_IS_DIR 0)
set(_NO_DEFAULT 0)
set(_DEFAULT)
set(_REGEXP)
set(_REGEXP_WD)
foreach(_i ${ARGN})
if (_IS_DIR)
set(_DIR "${_i}")
set(_IS_DIR 0)
elseif ("x${_i}" STREQUAL "xDIR")
set(_IS_DIR 1)
elseif ("x${_i}" STREQUAL "xNO_DEFAULT")
set(_NO_DEFAULT 1)
else()
list(APPEND _REGEXP ${_i})
endif()
endforeach()
if (NOT "x${_DIR}" STREQUAL "x")
#file(TO_CMAKE_PATH "${_DIR}//" _DIR)
string(REPLACE "\\" "/" _DIR "${_DIR}/")
string(REPLACE "//" "/" _DIR "${_DIR}")
endif()
foreach(_i ${_REGEXP})
list(APPEND _REGEXP_WD "${_DIR}${_i}")
endforeach()
if (NOT _NO_DEFAULT)
set(_DEFAULT "${_DIR}*.h" "${_DIR}*.hpp" "${_DIR}*.c" "${_DIR}*.cpp" "${_DIR}*.ui" "${_DIR}*.qrc" "${_DIR}*.rc" "${_DIR}*.ts" "${_DIR}lang/*.ts")
endif()
#message("${_DEFAULT}, ${_REGEXP_WD}")
file(GLOB ${OUT} ${_DEFAULT} ${_REGEXP_WD})
endmacro()
macro(qt_wrap)
set(HDR_VAR)
set(CPP_VAR)
set(QM_VAR)
set(_HDR_ARG 0)
set(_CPP_ARG 0)
set(_QM_ARG 0)
set(WAS_HDR_ARG 0)
set(WAS_CPP_ARG 0)
set(WAS_QM_ARG 0)
set(FILE_LIST)
foreach(_i ${ARGN})
if (_HDR_ARG)
set(HDR_VAR ${_i})
set(WAS_HDR_ARG 1)
set(_HDR_ARG 0)
elseif (_CPP_ARG)
set(CPP_VAR ${_i})
set(WAS_CPP_ARG 1)
set(_CPP_ARG 0)
elseif (_QM_ARG)
set(QM_VAR ${_i})
set(WAS_QM_ARG 1)
set(_QM_ARG 0)
elseif ("x${_i}" STREQUAL "xHDRS")
set(_HDR_ARG 1)
elseif ("x${_i}" STREQUAL "xCPPS")
set(_CPP_ARG 1)
elseif ("x${_i}" STREQUAL "xQMS")
set(_QM_ARG 1)
else()
list(APPEND FILE_LIST "${_i}")
endif()
endforeach()
foreach(_v ${_QT_VERSIONS_})
set(CPP${_v}_VAR)
set(QM${_v}_VAR)
if (LOCAL_FOUND${_v})
if (WAS_CPP_ARG)
set(CPP${_v}_VAR ${CPP_VAR}_Qt${_v})
endif()
if (WAS_QM_ARG)
set(QM${_v}_VAR ${QM_VAR}_Qt${_v})
endif()
endif()
endforeach()
#message("found 4: ${LOCAL_FOUND4}, 5: ${LOCAL_FOUND5}")
#message("has HRDS: ${WAS_HDR_ARG}: ${HDR_VAR}")
#message("has CPPS4: ${WAS_CPP_ARG}: ${CPP4_VAR}")
#message("has CPPS5: ${WAS_CPP_ARG}: ${CPP5_VAR}")
#message("files: ${FILE_LIST}")
set(H_LIST)
set(CPP_LIST)
set(UI_LIST)
set(RES_LIST)
set(RC_LIST)
set(TS_LIST)
foreach(_i ${FILE_LIST})
get_filename_component(_EXT "${_i}" EXT)
#message("${_EXT}")
if (NOT ("x${_EXT}" STREQUAL "x"))
if (("x${_EXT}" STREQUAL "x.h") OR ("x${_EXT}" STREQUAL "x.hpp"))
list(APPEND H_LIST "${_i}")
#message("header")
endif()
if (("x${_EXT}" STREQUAL "x.c") OR ("x${_EXT}" STREQUAL "x.cpp") OR ("x${_EXT}" STREQUAL "x.cxx"))
list(APPEND CPP_LIST "${_i}")
#message("source")
endif()
if ("x${_EXT}" STREQUAL "x.ui")
list(APPEND UI_LIST "${_i}")
endif()
if ("x${_EXT}" STREQUAL "x.qrc")
list(APPEND RES_LIST "${_i}")
endif()
if ("x${_EXT}" STREQUAL "x.rc")
list(APPEND RC_LIST "${_i}")
endif()
if ("x${_EXT}" STREQUAL "x.ts")
list(APPEND TS_LIST "${_i}")
endif()
endif()
endforeach()
if (WAS_HDR_ARG)
set(${HDR_VAR})
list(APPEND ${HDR_VAR} ${H_LIST})
endif()
set(SRC_CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v} AND WAS_CPP_ARG)
set(CMAKE_CURRENT_BINARY_DIR ${SRC_CMAKE_CURRENT_BINARY_DIR}/qt${_v})
set(${CPP${_v}_VAR})
if (WAS_QM_ARG)
set(${QM${_v}_VAR})
endif()
set(MOCS${_v})
set(CUIS${_v})
set(CRES${_v})
if (${_v} EQUAL 4)
qt4_wrap_cpp(MOCS${_v} ${H_LIST} OPTIONS -nw ${MOC_INC_Qt4})
qt4_wrap_ui(CUIS${_v} ${UI_LIST})
qt4_add_resources(CRES${_v} ${RES_LIST})
if (WAS_QM_ARG)
set(${QM${_v}_VAR} "")
qt4_add_translation(${QM${_v}_VAR} ${TS_LIST})
endif()
elseif (${_v} EQUAL 5)
qt5_wrap_cpp(MOCS${_v} ${H_LIST} OPTIONS -nw ${MOC_INC_Qt5})
qt5_wrap_ui(CUIS${_v} ${UI_LIST})
qt5_add_resources(CRES${_v} ${RES_LIST})
if (WAS_QM_ARG)
set(${QM${_v}_VAR} "")
qt5_add_translation(${QM${_v}_VAR} ${TS_LIST})
endif()
else()
# Qt6 ...
endif()
#message("${${QM${_v}_VAR}}")
list(APPEND ${CPP${_v}_VAR} ${CPP_LIST})
list(APPEND ${CPP${_v}_VAR} ${RC_LIST})
list(APPEND ${CPP${_v}_VAR} ${MOCS${_v}})
list(APPEND ${CPP${_v}_VAR} ${CUIS${_v}})
list(APPEND ${CPP${_v}_VAR} ${CRES${_v}})
if (WAS_QM_ARG)
list(APPEND ${CPP${_v}_VAR} ${${QM${_v}_VAR}})
endif()
#message("${${QM${_v}_VAR}}")
endif()
endforeach()
set(CMAKE_CURRENT_BINARY_DIR ${SRC_CMAKE_CURRENT_BINARY_DIR})
endmacro()
macro(_qt_split_add_args _P _A)
set(${_P})
set(${_A})
foreach(_i ${ARGN})
if (NOT ("x${${_i}_Qt${_v}}" STREQUAL "x"))
list(APPEND ${_A} ${${_i}_Qt${_v}})
elseif (("x${_i}" STREQUAL "xWIN32") OR
("x${_i}" STREQUAL "xMACOSX_BUNDLE") OR
("x${_i}" STREQUAL "xSTATIC") OR
("x${_i}" STREQUAL "xSHARED") OR
("x${_i}" STREQUAL "xMODULE") OR
("x${_i}" STREQUAL "xEXCLUDE_FROM_ALL"))
list(APPEND ${_P} ${_i})
elseif ("x${${_i}}" STREQUAL "x")
list(APPEND ${_A} ${_i})
else()
list(APPEND ${_A} ${${_i}})
endif()
endforeach()
endmacro()
macro(__qt_set_defines _NAME _T)
target_compile_definitions(${_T} PRIVATE "__TARGET_NAME__=\"${_NAME}\"")
target_compile_definitions(${_T} PRIVATE "__TARGET_LABEL__=\"${${_NAME}_LABEL}\"")
target_compile_definitions(${_T} PRIVATE "__TARGET_COMPANY__=\"${${_NAME}_COMPANY}\"")
target_compile_definitions(${_T} PRIVATE "__TARGET_VERSION__=\"${${_NAME}_VERSION}\"")
endmacro()
macro(qt_add_executable _NAME)
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v})
_qt_split_add_args(_PREF _ARGS ${ARGN})
if(APPLE)
set(_PREV_CIND "${CMAKE_INSTALL_NAME_DIR}")
set(CMAKE_INSTALL_NAME_DIR "@rpath")
else()
if(NOT WIN32)
set(CMAKE_INSTALL_RPATH "\$ORIGIN;\$ORIGIN/lib")
endif()
endif()
set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}})
add_executable(${_TARGET} ${_PREF} ${_ARGS})
set(_${_NAME}_is_qt 1)
target_include_directories(${_TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/qt${_v} ${Qt${_v}_INCLUDES})
__qt_set_defines(${_NAME} ${_TARGET})
if(APPLE)
set(CMAKE_INSTALL_NAME_DIR "${_PREV_CIND}")
endif()
# # Apple crosscompiling rpath patch
# if (APPLE AND CMAKE_CROSSCOMPILING AND CMAKE_MACOSX_RPATH)
# foreach(_RP ${CMAKE_INSTALL_RPATH})
# add_custom_command(TARGET ${_TARGET} POST_BUILD
# COMMAND "${CMAKE_INSTALL_NAME_TOOL}"
# "-add_rpath" "${_RP}"
# "$<TARGET_FILE_DIR:${_TARGET}>/$<TARGET_FILE_NAME:${_TARGET}>"
# COMMENT "Add to ${_TARGET} rpath \"${_RP}\"")
# endforeach()
# endif()
#list(APPEND _ALL_TARGETS "${_TARGET}")
#set(_ALL_TARGETS ${_ALL_TARGETS} PARENT_SCOPE)
endif()
endforeach()
endmacro()
macro(qt_add_library _NAME)
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v})
_qt_split_add_args(_PREF _ARGS ${ARGN})
if(APPLE)
set(_PREV_CIND "${CMAKE_INSTALL_NAME_DIR}")
set(CMAKE_INSTALL_NAME_DIR "@rpath")
else()
if(NOT WIN32)
set(CMAKE_INSTALL_RPATH "\$ORIGIN;\$ORIGIN/lib")
endif()
endif()
set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}})
add_library(${_TARGET} ${_PREF} ${_ARGS})
set(_${_NAME}_is_qt 1)
target_include_directories(${_TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/qt${_v} ${Qt${_v}_INCLUDES})
__qt_set_defines(${_NAME} ${_TARGET})
#message("add lib: \"${_TARGET}\"")
if(APPLE)
set(CMAKE_INSTALL_NAME_DIR "${_PREV_CIND}")
endif()
# # Apple crosscompiling rpath patch
# if (APPLE AND CMAKE_CROSSCOMPILING AND CMAKE_MACOSX_RPATH)
# foreach(_RP ${CMAKE_INSTALL_RPATH})
# add_custom_command(TARGET ${_TARGET} POST_BUILD
# COMMAND "${CMAKE_INSTALL_NAME_TOOL}"
# "-add_rpath" "${_RP}"
# "$<TARGET_FILE_DIR:${_TARGET}>/$<TARGET_FILE_NAME:${_TARGET}>"
# COMMENT "Add to ${_TARGET} rpath \"${_RP}\"")
# endforeach()
# endif()
list(APPEND _ALL_TARGETS "${_TARGET}")
set(_ALL_TARGETS ${_ALL_TARGETS} PARENT_SCOPE)
endif()
endforeach()
endmacro()
macro(_qt_multitarget_suffix_ _OUT _IN _v)
string(REPLACE ":" "_" _in_str "${_IN}")
if (NOT "x${MULTILIB_${_in_str}_SUFFIX_Qt${_v}}" STREQUAL "x")
set(${_OUT} "${MULTILIB_${_in_str}_SUFFIX_Qt${_v}}")
else()
set(${_OUT} "${MULTILIB_SUFFIX_Qt${_v}}")
endif()
endmacro()
macro(qt_target_link_libraries _NAME)
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v})
set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}})
set(_ARGS)
foreach(_i ${ARGN})
set(_ind -1)
list(FIND QT_MULTILIB_LIST "${_i}" _ind)
if (_ind GREATER -1)
_qt_multitarget_suffix_(_TS ${_i} ${_v})
#message(STATUS "${_i} in MULTILIB_LIST, suffix = ${_TS}")
list(APPEND _ARGS ${_i}${_TS})
else()
list(APPEND _ARGS ${_i})
endif()
endforeach()
target_link_libraries(${_TARGET} ${Qt${_v}_LIBRARIES} ${_ARGS})
#message("link ${_TARGET}: ${Qt${_v}_LIBRARIES} ${_ARGS}")
endif()
endforeach()
endmacro()
macro(qt_target_compile_definitions _NAME)
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v})
set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}})
target_compile_definitions(${_TARGET} ${ARGN})
endif()
endforeach()
endmacro()
macro(qt_target_include_directories _NAME)
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v})
set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}})
target_include_directories(${_TARGET} ${ARGN})
endif()
endforeach()
endmacro()
macro(qt_install)
set(_prev_inst)
set(__add_args)
#message("command: ${ARGN}")
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v})
set(_INST_LIST)
set(_IS_TARGET 0)
set(_IS_FILES 0)
set(_IS_DEST 0)
set(_IS_LANG 0)
set(_INVALID 0)
foreach(_i ${ARGN})
if ("x${_i}" STREQUAL "xQtLang")
set(_IS_LANG 1)
endif()
endforeach()
foreach(_i ${ARGN})
if (_IS_TARGET)
set(_IS_TARGET 0)
set(__target ${_i})
if (_${_i}_is_qt)
set(__target ${_i}${TARGET_SUFFIX_Qt${_v}})
endif()
if (DEFINED ANDROID_PLATFORM)
get_target_property(_TT ${__target} TYPE)
if ("x${_TT}" STREQUAL "xEXECUTABLE")
list(APPEND __add_args EXCLUDE_FROM_ALL)
endif()
endif()
list(APPEND _INST_LIST ${__target})
elseif (_IS_FILES)
set(_IS_FILES 0)
if (_IS_LANG)
if (("x${${_i}_Qt${_v}}" STREQUAL "x") OR ("x${_i}" STREQUAL "xDESTINATION"))
set(_INVALID 1)
else()
list(APPEND _INST_LIST ${${_i}_Qt${_v}})
endif()
else()
list(APPEND _INST_LIST ${_i})
endif()
else()
if (_IS_DEST)
set(_IS_DEST 0)
if ("x${_i}" STREQUAL "xQtBin")
list(APPEND _INST_LIST "${Qt${_v}_BIN}")
elseif ("x${_i}" STREQUAL "xQtLang")
list(APPEND _INST_LIST "${Qt${_v}_LANG_DIR}")
else()
set(_ind -1)
string(FIND "${_i}" "QtPlugins" _ind)
if (_ind GREATER -1)
string(REPLACE "QtPlugins" "${Qt${_v}_PLUGINS_DIR}" _o "${_i}")
list(APPEND _INST_LIST "${_o}")
else()
string(REPLACE "\\" "/" _o "${_i}")
list(APPEND _INST_LIST ${_o})
endif()
endif()
else()
set(_ii ${_i})
if ("x${_i}" STREQUAL "xTARGETS")
set(_IS_TARGET 1)
elseif ("x${_i}" STREQUAL "xFILES")
set(_IS_FILES 1)
elseif ("x${_i}" STREQUAL "xDESTINATION")
set(_IS_DEST 1)
elseif ("x${_i}" STREQUAL "xLANG")
set(_IS_FILES 1)
set(_IS_LANG 1)
set(_ii "FILES")
endif()
list(APPEND _INST_LIST ${_ii})
endif()
endif()
endforeach()
if (NOT _INVALID)
if (NOT ("x${_prev_inst}" STREQUAL "x${_INST_LIST}"))
#message("install: ${_INST_LIST}")
install(${_INST_LIST} ${__add_args})
set(_prev_inst "${_INST_LIST}")
endif()
endif()
endif()
endforeach()
endmacro()
macro(qt_install_lang _NAME)
set(_prev_inst)
#message("command: ${ARGN}")
set(_PATHS)
set(_DEST)
if(CMAKE_CROSSCOMPILING)
list(APPEND _PATHS "${CMAKE_PREFIX_PATH}/lang")
endif()
set(_cur_arg)
set(__args "DESTINATION;PATHS")
foreach(_i ${ARGN})
if (_i IN_LIST __args)
set(_cur_arg "${_i}")
elseif("${_cur_arg}" STREQUAL "DESTINATION")
set(_DEST "${_i}")
elseif("${_cur_arg}" STREQUAL "PATHS")
list(APPEND _PATHS "${_i}")
endif()
endforeach()
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v})
set(_target)
if (_${_NAME}_is_qt)
set(_target ${_NAME}${TARGET_SUFFIX_Qt${_v}})
endif()
get_target_property(_LL ${_target} LINK_LIBRARIES)
foreach (_L ${_LL})
get_filename_component(_libname "${_L}" NAME_WE)
#message("depend on ${_libname}")
if ("${_libname}" MATCHES "Qt${_v}::.*")
string(SUBSTRING "${_libname}" 5 -1 _libname)
string(TOLOWER "${_libname}" _libname)
#message("qt lib \"${_libname}\"")
list(APPEND _qt_libs qt${_libname})
else()
if ("${_libname}" MATCHES "lib.*")
string(LENGTH ${_libname} _sl)
math(EXPR _sl ${_sl}-3)
string(SUBSTRING ${_libname} 3 ${_sl} _libname)
endif()
if ("${_libname}" MATCHES "qad_.*${_v}")
string(LENGTH ${_libname} _sl)
math(EXPR _sl ${_sl}-1)
string(SUBSTRING ${_libname} 0 ${_sl} _libname)
#message("qad lib \"${_libname}\"")
list(APPEND _qt_libs ${_libname})
endif()
endif()
endforeach()
if (NOT "x${_qt_libs}" STREQUAL "x")
list(APPEND _qt_libs "qtbase")
foreach (_i ${${PROJECT_NAME}_LANG})
foreach (_l ${_qt_libs})
unset(_qm_path CACHE)
find_file(_qm_path "${_l}_${_i}.qm" PATHS "${Qt${_v}_LANG_DIR}" ${_PATHS} NO_DEFAULT_PATH)
if (EXISTS "${_qm_path}")
install(FILES ${_qm_path} DESTINATION "${_DEST}")
#message("qm = \"${_qm_path}\"")
endif()
endforeach()
endforeach()
endif()
endif()
endforeach()
endmacro()
macro(qt_get_target _NAME _OUT)
set(${_OUT})
set(_ver)
foreach(_i ${ARGN})
foreach(_v ${_QT_VERSIONS_})
if ("x${_i}" STREQUAL "xQt${_v}")
set(_ver ${_v})
break()
endif()
endforeach()
if (NOT "x${_ver}" STREQUAL "x")
break()
endif()
endforeach()
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v} AND (("x${_ver}" STREQUAL "x") OR ((NOT "x${_ver}" STREQUAL "x") AND ("x${_ver}" STREQUAL "x${_v}"))))
set(${_OUT} ${_NAME}${TARGET_SUFFIX_Qt${_v}})
endif()
endforeach()
endmacro()
macro(qt_get_targets _NAME _OUT)
set(${_OUT})
foreach(_v ${_QT_VERSIONS_})
if (LOCAL_FOUND${_v})
list(APPEND ${_OUT} ${_NAME}${TARGET_SUFFIX_Qt${_v}})
endif()
endforeach()
endmacro()
macro(qt_generate_export_header _NAME)
qt_get_target(${_NAME} _some_target)
qt_get_target(${_NAME} _targets)
foreach(_t ${_targets})
set_target_properties(${_t} PROPERTIES DEFINE_SYMBOL ${_NAME}_EXPORTS)
endforeach()
set_target_properties(${_some_target} PROPERTIES DEFINE_SYMBOL ${_NAME}_EXPORTS)
generate_export_header(${_some_target} BASE_NAME "${_NAME}" ${ARGN})
endmacro()

View File

@@ -1,14 +0,0 @@
project(qpicalc)
if(APPLE)
set(APP_ICON "")
elseif(WIN32)
set(APP_ICON "icons/qpicalculator.ico")
else()
set(APP_ICON "icons/qpicalculator.png")
endif()
set(APP_INFO "Small calculator ang grapher")
qad_application(${PROJECT_NAME} "Gui;Widgets" "qad_utils;qad_widgets;qad_graphic")
if (Qt5_FOUND)
import_version(${PROJ_NAME}5 ${PROJECT_NAME})
deploy_target(${PROJECT_NAME}5 DEPLOY_DIR ${CMAKE_CURRENT_BINARY_DIR} DESTINATION ${ROOT_DIR}/release)
endif()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 158 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

View File

@@ -1,13 +0,0 @@
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
#if QT_VERSION >= 0x050000
a.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
#endif
MainWindow w;
w.show();
return a.exec();
}

View File

@@ -1,261 +0,0 @@
#include "mainwindow.h"
MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow() {
setupUi(this);
active_ = false;
lineInput->setFocus();
#if QT_VERSION >= 0x050000
treeGraphics->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
treeGraphics->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
#else
treeGraphics->header()->setResizeMode(0, QHeaderView::ResizeToContents);
treeGraphics->header()->setResizeMode(1, QHeaderView::ResizeToContents);
#endif
npal = epal = lineInput->palette();
epal.setColor(lineInput->backgroundRole(), QColor(Qt::red).lighter(150));
connect(&session, SIGNAL(loading(QPIConfig & )), this, SLOT(loading(QPIConfig & )));
connect(&session, SIGNAL(saving(QPIConfig & )), this, SLOT(saving(QPIConfig & )));
session.setFile("session_qpicalc.conf");
session.addEntry(this);
session.addEntry(lineInput);
session.addEntry(tabWidget);
session.load();
ans = evaluator.setVariable("ans");
on_lineInput_returnPressed();
}
MainWindow::~MainWindow() {session.save();
}
void MainWindow::changeEvent(QEvent * e) {
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::updateGraphics() {
graphic->setGraphicsCount(treeGraphics->topLevelItemCount());
for (int i = 0; i < treeGraphics->topLevelItemCount(); ++i)
graphic->setGraphicColor(treeGraphics->topLevelItem(i)->data(0, Qt::DecorationRole).value<QColor>(), i);
redrawGraphics();
}
void MainWindow::redrawGraphics() {
QRectF sr = graphic->visualRect();
double dx = (sr.right() - sr.left()) / graphic->width(), sx = sr.left(), fx = sr.right(), cx;
QPolygonF pol;
evaluator.setVariable("x");
int vi = evaluator.variableIndex("x");
graphic->setAutoUpdate(false);
for (int i = 0; i < treeGraphics->topLevelItemCount(); ++i) {
QTreeWidgetItem * ti = treeGraphics->topLevelItem(i);
graphic->setGraphicName(ti->text(1), i);
pol.clear();
if (ti->checkState(0) == Qt::Checked) {
if (evaluator.check(ti->text(1))) {
cx = sx;
while (cx < fx) {
evaluator.setVariable(vi, complexd(cx, 0.));
pol << QPointF(cx, evaluator.evaluate().real());
cx += dx;
}
}
}
graphic->setGraphicVisible(ti->checkState(0) == Qt::Checked, i);
graphic->setGraphicData(pol, i);
}
graphic->setAutoUpdate(true);
graphic->update(true);
}
void MainWindow::loading(QPIConfig & conf) {
active_ = false;
QStringList vars = conf.getValue("variables").toStringList();
int vc = vars.size() / 2;
for (int i = 0; i < vc; ++i) {
QTreeWidgetItem * ti = new QTreeWidgetItem(treeVariables);
ti->setText(0, vars[i * 2]);
ti->setText(1, vars[i * 2 + 1]);
ti->setFlags(ti->flags() | Qt::ItemIsEditable);
treeVariables->addTopLevelItem(ti);
}
buttonVarClear->setEnabled(treeVariables->topLevelItemCount() > 0);
QByteArray ba = conf.getValue("graphics").toByteArray();
QDataStream s(ba);
QVector<GraphicType> g;
if (!ba.isEmpty()) s >> g;
graphic->setAllGraphics(g);
for (int i = 0; i < graphic->graphicsCount(); ++i) {
graphic->setCurrentGraphic(i);
QTreeWidgetItem * ti = new QTreeWidgetItem(treeGraphics);
ti->setFlags(ti->flags() | Qt::ItemIsEditable);
ti->setCheckState(0, graphic->graphicVisible() ? Qt::Checked : Qt::Unchecked);
ti->setData(0, Qt::DecorationRole, graphic->graphicColor());
ti->setText(1, graphic->graphicName());
treeGraphics->addTopLevelItem(ti);
}
buttonGraphicClear->setEnabled(treeGraphics->topLevelItemCount() > 0);
graphic->setVisualRect(conf.getValue("graphicRect", QRectF(-1., -1., 2., 2.)).toRectF());
ba = conf.getValue("graphic_state").toByteArray();
if (!ba.isEmpty())
graphic->load(ba);
on_tabWidget_currentChanged(0);
redrawGraphics();
active_ = true;
}
void MainWindow::saving(QPIConfig & conf) {
QStringList vars;
int vc = treeVariables->topLevelItemCount();
for (int i = 0; i < vc; ++i) {
QTreeWidgetItem * ti = treeVariables->topLevelItem(i);
vars << ti->text(0) << ti->text(1);
}
conf.setValue("variables", vars);
QVector<GraphicType> g;
vc = treeGraphics->topLevelItemCount();
for (int i = 0; i < vc; ++i) {
QTreeWidgetItem * ti = treeGraphics->topLevelItem(i);
vars << QString::number(ti->background(1).color().rgb()) << ti->text(2);
}
QByteArray ba; QDataStream s(&ba, QIODevice::WriteOnly);
s << graphic->allGraphics();
conf.setValue("graphics", QByteArray2QString(ba));
conf.setValue("graphicRect", graphic->visualRect());
conf.setValue("graphic_state", graphic->save());
}
void MainWindow::on_lineInput_textChanged(QString text) {
if (evaluator.check(text)) lineInput->setPalette(npal);
else lineInput->setPalette(epal);
labelParsed->setText(evaluator.expression());
labelError->setText(evaluator.error());
}
void MainWindow::on_lineInput_returnPressed() {
bool ret = evaluator.check(lineInput->text());
if (ret) lineInput->setPalette(npal);
else lineInput->setPalette(epal);
labelParsed->setText(evaluator.expression());
labelError->setText(evaluator.error());
if (!ret) return;
complexd val = evaluator.evaluate();
evaluator.setVariable(ans, val);
if (val.imag() == 0) labelResult->setText(QString::number(val.real()));
else {
if (val.real() == 0) labelResult->setText(QString::number(val.imag()) + "i");
else {
if (val.imag() > 0) labelResult->setText(QString::number(val.real())
+ " + " + QString::number(val.imag()) + "i");
else labelResult->setText(QString::number(val.real())
+ " - " + QString::number(fabs(val.imag())) + "i");
}
}
if (lineInput->text().trimmed().isEmpty()) return;
QTreeWidgetItem * ti = 0, * pti = 0;
if (treeHistory->topLevelItemCount() > 0)
pti = treeHistory->topLevelItem(treeHistory->topLevelItemCount() - 1);
if (pti != 0)
if (pti->text(0) == lineInput->text())
return;
ti = new QTreeWidgetItem(treeHistory);
ti->setText(0, lineInput->text());
ti->setText(1, labelResult->text());
treeHistory->addTopLevelItem(ti);
if (treeHistory->verticalScrollBar()->value() == treeHistory->verticalScrollBar()->maximum())
treeHistory->scrollToBottom();
}
void MainWindow::on_treeGraphics_itemDoubleClicked(QTreeWidgetItem * item, int column) {
Qt::ItemFlags f = item->flags();
if (column != 1) f &= ~Qt::ItemIsEditable;
else f |= Qt::ItemIsEditable;
item->setFlags(f);
if (column != 0) return;
QColor col = QColorDialog::getColor(item->data(0, Qt::DecorationRole).value<QColor>(), this, "Select color for graphic", QColorDialog::ShowAlphaChannel);
if (!col.isValid()) return;
item->setData(0, Qt::DecorationRole, col);
updateGraphics();
}
void MainWindow::on_buttonVarAdd_clicked() {
QTreeWidgetItem * ti = new QTreeWidgetItem(treeVariables);
ti->setSelected(true);
ti->setFlags(ti->flags() | Qt::ItemIsEditable);
treeVariables->addTopLevelItem(ti);
treeVariables->setFocus();
treeVariables->editItem(ti);
buttonVarClear->setEnabled(treeVariables->topLevelItemCount() > 0);
}
void MainWindow::on_buttonVarDel_clicked() {
QList<QTreeWidgetItem * > si = treeVariables->selectedItems();
foreach (QTreeWidgetItem * i, si)
delete i;
buttonVarClear->setEnabled(treeVariables->topLevelItemCount() > 0);
}
void MainWindow::on_buttonGraphicAdd_clicked() {
graphic->setGraphicsCount(graphic->graphicsCount() + 1);
graphic->setCurrentGraphic(graphic->graphicsCount() - 1);
QTreeWidgetItem * ti = new QTreeWidgetItem(treeGraphics);
ti->setSelected(true);
ti->setFlags(ti->flags() | Qt::ItemIsEditable);
ti->setCheckState(0, Qt::Checked);
ti->setData(0, Qt::DecorationRole, graphic->graphicColor());
treeGraphics->addTopLevelItem(ti);
treeGraphics->setFocus();
treeGraphics->editItem(ti, 1);
buttonGraphicClear->setEnabled(treeGraphics->topLevelItemCount() > 0);
updateGraphics();
}
void MainWindow::on_buttonGraphicDel_clicked() {
QList<QTreeWidgetItem * > si = treeGraphics->selectedItems();
foreach (QTreeWidgetItem * i, si)
delete i;
buttonGraphicClear->setEnabled(treeGraphics->topLevelItemCount() > 0);
updateGraphics();
}
void MainWindow::on_buttonGraphicClear_clicked() {
treeGraphics->clear();
buttonGraphicClear->setEnabled(false);
updateGraphics();
}
void MainWindow::on_tabWidget_currentChanged(int index) {
QPIEvaluator eval;
evaluator.clearCustomVariables();
for (int i = 0; i < treeVariables->topLevelItemCount(); ++i) {
QString vn, vv;
vn = treeVariables->topLevelItem(i)->text(0);
vv = treeVariables->topLevelItem(i)->text(1);
eval.check(vv);
evaluator.setVariable(vn, eval.evaluate());
}
if (index == 0) on_lineInput_returnPressed();
if (index == 2) redrawGraphics();
}

View File

@@ -1,56 +0,0 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPalette>
#include <QFile>
#include <QTextStream>
#include <QScrollBar>
#include <QColorDialog>
#include "ui_mainwindow.h"
#include "qpievaluator.h"
#include "session_manager.h"
class MainWindow: public QMainWindow, private Ui::MainWindow
{
Q_OBJECT
public:
MainWindow(QWidget * parent = 0);
~MainWindow();
protected:
void changeEvent(QEvent * e);
private:
void updateGraphics();
void redrawGraphics();
QPIEvaluator evaluator;
QPalette npal, epal;
SessionManager session;
int ans;
bool active_;
private slots:
void loading(QPIConfig & conf);
void saving(QPIConfig & conf);
void on_lineInput_textChanged(QString s);
void on_lineInput_returnPressed();
void on_treeHistory_itemDoubleClicked(QTreeWidgetItem * item, int column) {lineInput->setText(item->text(0));}
void on_treeVariables_itemSelectionChanged() {buttonVarDel->setDisabled(treeVariables->selectedItems().isEmpty());}
void on_treeGraphics_itemSelectionChanged() {buttonGraphicDel->setDisabled(treeGraphics->selectedItems().isEmpty());}
void on_treeGraphics_itemChanged(QTreeWidgetItem * , int col) { if (active_) redrawGraphics();}
void on_treeGraphics_itemDoubleClicked(QTreeWidgetItem * item, int column);
void on_buttonVarAdd_clicked();
void on_buttonVarDel_clicked();
void on_buttonVarClear_clicked() {treeVariables->clear(); buttonVarClear->setEnabled(false);}
void on_buttonGraphicAdd_clicked();
void on_buttonGraphicDel_clicked();
void on_buttonGraphicClear_clicked();
void on_tabWidget_currentChanged(int index);
void on_graphic_visualRectChanged() {redrawGraphics();}
};
#endif // MAINWINDOW_H

View File

@@ -1,379 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>780</width>
<height>521</height>
</rect>
</property>
<property name="windowTitle">
<string>QPICalculator</string>
</property>
<property name="windowIcon">
<iconset resource="qpicalculator.qrc">
<normaloff>:/icons/qpicalculator.png</normaloff>:/icons/qpicalculator.png</iconset>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>2</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Calculator</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTreeWidget" name="treeHistory">
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="itemsExpandable">
<bool>false</bool>
</property>
<property name="allColumnsShowFocus">
<bool>true</bool>
</property>
<attribute name="headerDefaultSectionSize">
<number>300</number>
</attribute>
<column>
<property name="text">
<string>Expression</string>
</property>
</column>
<column>
<property name="text">
<string>Result</string>
</property>
</column>
</widget>
</item>
<item>
<widget class="CLineEdit" name="lineInput"/>
</item>
<item>
<widget class="QLabel" name="labelError">
<property name="text">
<string>Correct</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelParsed">
<property name="text">
<string>0</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelResult">
<property name="font">
<font>
<pointsize>14</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>0</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Variables</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTreeWidget" name="treeVariables">
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="itemsExpandable">
<bool>false</bool>
</property>
<property name="allColumnsShowFocus">
<bool>true</bool>
</property>
<attribute name="headerDefaultSectionSize">
<number>200</number>
</attribute>
<column>
<property name="text">
<string>Name</string>
</property>
</column>
<column>
<property name="text">
<string>Value</string>
</property>
</column>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QToolButton" name="buttonVarAdd">
<property name="icon">
<iconset resource="../../utils/qad_utils.qrc">
<normaloff>:/icons/list-add.png</normaloff>:/icons/list-add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonVarDel">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="../../utils/qad_utils.qrc">
<normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset>
</property>
<property name="shortcut">
<string>Del</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="buttonVarClear">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="../../utils/qad_utils.qrc">
<normaloff>:/icons/edit-clear.png</normaloff>:/icons/edit-clear.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string>Graphics</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QWidget" name="">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QTreeWidget" name="treeGraphics">
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="horizontalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="itemsExpandable">
<bool>false</bool>
</property>
<property name="allColumnsShowFocus">
<bool>true</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<attribute name="headerDefaultSectionSize">
<number>50</number>
</attribute>
<column>
<property name="text">
<string>On</string>
</property>
</column>
<column>
<property name="text">
<string>Function</string>
</property>
</column>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QToolButton" name="buttonGraphicAdd">
<property name="icon">
<iconset resource="../../utils/qad_utils.qrc">
<normaloff>:/icons/list-add.png</normaloff>:/icons/list-add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonGraphicDel">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="../../utils/qad_utils.qrc">
<normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset>
</property>
<property name="shortcut">
<string>Del</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="buttonGraphicClear">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="../../utils/qad_utils.qrc">
<normaloff>:/icons/edit-clear.png</normaloff>:/icons/edit-clear.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="Graphic" name="graphic">
<property name="buttons">
<set>Graphic::BorderInputs|Graphic::Configure|Graphic::CursorAxis|Graphic::Fullscreen|Graphic::Grid|Graphic::Save</set>
</property>
<property name="antialiasing">
<bool>true</bool>
</property>
<property name="borderInputsVisible">
<bool>false</bool>
</property>
<property name="legendVisible">
<bool>false</bool>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>Graphic</class>
<extends>QFrame</extends>
<header>graphic.h</header>
</customwidget>
<customwidget>
<class>CLineEdit</class>
<extends>QLineEdit</extends>
<header>clineedit.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../../utils/qad_utils.qrc"/>
<include location="qpicalculator.qrc"/>
</resources>
<connections/>
</ui>

View File

@@ -1,5 +0,0 @@
<RCC>
<qresource prefix="/">
<file>icons/qpicalculator.png</file>
</qresource>
</RCC>