diff --git a/CMakeLists.txt b/CMakeLists.txt index f2c6f87..3414dad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,10 @@ cmake_minimum_required(VERSION 3.0) cmake_policy(SET CMP0017 NEW) # need include() with .cmake project(qad) -set(qad_MAJOR 1) -set(qad_MINOR 18) +set(qad_MAJOR 2) +set(qad_MINOR 0) set(qad_REVISION 0) -set(qad_SUFFIX ) +set(qad_SUFFIX alpha) set(qad_COMPANY SHS) set(qad_DOMAIN org.SHS) @@ -32,17 +32,17 @@ option(UTILS "Build various utils" ${_plugins_default_}) option(DESIGNER_PLUGINS "Build Qt designer plugins" ${_plugins_default_}) macro(qad_library NAME _MODULES _LIBS) - shstk_qt_project(qad_${NAME} FALSE "qad" "${_MODULES}" "${_LIBS}" ${ARGN}) - shstk_qt_install("qad" FALSE qad_${NAME} "${out_HDR}" "out_QM") + shstk_qad_project(qad_${NAME} FALSE "qad" "${_MODULES}" "${_LIBS}" ${ARGN}) + shstk_qad_install("qad" FALSE qad_${NAME} "${out_HDR}" "out_QM") endmacro() macro(qad_application NAME _MODULES _LIBS) - shstk_qt_project(${NAME} TRUE "qad" "${_MODULES}" "${_LIBS}" ${ARGN}) - shstk_qt_install("qad" TRUE ${NAME} "" "out_QM") + shstk_qad_project(${NAME} TRUE "qad" "${_MODULES}" "${_LIBS}" ${ARGN}) + shstk_qad_install("qad" TRUE ${NAME} "" "out_QM") endmacro() macro(qad_plugin NAME _MODULES _LIBS) - shstk_qt_plugin(qad_${NAME} "${_MODULES}" "qad_${NAME};${_LIBS}") + shstk_qad_plugin(qad_${NAME} "${_MODULES}" "qad_${NAME};${_LIBS}") endmacro() shstk_install(qad FALSE "" "${qad_VERSION_FILE}") diff --git a/cmake/FindQAD.cmake b/cmake/FindQAD.cmake index 96ee0e9..10c7976 100644 --- a/cmake/FindQAD.cmake +++ b/cmake/FindQAD.cmake @@ -30,7 +30,7 @@ shstk_is_parent_exists(hasParent PARENT_DIRECTORY) shstk_set_find_dirs(qad) set(_SEARCH_DIR ${qad_LIBDIR}) -find_qt(Core QUIET) +qad_find_qt(Core QUIET) if(NOT SOME_QT_FOUND) message(WARNING "No qt found, please install qt") set(QAD_FOUND OFF CACHE BOOL "") diff --git a/cmake/QtWraps.cmake b/cmake/QtWraps.cmake index ea1e786..033f0a2 100644 --- a/cmake/QtWraps.cmake +++ b/cmake/QtWraps.cmake @@ -1,19 +1,19 @@ #[[ -find_qt([ ...] [Qt4] [Qt5]) +qad_find_qt([ ...] [Qt4] [Qt5] [Qt6]) -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 +Find Qt4 or/and Qt5, Qt6 packages +If Qt4/5/6 found, set +* Qt<4/5/6>_ROOT var to Qt root dir +* Qt<4/5/6>_BIN var to Qt binary dir +* Qt<4/5/6>_PLUGINS_DIR var to Qt plugins dir +* Qt<4/5/6>_LANG_DIR var to Qt translations dir Also set variable SOME_QT_FOUND -qt_sources( [NO_DEFAULT] [DIR ] [ ...]) +qad_sources( [NO_DEFAULT] [DIR ] [ ...]) Collect all sources, optionally in directory and Additional filters . By default filter files with regexps @@ -23,34 +23,34 @@ Default filters disabled with option NO_DEFAULT -qt_wrap( ... [HDRS ] [CPPS ] [QMS ]) +qad_wrap( ... [HDRS ] [CPPS ] [QMS ]) Prepare sources for compile -Store headers to , all wrapped Qt4 files to _Qt4 and Qt5 files to _Qt5 -version are automatic detected after find_qt() call +Store headers to , all wrapped Qt4 files to _Qt4, Qt5 files to _Qt5 and Qt6 files to _Qt6 +version are automatic detected after qad_find_qt() call -qt_add_executable( [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL] source1 [source2 ...]) +qad_add_executable( [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL] source1 [source2 ...]) Add executables for founded Qt versions, target names is All needed Qt includes automatic added to corresponding targets - cant be CPPS variable passed to qt_wrap() or some list or filename + cant be CPPS variable passed to qad_wrap() or some list or filename -qt_add_library( [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL] source1 [source2 ...]) +qad_add_library( [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL] source1 [source2 ...]) Add library for founded Qt versions, target names is All needed Qt includes automatic added to corresponding targets - cant be CPPS variable passed to qt_wrap() or some list or filename + cant be CPPS variable passed to qad_wrap() or some list or filename -qt_target_link_libraries( ... ...) +qad_target_link_libraries( ... ...) Link targets for founded Qt versions, target names is All needed Qt libraries automatic added to corresponding targets @@ -60,7 +60,7 @@ add or individual libname<_SUFFIX_Qt?> -qt_target_compile_definitions( ...) +qad_target_compile_definitions( ...) Syntax similar to original "target_compile_definitions()" Specify compile definitions to use when compiling a given @@ -68,7 +68,7 @@ Specify compile definitions to use when compiling a given -qt_target_include_directories( ...) +qad_target_include_directories( ...) Syntax similar to original "target_include_directories()" Add include directories to a target @@ -76,7 +76,7 @@ Add include directories to a target -qt_install(...) +qad_install(...) Syntax similar to original "install()" Install targets for founded Qt versions @@ -90,12 +90,12 @@ 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)" +e.g. "qad_install(LANG my_QM DESTINATION QtLang)" -qt_install_lang( DESTINATION [PATHS [] [...] ]) +qad_install_lang( DESTINATION [PATHS [] [...] ]) Search Qt translations for all dependencies in Qt_LANG_DIR for _LANG languages @@ -105,23 +105,23 @@ You should use "set_lang()" macro before this action -qt_get_target( [Qt4 | Qt5]) +qad_get_target( [Qt4 | Qt5 | Qt6]) Write real Qt target name to -If Qt4 or Qt5 specified, search for this version, +If Qt4 or Qt5, Qt6 specified, search for this version, otherwise returns greatest version -qt_get_targets( ) +qad_get_targets( ) Write all real Qt target names to -qt_generate_export_header( ...) +qad_generate_export_header( ...) Call generate_export_header on Qt multitarget @@ -162,7 +162,7 @@ QuickControls2;QuickParticles;QuickShapes;QuickTemplates2;QuickTest;QuickWidgets ShaderTools;Sql;Svg;SvgWidgets;Test;Tools;UiPlugin;UiTools;Widgets;Xml") -set(_QT_VERSIONS_ 4 5) +set(_QT_VERSIONS_ 4 5 6) foreach(_v ${_QT_VERSIONS_}) if (NOT DEFINED TARGET_SUFFIX_Qt${_v}) set(TARGET_SUFFIX_Qt${_v} "${_v}") @@ -176,7 +176,7 @@ endif() #set(TARGET_SUFFIX_Qt4 "") -macro(find_qt) +macro(qad_find_qt) set(_QCOMP) foreach(_v ${_QT_VERSIONS_}) set(_NEED${_v} 0) @@ -307,6 +307,75 @@ macro(find_qt) endif() endif() endif() + if (_NEED6) + #set(_MSG 1) + #if (Qt6_FOUND) + # set(_MSG 0) + #endif() + set(_QCOMP6 Core LinguistTools UiPlugin Widgets ${_QCOMP}) + list(REMOVE_DUPLICATES _QCOMP6) + find_package(Qt6 COMPONENTS ${_QCOMP6} 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 (Qt6Core_FOUND) + set(LOCAL_FOUND6 1) + set(_Qt6Modules) + foreach(m ${_QCOMP6}) + if (m IN_LIST __qt_modules_6) + if (${Qt6${m}_FOUND}) + set(__lib ${Qt6${m}_LIBRARIES}) + if (DEFINED ANDROID_PLATFORM) + if (m IN_LIST __qt_bug_modules) + get_target_property(__lib Qt6::${m} LOCATION) + endif() + endif() + list(APPEND _Qt6Modules ${m}) + list(APPEND Qt6_INCLUDES ${Qt6${m}_INCLUDE_DIRS}) + list(APPEND Qt6_LIBRARIES ${__lib}) + else() + if (NOT "x${_QUIET}" STREQUAL "xQUIET") + message(FATAL_ERROR "Qt6${m} NOT FOUND") + endif() + endif() + endif() + endforeach() + #get_property(_up_dir TARGET Qt6::UiPlugin PROPERTY INTERFACE_INCLUDE_DIRECTORIES) + #message("${_up_dir}") + #if (NOT "x${_up_dir}" STREQUAL "x") + # list(APPEND Qt6_INCLUDES ${_up_dir}) + #endif() + get_target_property(_Qt6_qmake Qt6::qmake LOCATION) + get_filename_component(_Qt6_BIN ${_Qt6_qmake} PATH) + foreach(_p ${Qt6Gui_PLUGINS}) + get_target_property(_l ${_p} LOCATION) + get_filename_component(_l ${_l} DIRECTORY) + string(FIND "${_l}" "/" _ind REVERSE) + string(SUBSTRING "${_l}" 0 ${_ind} _l) + #message("Qt6: plugins dir: ${Qt6_PLUGINS_DIR}") + break() + endforeach() + string(FIND "${_Qt6_BIN}" "/" _ind REVERSE) + string(SUBSTRING "${_Qt6_BIN}" 0 ${_ind} _Qt6_ROOT) + set(Qt6_ROOT "${_Qt6_ROOT}" CACHE STRING "") + set(Qt6_BIN "${_Qt6_BIN}" CACHE STRING "") + set(Qt6_LANG_DIR ${Qt6_BIN}/../translations CACHE STRING "") + if ("x${Qt6_PLUGINS_DIR}" STREQUAL "x") + set(Qt6_PLUGINS_DIR "${Qt6_ROOT}/plugins" CACHE STRING "") + endif() + if (APPLE) + list(APPEND MOC_INC_Qt6 "-F${Qt6_ROOT}/lib") + endif() + if (NOT _QT6_MSG) + message(STATUS "Found Qt6: ${_Qt6_qmake} (version \"${Qt6_VERSION}\")") + set(_QT6_MSG 1 CACHE BOOL "msg_qt6" FORCE) + message(STATUS "Found Qt6 modules: ${_Qt6Modules}") + endif() + endif() + endif() foreach(_v ${_QT_VERSIONS_}) if (LOCAL_FOUND${_v}) set(SOME_QT_FOUND 1 CACHE BOOL "" FORCE) @@ -321,7 +390,7 @@ macro(find_qt) endmacro() -macro(qt_sources OUT) +macro(qad_sources OUT) set(${OUT}) set(_DIR "") set(_IS_DIR 0) @@ -357,7 +426,7 @@ macro(qt_sources OUT) endmacro() -macro(qt_wrap) +macro(qad_wrap) set(HDR_VAR) set(CPP_VAR) set(QM_VAR) @@ -471,8 +540,16 @@ macro(qt_wrap) set(${QM${_v}_VAR} "") qt5_add_translation(${QM${_v}_VAR} ${TS_LIST}) endif() + elseif (${_v} EQUAL 6) + qt6_wrap_cpp(MOCS${_v} ${H_LIST} OPTIONS -nw ${MOC_INC_Qt6}) + qt6_wrap_ui(CUIS${_v} ${UI_LIST}) + qt6_add_resources(CRES${_v} ${RES_LIST}) + if (WAS_QM_ARG) + set(${QM${_v}_VAR} "") + qt6_add_translation(${QM${_v}_VAR} ${TS_LIST}) + endif() else() - # Qt6 ... + # Qt7 ... endif() #message("${${QM${_v}_VAR}}") list(APPEND ${CPP${_v}_VAR} ${CPP_LIST}) @@ -520,7 +597,8 @@ macro(__qt_set_defines _NAME _T) endmacro() -macro(qt_add_executable _NAME) +macro(qad_add_executable _NAME) + #message("*qad_add_executable: \"${_NAME}\"") foreach(_v ${_QT_VERSIONS_}) if (LOCAL_FOUND${_v}) _qt_split_add_args(_PREF _ARGS ${ARGN}) @@ -537,6 +615,7 @@ macro(qt_add_executable _NAME) 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 exe: \"${_TARGET}\"") if(APPLE) set(CMAKE_INSTALL_NAME_DIR "${_PREV_CIND}") @@ -559,7 +638,8 @@ macro(qt_add_executable _NAME) endmacro() -macro(qt_add_library _NAME) +macro(qad_add_library _NAME) + #message("*qad_add_library: \"${_NAME}\"") foreach(_v ${_QT_VERSIONS_}) if (LOCAL_FOUND${_v}) _qt_split_add_args(_PREF _ARGS ${ARGN}) @@ -573,6 +653,7 @@ macro(qt_add_library _NAME) endif() set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}}) add_library(${_TARGET} ${_PREF} ${_ARGS}) + #message("add lib: \"${_TARGET} ${_PREF}\"") set(_${_NAME}_is_qt 1) target_include_directories(${_TARGET} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/qt${_v}) target_include_directories(${_TARGET} PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${Qt${_v}_INCLUDES}) @@ -610,7 +691,7 @@ macro(_qt_multitarget_suffix_ _OUT _IN _v) endmacro() -macro(qt_target_link_libraries _NAME) +macro(qad_target_link_libraries _NAME) foreach(_v ${_QT_VERSIONS_}) if (LOCAL_FOUND${_v}) set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}}) @@ -633,7 +714,7 @@ macro(qt_target_link_libraries _NAME) endmacro() -macro(qt_target_compile_definitions _NAME) +macro(qad_target_compile_definitions _NAME) foreach(_v ${_QT_VERSIONS_}) if (LOCAL_FOUND${_v}) set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}}) @@ -643,7 +724,7 @@ macro(qt_target_compile_definitions _NAME) endmacro() -macro(qt_target_include_directories _NAME) +macro(qad_target_include_directories _NAME) foreach(_v ${_QT_VERSIONS_}) if (LOCAL_FOUND${_v}) set(_TARGET ${_NAME}${TARGET_SUFFIX_Qt${_v}}) @@ -653,7 +734,7 @@ macro(qt_target_include_directories _NAME) endmacro() -macro(qt_install) +macro(qad_install) set(_prev_inst) set(__add_args) #message("command: ${ARGN}") @@ -771,7 +852,7 @@ macro(_qt_gather_deps _T _out __p) endmacro() -macro(qt_install_lang _NAME) +macro(qad_install_lang _NAME) set(_prev_inst) #message("command: ${ARGN}") set(_PATHS) @@ -849,7 +930,7 @@ macro(qt_install_lang _NAME) endmacro() -macro(qt_get_target _NAME _OUT) +macro(qad_get_target _NAME _OUT) set(${_OUT}) set(_ver) foreach(_i ${ARGN}) @@ -871,7 +952,7 @@ macro(qt_get_target _NAME _OUT) endmacro() -macro(qt_get_targets _NAME _OUT) +macro(qad_get_targets _NAME _OUT) set(${_OUT}) foreach(_v ${_QT_VERSIONS_}) if (LOCAL_FOUND${_v}) @@ -881,9 +962,9 @@ macro(qt_get_targets _NAME _OUT) endmacro() -macro(qt_generate_export_header _NAME) - qt_get_target(${_NAME} _some_target) - qt_get_target(${_NAME} _targets) +macro(qad_generate_export_header _NAME) + qad_get_target(${_NAME} _some_target) + qad_get_target(${_NAME} _targets) foreach(_t ${_targets}) set_target_properties(${_t} PROPERTIES DEFINE_SYMBOL ${_NAME}_EXPORTS) endforeach() diff --git a/libs/application/emainwindow.cpp b/libs/application/emainwindow.cpp index 4bd3da6..b398818 100644 --- a/libs/application/emainwindow.cpp +++ b/libs/application/emainwindow.cpp @@ -94,7 +94,13 @@ bool EMainWindow::eventFilter(QObject * o, QEvent * e) { if (tdocks.contains((QDockWidget*)o)) popup = popup || ((QDockWidget*)o)->titleBarWidget()->geometry().contains(((QMouseEvent*)e)->pos()); if (popup) { - createPopupMenu()->popup(((QMouseEvent*)e)->globalPos()); + createPopupMenu()->popup( +#if QT_VERSION_MAJOR <= 5 + ((QMouseEvent*)e)->globalPos() +#else + ((QMouseEvent*)e)->globalPosition().toPoint() +#endif + ); return true; } } diff --git a/libs/application/emainwindow.h b/libs/application/emainwindow.h index 2d17ae8..eefe134 100644 --- a/libs/application/emainwindow.h +++ b/libs/application/emainwindow.h @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -138,7 +137,8 @@ public slots: void newFile(); void openFile(); void openFiles(); - bool saveFile(bool ask = false); + bool saveFile(bool ask); + bool saveFile() {return saveFile(false);} bool saveAsFile(); void clearRecent(); diff --git a/libs/application/historyview.h b/libs/application/historyview.h index 5c04c17..e57bef7 100644 --- a/libs/application/historyview.h +++ b/libs/application/historyview.h @@ -79,7 +79,8 @@ public slots: void setDuplicatesEnabled(bool yes) {duplicates_ = yes;} void setLimit(int l); void setHistoryColor(const QColor & c); - void clear(bool silent = false); + void clear(bool silent); + void clear() {clear(false);} void undo(); void redo(); diff --git a/libs/blockview/alignedtextitem.cpp b/libs/blockview/alignedtextitem.cpp index b870517..805bf09 100644 --- a/libs/blockview/alignedtextitem.cpp +++ b/libs/blockview/alignedtextitem.cpp @@ -29,7 +29,7 @@ void AlignedTextItem::setFont(const QFont & f) { QFont AlignedTextItem::sceneFont(const QFont & f) { QFont ret = f; - double scl = 16. / QApplication::fontMetrics().size(0, "0").height(); + double scl = 16. / fontHeight(); ret.setPointSizeF(ret.pointSizeF() * scl); return ret; } diff --git a/libs/blockview/blockbusitem.cpp b/libs/blockview/blockbusitem.cpp index 7994276..a33ae27 100644 --- a/libs/blockview/blockbusitem.cpp +++ b/libs/blockview/blockbusitem.cpp @@ -609,9 +609,9 @@ void BlockBusItem::mousePressEvent(QGraphicsSceneMouseEvent * e) { if (endpoints().contains(selPoint)) QMetaObject::invokeMethod(scene()->views().back(), "startBusPointMove", Q_ARG(int, busType())); } - if (e->buttons().testFlag(Qt::LeftButton)) btncnt++; + if (e->buttons().testFlag(Qt::LeftButton )) btncnt++; if (e->buttons().testFlag(Qt::RightButton)) btncnt++; - if (e->buttons().testFlag(Qt::MidButton)) btncnt++; + if (e->buttons().testFlag(QT_MID_BUTTON )) btncnt++; if (btncnt > 0) mm_mods = e->modifiers(); if (btncnt >= 2 && e->button() == Qt::RightButton) { //qDebug() << "bus revert"; @@ -722,9 +722,9 @@ void BlockBusItem::mouseMoveEvent(QGraphicsSceneMouseEvent * e) { void BlockBusItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * e) { mm_mods = Qt::KeyboardModifiers(); int btncnt = 0; - if (e->buttons().testFlag(Qt::LeftButton)) btncnt++; + if (e->buttons().testFlag(Qt::LeftButton )) btncnt++; if (e->buttons().testFlag(Qt::RightButton)) btncnt++; - if (e->buttons().testFlag(Qt::MidButton)) btncnt++; + if (e->buttons().testFlag(QT_MID_BUTTON )) btncnt++; if (btncnt == 0) mm_cancel = false; if (new_segment) { QMetaObject::invokeMethod(scene()->views().back(), "newBranchAccept", Q_ARG(BlockBusItem * , this)); diff --git a/libs/blockview/blockitem.cpp b/libs/blockview/blockitem.cpp index 620bdc0..107946b 100644 --- a/libs/blockview/blockitem.cpp +++ b/libs/blockview/blockitem.cpp @@ -168,9 +168,10 @@ void BlockItem::clearPins() { void BlockItem::clearDecors() { bool pbs = false; if (scene()) pbs = scene()->blockSignals(true); - if (scene()) + if (scene()) { foreach (QGraphicsItem * i, decors_) scene()->sendEvent(i, new QGraphicsSceneEvent(QEvent::Close)); + } qDeleteAll(decors_); decors_.clear(); if (scene()) { diff --git a/libs/blockview/blockview.cpp b/libs/blockview/blockview.cpp index f5bc9a1..64e17e1 100644 --- a/libs/blockview/blockview.cpp +++ b/libs/blockview/blockview.cpp @@ -14,14 +14,6 @@ const QString _BlockView_Mime_ = "_BlockView_copypaste_"; -template QSet QList2QSet(const QList & l) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - return QSet(l.begin(), l.end()); -#else - return QSet::fromList(l); -#endif -} - BlockView::BlockView(QWidget * parent): QGraphicsView(parent), tmp_bus(true) { _init(); } @@ -218,7 +210,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) { } if (me->buttons().testFlag(Qt::LeftButton )) btncnt++; if (me->buttons().testFlag(Qt::RightButton)) btncnt++; - if (me->buttons().testFlag(Qt::MidButton )) btncnt++; + if (me->buttons().testFlag(QT_MID_BUTTON )) btncnt++; mm_cancel = btncnt >= 2; match_bus = bus_from = 0; hpin = 0; @@ -266,7 +258,7 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) { mm_drag = moved = false; screen_point = me->screenPos(); scene_point = me->scenePos(); - if ((me->button() == Qt::MidButton) || (me->button() == Qt::RightButton)) { + if ((me->button() == QT_MID_BUTTON) || (me->button() == Qt::RightButton)) { thumbShow(); restartTimer(timer_thumb, thumb_hide_delay); return true; @@ -525,10 +517,10 @@ bool BlockView::eventFilter(QObject * o, QEvent * e) { case QEvent::GraphicsSceneMouseRelease: if (me->buttons().testFlag(Qt::LeftButton)) btncnt++; if (me->buttons().testFlag(Qt::RightButton)) btncnt++; - if (me->buttons().testFlag(Qt::MidButton)) btncnt++; + if (me->buttons().testFlag(QT_MID_BUTTON)) btncnt++; cur_bus = 0; mm_cancel = btncnt > 0; - if (mm_cancel || (me->button() == Qt::MidButton) || (me->button() == Qt::RightButton)) { + if (mm_cancel || (me->button() == QT_MID_BUTTON) || (me->button() == Qt::RightButton)) { mm_ci = 0; return true; } @@ -665,19 +657,19 @@ void BlockView::timerEvent(QTimerEvent * e) { void BlockView::wheelEvent(QWheelEvent * e) { if (!navigation) return; if (wheel_zoom || e->modifiers().testFlag(Qt::ControlModifier)) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - double scl = 1. - e->angleDelta().y() / 500.; -#else +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) double scl = 1. - e->delta() / 500.; +#else + double scl = 1. - e->angleDelta().y() / 500.; #endif if (!is_nav_anim || (nav_anim.state() != QPropertyAnimation::Running)) nav_target = _nav(); QRectF r = nav_target; double vw = viewport()->width(), vh = viewport()->height(); -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - double cx = double(e->position().x()) / vw, cy = double(e->position().y()) / vh; -#else +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) double cx = double(e->pos().x()) / vw, cy = double(e->pos().y()) / vh; +#else + double cx = double(e->position().x()) / vw, cy = double(e->position().y()) / vh; #endif double pw = r.width(), ph = r.height(); r.setWidth(r.width() * scl); @@ -692,7 +684,7 @@ void BlockView::wheelEvent(QWheelEvent * e) { void BlockView::mousePressEvent(QMouseEvent * event) { press_point = event->pos(); - if (event->buttons().testFlag(Qt::MidButton) || event->buttons().testFlag(Qt::RightButton)) { + if (event->buttons().testFlag(QT_MID_BUTTON) || event->buttons().testFlag(Qt::RightButton)) { setCursor(Qt::ClosedHandCursor); //sel_rect.hide(); if (sel_rect.scene()) @@ -723,7 +715,7 @@ void BlockView::scrolled() { void BlockView::mouseMoveEvent(QMouseEvent * event) { if (!event) return; if (navigation) { - if (event->buttons().testFlag(Qt::MidButton) || event->buttons().testFlag(Qt::RightButton)) { + if (event->buttons().testFlag(QT_MID_BUTTON) || event->buttons().testFlag(Qt::RightButton)) { QPoint dp = (press_point - event->pos()); horizontalScrollBar()->setValue(horizontalScrollBar()->value() + dp.x()); verticalScrollBar()->setValue(verticalScrollBar()->value() + dp.y()); @@ -740,7 +732,7 @@ void BlockView::mouseMoveEvent(QMouseEvent * event) { void BlockView::mouseDoubleClickEvent(QMouseEvent * event) { - if (event->buttons().testFlag(Qt::MidButton) || event->buttons().testFlag(Qt::RightButton)) { + if (event->buttons().testFlag(QT_MID_BUTTON) || event->buttons().testFlag(Qt::RightButton)) { fitInView(); return; } diff --git a/libs/blockview/blockview.h b/libs/blockview/blockview.h index 78ddcd5..674feee 100644 --- a/libs/blockview/blockview.h +++ b/libs/blockview/blockview.h @@ -223,7 +223,8 @@ protected slots: void startBusPointMove(int bus_type); void endBusPointMove(); void pinHoverInOut(BlockItemPin * pin); - void checkPaste(bool queued = false); + void checkPaste(bool queued); + void checkPaste() {checkPaste(false);} public slots: void setGridPen(const QPen & pen) {grid_pen = pen; _updateBack();} diff --git a/libs/blockview/drawtools.cpp b/libs/blockview/drawtools.cpp index c3cff7b..ac2818b 100644 --- a/libs/blockview/drawtools.cpp +++ b/libs/blockview/drawtools.cpp @@ -119,7 +119,7 @@ void _DTSizeItem::doubleClick() { void _DTSizeItem::resizeHandles() { - double sz = QApplication::fontMetrics().size(0, "0").height() / 3.; + double sz = fontHeight() / 3.; QRectF r(-sz, -sz, sz*2, sz*2); for (int i = 0; i < 8; ++i) rects[i].setRect(r); @@ -235,7 +235,7 @@ actions_Z_up(this), actions_Z_top(this), actions_Z_down(this), actions_Z_bottom( ui->labelBrush->setMinimumSize(ui->labelPen->minimumSize()); ui->labelBrush->setMaximumSize(ui->labelBrush->minimumSize()); widget_props->setEnabled(false); - int fh = qMax(QApplication::fontMetrics().size(0, "0").height(), 22); + int fh = qMax(fontHeight(), 22); int thick = lineThickness(); QSize sz(fh * 2.5, fh); ui->comboLineStyle->setIconSize(sz); diff --git a/libs/doc/markdown.cpp b/libs/doc/markdown.cpp index f218633..57fee7d 100644 --- a/libs/doc/markdown.cpp +++ b/libs/doc/markdown.cpp @@ -1,4 +1,5 @@ #include "markdown.h" +#include #include #ifndef NO_MARKDOWN extern "C" { diff --git a/libs/graphic/CMakeLists.txt b/libs/graphic/CMakeLists.txt index 83be8b6..8ef4b88 100644 --- a/libs/graphic/CMakeLists.txt +++ b/libs/graphic/CMakeLists.txt @@ -1 +1 @@ -qad_library(graphic "Gui;Widgets;OpenGL" "qad_widgets;${OPENGL_LIBRARIES}") +qad_library(graphic "Gui;Widgets;OpenGL;OpenGLWidgets" "qad_widgets;${OPENGL_LIBRARIES}") diff --git a/libs/graphic/graphic.cpp b/libs/graphic/graphic.cpp index d49ee70..dad4a7b 100644 --- a/libs/graphic/graphic.cpp +++ b/libs/graphic/graphic.cpp @@ -212,10 +212,20 @@ bool Graphic::eventFilter(QObject * o, QEvent * e) { break; case QEvent::TouchUpdate: { if (!navigation || !gestures) break; - QList tpl = ((QTouchEvent*)e)->touchPoints(); + QList tpl = +#if QT_VERSION_MAJOR <= 5 + ((QTouchEvent*)e)->touchPoints(); +#else + ((QTouchEvent*)e)->points(); +#endif if (tpl.size() == 2) { need_mouse_pan = false; - QPointF dp = tpl[0].scenePos() - tpl[1].scenePos(); + QPointF dp = +#if QT_VERSION_MAJOR <= 5 + tpl[0].scenePos() - tpl[1].scenePos(); +#else + tpl[0].scenePosition() - tpl[1].scenePosition(); +#endif gesture_angle = rad2deg_qpie * qAtan2(qAbs(dp.y()), qAbs(dp.x())); } } break; @@ -432,7 +442,7 @@ void Graphic::canvasMousePressEvent(QMouseEvent * e) { startpos = prevpos; startpos_r = canvas2real(startpos); if (cancel || gestures) return; - if (e->button() == Qt::MidButton) curaction = gaMove; + if (e->button() == QT_MID_BUTTON) curaction = gaMove; if (e->button() == Qt::RightButton) { if (bufferActive) { curpos = startpos; @@ -700,6 +710,7 @@ void Graphic::setButtons(Graphic::Buttons b) { ui->graphic_buttonClear->setVisible(b.testFlag(Clear)); ui->graphic_buttonConfigure->setVisible(b.testFlag(Configure)); ui->graphic_buttonSave->setVisible(b.testFlag(Save)); + ui->graphic_buttonExport->setVisible(b.testFlag(Export)); ui->graphic_buttonClose->setVisible(b.testFlag(Close)); ui->graphic_checkPause->setVisible(b.testFlag(Pause)); if (ui->graphic_buttonAutofit ->isVisible() || ui->graphic_checkGrid ->isVisible() || ui->graphic_checkGuides->isVisible() || @@ -793,10 +804,8 @@ void Graphic::setDefaultRect(const QRectF & rect) { } -void Graphic::saveImage() { - QString str = QFileDialog::getSaveFileName(this, tr("Save Image"), ppath, "PNG(*.png);;JPEG(*.jpg *.jpeg);;BMP(*.bmp);;TIFF(*.tiff *.tif);;PPM(*.ppm)"); - if (str == "") return; - ppath = str; +void Graphic::saveImage(QString filename) { + ppath = filename; QPixmap im(canvas->size()); canvas->render(&im); im.save(ppath); @@ -804,6 +813,50 @@ void Graphic::saveImage() { } +void Graphic::exportGraphics(QString filename) { + ppath = filename; + QFile f(filename); + if (!f.open(QIODevice::ReadWrite)) { + QMessageBox::critical(this, tr("Export graphics"), tr("Can`t open file \"%1\"!").arg(filename)); + return; + } + f.resize(0); + QTextStream ts(&f); + ts << "#"; + for (int i = 0; i < graphics.size(); ++i) { + GraphicType & g(graphics[i]); + if (!g.visible) continue; + ts << ";" << (g.name + "_X") << ";" << (g.name + "_Y"); + } + ts << "\n"; + bool has_data = true; + int ind = 0; + QString line; + while (has_data) { + has_data = false; + line.clear(); + line += QString::number(ind + 1); + for (int i = 0; i < graphics.size(); ++i) { + GraphicType & g(graphics[i]); + if (!g.visible) continue; + if (ind >= g.polyline.size()) { + line += ";;"; + continue; + } + has_data = true; + line += ";"; + line += QString::number(g.polyline[ind].x(), 'g', 9); + line += ";"; + line += QString::number(g.polyline[ind].y(), 'g', 9); + } + ++ind; + line += "\n"; + if (has_data) + ts << line; + } +} + + void Graphic::setOpenGL(bool on) { #ifdef HAS_GL isOGL = on; @@ -1546,6 +1599,20 @@ void Graphic::on_graphic_buttonConfigure_clicked() { } +void Graphic::on_graphic_buttonSave_clicked() { + QString f = QFileDialog::getSaveFileName(this, tr("Save Image"), ppath, "PNG(*.png);;JPEG(*.jpg *.jpeg);;BMP(*.bmp);;TIFF(*.tiff *.tif);;PPM(*.ppm)"); + if (f.isEmpty()) return; + saveImage(f); +} + + +void Graphic::on_graphic_buttonExport_clicked() { + QString f = QFileDialog::getSaveFileName(this, tr("Export graphics"), ppath, "CSV(*.csv)"); + if (f.isEmpty()) return; + exportGraphics(f); +} + + void Graphic::on_graphic_checkGuides_toggled(bool checked) { guides = checked; setGuidesCursor(); diff --git a/libs/graphic/graphic.h b/libs/graphic/graphic.h index 7277244..64ececc 100644 --- a/libs/graphic/graphic.h +++ b/libs/graphic/graphic.h @@ -124,19 +124,20 @@ public: typedef QVector > GraphicsData; enum GraphicAction {gaNone, gaZoomInRect, gaZoomRangeX, gaZoomRangeY, gaMove}; - enum Button {NoButtons = 0x0, - AllButtons = 0xFFFFFFFF, - Autofit = 0x01, - Grid = 0x02, - CursorAxis = 0x04, - Fullscreen = 0x20, + enum Button {NoButtons = 0x0, + AllButtons = 0xFFFFFFFF, + Autofit = 0x01, + Grid = 0x02, + CursorAxis = 0x04, + Fullscreen = 0x20, BorderInputs = 0x40, - Legend = 0x80, - Configure = 0x100, - Save = 0x200, - Clear = 0x800, - Close = 0x1000, - Pause = 0x2000, + Legend = 0x80, + Configure = 0x100, + Save = 0x200, + Export = 0x400, + Clear = 0x800, + Close = 0x1000, + Pause = 0x2000, StandartButtons = 0x2FFF }; enum Alignment {Left, Right}; @@ -314,9 +315,11 @@ public slots: void setVisualRect(const QRectF & rect); void setDefaultRect(const QRectF & rect); void autofit() {on_graphic_buttonAutofit_clicked();} - void saveImage(); + void saveImage(QString filename); + void exportGraphics(QString filename); void clear(); - void update(bool force = false); + void update(bool force); + void update() {update(false);} void updateGraphics() {findGraphicsRect(); update();} void setCurrentGraphic(int arg) {if (arg < 0 || arg >= graphics.size()) return; curGraphic = arg;} void setTraceGraphic(int arg) {if (arg < 0 || arg >= graphics.size()) return; curTrace = arg;} @@ -421,7 +424,8 @@ protected slots: void on_graphic_buttonAutofit_clicked(); void on_graphic_buttonConfigure_clicked(); void on_graphic_buttonFullscreen_clicked() {fullscreen();} - void on_graphic_buttonSave_clicked() {saveImage();} + void on_graphic_buttonSave_clicked(); + void on_graphic_buttonExport_clicked(); void on_graphic_checkGrid_toggled(bool checked) {grid = checked; update();} void on_graphic_checkGuides_toggled(bool checked); void on_graphic_actionExpandX_triggered(bool checked); @@ -462,7 +466,9 @@ public: __GraphicRegistrator__() { qRegisterMetaType >("QVector"); qRegisterMetaType("Graphic::GraphicsData"); +#if QT_VERSION_MAJOR <= 5 qRegisterMetaTypeStreamOperators("Graphic::GraphicsData"); +#endif } }; diff --git a/libs/graphic/graphic.ui b/libs/graphic/graphic.ui index 0d00a0f..5cc6b8a 100644 --- a/libs/graphic/graphic.ui +++ b/libs/graphic/graphic.ui @@ -6,8 +6,8 @@ 0 0 - 564 - 484 + 575 + 440 @@ -180,6 +180,17 @@ + + + + Export graphics ... + + + + :/icons/document-edit.png:/icons/document-edit.png + + + diff --git a/libs/graphic/uwidget.h b/libs/graphic/uwidget.h index 1c61ad2..6c6b44c 100644 --- a/libs/graphic/uwidget.h +++ b/libs/graphic/uwidget.h @@ -20,7 +20,11 @@ private: if (e->type() != QEvent::Paint) return QWidget::event(e); e->accept(); QStyleOption opt; +#if QT_VERSION_MAJOR <= 5 opt.init(this); +#else + opt.initFrom(this); +#endif QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); emit paintEvent((QPaintEvent * )e); diff --git a/libs/piqt/piqt.cpp b/libs/piqt/piqt.cpp index 403310e..7ef4d1e 100644 --- a/libs/piqt/piqt.cpp +++ b/libs/piqt/piqt.cpp @@ -1,8 +1,5 @@ #include "piqt.h" #include "qvariantedit.h" -#if QT_VERSION >= 0x050200 -# include -#endif const QAD::Enum PI2QADEnum(const PIVariantTypes::Enum & el) { @@ -60,24 +57,105 @@ const QVariant PI2QVariant(const PIVariant & v) { const PIVariant Q2PIVariant(const QVariant & v) { +#if QT_VERSION_MAJOR <= 5 switch (v.type()) { - case QVariant::Bool: return PIVariant(v.toBool()); - case QVariant::Int: return PIVariant(v.toInt()); - case QVariant::UInt: return PIVariant(v.toUInt()); - case QVariant::LongLong: return PIVariant(v.toLongLong()); - case QVariant::ULongLong: return PIVariant(v.toULongLong()); - case QVariant::Double: return PIVariant(v.toDouble()); - case QVariant::ByteArray: return PIVariant(Q2PIByteArray(v.toByteArray())); - case QVariant::String: return PIVariant(Q2PIString(v.toString())); - case QVariant::StringList: return PIVariant(Q2PIStringList(v.toStringList())); - case QVariant::Time: return PIVariant(Q2PITime(v.toTime())); - case QVariant::Date: return PIVariant(Q2PIDate(v.toDate())); - case QVariant::DateTime: return PIVariant(Q2PIDateTime(v.toDateTime())); - case QVariant::Color: return PIVariant(Q2PIColor(v.value())); +#else + switch (v.metaType().id()) { +#endif +#if QT_VERSION_MAJOR <= 5 + case QVariant::Bool: +#else + case QMetaType::Bool: +#endif + return PIVariant(v.toBool()); +#if QT_VERSION_MAJOR <= 5 + case QVariant::Int: +#else + case QMetaType::Int: +#endif + return PIVariant(v.toInt()); +#if QT_VERSION_MAJOR <= 5 + case QVariant::UInt: +#else + case QMetaType::UInt: +#endif + return PIVariant(v.toUInt()); +#if QT_VERSION_MAJOR <= 5 + case QVariant::LongLong: +#else + case QMetaType::LongLong: +#endif + return PIVariant(v.toLongLong()); +#if QT_VERSION_MAJOR <= 5 + case QVariant::ULongLong: +#else + case QMetaType::ULongLong: +#endif + return PIVariant(v.toULongLong()); +#if QT_VERSION_MAJOR <= 5 + case QVariant::Double: +#else + case QMetaType::Double: +#endif + return PIVariant(v.toDouble()); +#if QT_VERSION_MAJOR <= 5 + case QVariant::ByteArray: +#else + case QMetaType::QByteArray: +#endif + return PIVariant(Q2PIByteArray(v.toByteArray())); +#if QT_VERSION_MAJOR <= 5 + case QVariant::String: +#else + case QMetaType::QString: +#endif + return PIVariant(Q2PIString(v.toString())); +#if QT_VERSION_MAJOR <= 5 + case QVariant::StringList: +#else + case QMetaType::QStringList: +#endif + return PIVariant(Q2PIStringList(v.toStringList())); +#if QT_VERSION_MAJOR <= 5 + case QVariant::Time: +#else + case QMetaType::QTime: +#endif + return PIVariant(Q2PITime(v.toTime())); +#if QT_VERSION_MAJOR <= 5 + case QVariant::Date: +#else + case QMetaType::QDate: +#endif + return PIVariant(Q2PIDate(v.toDate())); +#if QT_VERSION_MAJOR <= 5 + case QVariant::DateTime: +#else + case QMetaType::QDateTime: +#endif + return PIVariant(Q2PIDateTime(v.toDateTime())); +#if QT_VERSION_MAJOR <= 5 + case QVariant::Color: +#else + case QMetaType::QColor: +#endif + return PIVariant(Q2PIColor(v.value())); +#if QT_VERSION_MAJOR <= 5 case QVariant::Point: - case QVariant::PointF: return PIVariant(Q2PIPoint(v.toPointF())); + case QVariant::PointF: +#else + case QMetaType::QPoint: + case QMetaType::QPointF: +#endif + return PIVariant(Q2PIPoint(v.toPointF())); +#if QT_VERSION_MAJOR <= 5 case QVariant::Rect: - case QVariant::RectF: return PIVariant(Q2PIRect(v.toRectF())); + case QVariant::RectF: +#else + case QMetaType::QRect: + case QMetaType::QRectF: +#endif + return PIVariant(Q2PIRect(v.toRectF())); default: break; } if (v.canConvert()) return PIVariant(v.value()); @@ -126,7 +204,7 @@ const PIVariantTypes::Dir QAD2PIDir(const QAD::Dir & v) { } -#if QT_VERSION >= 0x050200 +#ifdef PIQT_HAS_GEOPOSITION const QGeoCoordinate PI2QGeoPosition(const PIGeoPosition & v) { PIGeoPosition p(v); p.transformTo(PIGeoPosition::Cartesian); diff --git a/libs/piqt/piqt.h b/libs/piqt/piqt.h index 7454f59..dd0e5b6 100644 --- a/libs/piqt/piqt.h +++ b/libs/piqt/piqt.h @@ -20,16 +20,28 @@ #ifndef PIQT_H #define PIQT_H -#include "pimathmatrix.h" -#include "pipropertystorage.h" -#include "qad_types.h" #include #include #include -#if QT_VERSION >= 0x050200 + +#include "pimathmatrix.h" +#include "pipropertystorage.h" +#include "qad_types.h" +#include "piqt_macros.h" +#if QT_VERSION_MAJOR == 5 +# if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) +# define PIQT_HAS_GEOPOSITION +# endif +#endif +#if QT_VERSION_MAJOR == 6 +# if QT_VERSION >= QT_VERSION_CHECK(6, 1, 0) +# define PIQT_HAS_GEOPOSITION +# endif +#endif +#ifdef PIQT_HAS_GEOPOSITION +# include # include "pigeoposition.h" #endif -#include "piqt_macros.h" #include "qad_piqt_export.h" @@ -137,7 +149,7 @@ QAD_PIQT_EXPORT const PIVariantTypes::IODevice QAD2PIIODevice(const QAD::IODevic //inline const PIVariant QString2PIVariant(const QString & v) {return PIVariant::readFromString(QString2PIString(v));} -#if QT_VERSION >= 0x050200 +#ifdef PIQT_HAS_GEOPOSITION QAD_PIQT_EXPORT const QGeoCoordinate PI2QGeoPosition(const PIGeoPosition & v); QAD_PIQT_EXPORT const PIGeoPosition Q2PIGeoPosition(const QGeoCoordinate & v); #endif diff --git a/libs/piqt/piqt_macros.h b/libs/piqt/piqt_macros.h index 623d286..86a0e27 100644 --- a/libs/piqt/piqt_macros.h +++ b/libs/piqt/piqt_macros.h @@ -47,7 +47,14 @@ namespace PIQt { template T removePtr(T*) {} -template QArgument qargument(const T & v) {return QArgument(QMetaType::typeName(qMetaTypeId()), v);} +template QArgument qargument(const T & v) { + return QArgument( +#if QT_VERSION_MAJOR <= 5 + QMetaType::typeName(qMetaTypeId()) +#else + QMetaType::fromType().name() +#endif + , v);} template void piqConnect(PIObject * source, const char * event, void(*func)(void*,ARGS...), O * target, SR(O::*slot)(ARGS...)) { diff --git a/libs/piqt_widgets/piqt_highlighter.cpp b/libs/piqt_widgets/piqt_highlighter.cpp index 8e6ae64..da94d1d 100644 --- a/libs/piqt_widgets/piqt_highlighter.cpp +++ b/libs/piqt_widgets/piqt_highlighter.cpp @@ -5,39 +5,38 @@ ConfigHighlighter::ConfigHighlighter(QTextDocument * parent): QSyntaxHighlighter HighlightingRule rule; valueNameFormat.setForeground(QColor(0, 64, 154)); - rule.pattern = QRegExp("[^=]"); //"\\b[A-Za-z0-9_]+(?=\\()"); + rule.pattern = QRegularExpression("[^=]"); //"\\b[A-Za-z0-9_]+(?=\\()"); rule.format = valueNameFormat; highlightingRules.append(rule); valueFormat.setForeground(QColor(192, 0, 0)); - rule.pattern = QRegExp("=[^\n]*"); + rule.pattern = QRegularExpression("=[^\n]*"); rule.format = valueFormat; highlightingRules.append(rule); equalFormat.setFontWeight(QFont::Bold); equalFormat.setForeground(QColor(96, 126, 0)); - rule.pattern = QRegExp("="); + rule.pattern = QRegularExpression("="); rule.format = equalFormat; highlightingRules.append(rule); sectionFormat.setFontWeight(QFont::Bold); sectionFormat.setForeground(QColor(0, 32, 64)); - rule.pattern = QRegExp("\\[.*\\]"); + rule.pattern = QRegularExpression("\\[.*\\]"); rule.format = sectionFormat; highlightingRules.append(rule); - //substFormat.setFontWeight(QFont::Bold); substFormat.setForeground(QColor(192, 0, 192)); - rule.pattern = QRegExp("\\$\\{.*\\}+"); - rule.pattern.setMinimal(true); + rule.pattern = QRegularExpression("\\$\\{.*\\}+"); + //rule.pattern.setMinimal(true); rule.format = substFormat; highlightingRules.append(rule); - rule.pattern = QRegExp("\\$\\{[^\\{]*\\}+"); + rule.pattern = QRegularExpression("\\$\\{[^\\{]*\\}+"); highlightingRules.append(rule); singleLineCommentFormat.setFontItalic(true); singleLineCommentFormat.setForeground(QColor(128, 128, 128)); - rule.pattern = QRegExp("#[^\n]*"); + rule.pattern = QRegularExpression("#[^\n]*"); rule.format = singleLineCommentFormat; highlightingRules.append(rule); @@ -50,21 +49,37 @@ ConfigHighlighter::ConfigHighlighter(QTextDocument * parent): QSyntaxHighlighter void ConfigHighlighter::highlightBlock(const QString & text) { foreach (const HighlightingRule &rule, highlightingRules) { - QRegExp expression(rule.pattern); + QRegularExpression expression(rule.pattern); +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + QRegularExpressionMatchIterator i = expression.globalMatch(text); + while (i.hasNext()) { + QRegularExpressionMatch match = i.next(); + setFormat(match.capturedStart(), match.capturedLength(), rule.format); + } +#else int index = expression.indexIn(text); while (index >= 0) { int length = expression.matchedLength(); setFormat(index, length, rule.format); index = expression.indexIn(text, index + length); } +#endif } setCurrentBlockState(0); - QRegExp expression = QRegExp("[ |\t]"); + QRegularExpression expression("[ |\t]"); +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + QRegularExpressionMatchIterator i = expression.globalMatch(text); + while (i.hasNext()) { + QRegularExpressionMatch match = i.next(); + setFormat(match.capturedStart(), match.capturedLength(), spaceFormat); + } +#else int index = expression.indexIn(text); while (index >= 0) { int length = expression.matchedLength(); setFormat(index, length, spaceFormat); index = expression.indexIn(text, index + length); } +#endif } diff --git a/libs/piqt_widgets/piqt_highlighter.h b/libs/piqt_widgets/piqt_highlighter.h index bb49352..557ced3 100644 --- a/libs/piqt_widgets/piqt_highlighter.h +++ b/libs/piqt_widgets/piqt_highlighter.h @@ -23,6 +23,12 @@ #include #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) +# include +#else +# include + typedef QRegExp QRegularExpression; +#endif #include "qad_piqt_utils_export.h" class QTextDocument; @@ -39,12 +45,12 @@ private: void highlightBlock(const QString &text); struct QAD_PIQT_UTILS_EXPORT HighlightingRule { - QRegExp pattern; + QRegularExpression pattern; QTextCharFormat format; }; QVector highlightingRules; - QRegExp commentStartExpression, commentEndExpression; + QRegularExpression commentStartExpression, commentEndExpression; QTextCharFormat singleLineCommentFormat, valueNameFormat, valueFormat, equalFormat, sectionFormat, spaceFormat, substFormat; }; diff --git a/libs/qglview/CMakeLists.txt b/libs/qglview/CMakeLists.txt index 7f2be50..d12965a 100644 --- a/libs/qglview/CMakeLists.txt +++ b/libs/qglview/CMakeLists.txt @@ -1,10 +1,10 @@ if (((DEFINED QGLVIEW) AND QGLVIEW) OR (NOT DEFINED QGLVIEW)) find_package(OpenGL REQUIRED) - shstk_qt_project(qglview FALSE "qad" "Gui;OpenGL;Xml" "qad_widgets;qad_utils;${OPENGL_LIBRARIES}") - shstk_qt_install("qad" FALSE qglview "${out_HDR}" "${out_QM}") + shstk_qad_project(qglview FALSE "qad" "Gui;OpenGL;Xml" "qad_widgets;qad_utils;${OPENGL_LIBRARIES}") + shstk_qad_install("qad" FALSE qglview "${out_HDR}" "${out_QM}") - qt_sources(test_SRC DIR "qglview_test") - qt_wrap(${test_SRC} CPPS test_CPP) - qt_add_executable(qglview_test test_CPP) - qt_target_link_libraries(qglview_test qglview) + qad_sources(test_SRC DIR "qglview_test") + qad_wrap(${test_SRC} CPPS test_CPP) + qad_add_executable(qglview_test test_CPP) + qad_target_link_libraries(qglview_test qglview) endif() diff --git a/libs/qglview/plugin/CMakeLists.txt b/libs/qglview/plugin/CMakeLists.txt index 0108b63..6a931fb 100644 --- a/libs/qglview/plugin/CMakeLists.txt +++ b/libs/qglview/plugin/CMakeLists.txt @@ -1 +1 @@ -shstk_qt_plugin(qglview "Gui;Widgets;OpenGL" "qglview") +shstk_qad_plugin(qglview "Gui;Widgets;OpenGL" "qglview") diff --git a/libs/sql_table/sql_table_widget.h b/libs/sql_table/sql_table_widget.h index eab42e5..024852b 100644 --- a/libs/sql_table/sql_table_widget.h +++ b/libs/sql_table/sql_table_widget.h @@ -45,6 +45,7 @@ #include #include #include +#include #include "qpiconfig.h" #include "qad_sql_table_export.h" diff --git a/libs/utils/propertystorage.cpp b/libs/utils/propertystorage.cpp index 8e8a0de..ef9ef1a 100644 --- a/libs/utils/propertystorage.cpp +++ b/libs/utils/propertystorage.cpp @@ -150,6 +150,7 @@ PropertyStorage::Property PropertyStorage::parsePropertyLine(QString l) { ret.value = QVariant(typeFromLetter(pt)); if (!pv.isEmpty()) { //qDebug() << "set value !" << pv; +#if QT_VERSION_MAJOR <= 5 switch (ret.value.type()) { case QVariant::Bool: pv = pv.toLower(); ret.value = (pv == "on" || pv == "true" || pv == "enable" || pv == "enabled" || pv.toInt() > 0 ? true : false); break; case QVariant::Int: ret.value = pv.toInt(); break; @@ -160,6 +161,18 @@ PropertyStorage::Property PropertyStorage::parsePropertyLine(QString l) { case QVariant::Color: ret.value = QColor(pv); break; default: ret.value = pv; break; }; +#else + switch (ret.value.metaType().id()) { + case QMetaType::Bool: pv = pv.toLower(); ret.value = (pv == "on" || pv == "true" || pv == "enable" || pv == "enabled" || pv.toInt() > 0 ? true : false); break; + case QMetaType::Int: ret.value = pv.toInt(); break; + case QMetaType::UInt: ret.value = pv.toUInt(); break; + case QMetaType::LongLong: ret.value = pv.toLongLong(); break; + case QMetaType::ULongLong: ret.value = pv.toULongLong(); break; + case QMetaType::Double: ret.value = pv.toDouble(); break; + case QMetaType::QColor: ret.value = QColor(pv); break; + default: ret.value = pv; break; + }; +#endif } return ret; } diff --git a/libs/utils/propertystorage.h b/libs/utils/propertystorage.h index c14c8ae..643a3bf 100644 --- a/libs/utils/propertystorage.h +++ b/libs/utils/propertystorage.h @@ -115,9 +115,6 @@ protected: inline QDebug operator <<(QDebug s, const PropertyStorage::Property & p) {s.nospace() << p.name << " (0x" << QString::number(p.flags, 16) << ") = " << p.value; return s.space();} -inline QDataStream & operator <<(QDataStream & s, const PropertyStorage & p) {s << p.properties(); return s;} -inline QDataStream & operator >>(QDataStream & s, PropertyStorage & p) {s >> p.properties(); return s;} - inline QDataStream & operator <<(QDataStream & s, const PropertyStorage::Property & p) { ChunkStream cs; cs << cs.chunk(1, p.name) << cs.chunk(2, p.comment) << cs.chunk(3, p.value) << cs.chunk(4, p.flags); @@ -137,5 +134,8 @@ inline QDataStream & operator >>(QDataStream & s, PropertyStorage::Property & p) return s; } +inline QDataStream & operator <<(QDataStream & s, const PropertyStorage & p) {s << p.properties(); return s;} +inline QDataStream & operator >>(QDataStream & s, PropertyStorage & p) {s >> p.properties(); return s;} + #endif // PROPERTYSTORAGE_H diff --git a/libs/utils/qad_types.cpp b/libs/utils/qad_types.cpp index 6000da0..3428331 100644 --- a/libs/utils/qad_types.cpp +++ b/libs/utils/qad_types.cpp @@ -26,25 +26,22 @@ __QADTypesRegistrator__::__QADTypesRegistrator__() { _inited = true; qRegisterMetaType("QAD::Enumerator"); - qRegisterMetaTypeStreamOperators("QAD::Enumerator"); - qRegisterMetaType("QAD::Enum"); - qRegisterMetaTypeStreamOperators("QAD::Enum"); - qRegisterMetaType("QAD::File"); - qRegisterMetaTypeStreamOperators("QAD::File"); - qRegisterMetaType("QAD::Dir"); - qRegisterMetaTypeStreamOperators("QAD::Dir"); - qRegisterMetaType("QAD::IODevice"); - qRegisterMetaTypeStreamOperators("QAD::IODevice"); - qRegisterMetaType("QAD::MathVector"); - qRegisterMetaTypeStreamOperators("QAD::MathVector"); - qRegisterMetaType("QAD::MathMatrix"); + +#if QT_VERSION_MAJOR <= 5 + qRegisterMetaTypeStreamOperators("QAD::Enumerator"); + qRegisterMetaTypeStreamOperators("QAD::Enum"); + qRegisterMetaTypeStreamOperators("QAD::File"); + qRegisterMetaTypeStreamOperators("QAD::Dir"); + qRegisterMetaTypeStreamOperators("QAD::IODevice"); + qRegisterMetaTypeStreamOperators("QAD::MathVector"); qRegisterMetaTypeStreamOperators("QAD::MathMatrix"); +#endif #if QT_VERSION >= 0x050200 QMetaType::registerConverter(&QAD::Enum::selectedValue); @@ -185,7 +182,13 @@ QString QAD::IODevice::toString() const { -QVariant::Type typeFromLetter(const QString & l) { +#if QT_VERSION_MAJOR <= 5 +QVariant::Type +#else +QMetaType +#endif + typeFromLetter(const QString & l) { +#if QT_VERSION_MAJOR <= 5 if (l.isEmpty()) return QVariant::String; QString ft = l.left(1); if (ft == "l") return QVariant::StringList; @@ -204,6 +207,26 @@ QVariant::Type typeFromLetter(const QString & l) { if (ft == "V") return (QVariant::Type)qMetaTypeId(); if (ft == "M") return (QVariant::Type)qMetaTypeId(); return QVariant::String; +#else + if (l.isEmpty()) return QMetaType::fromType(); + QString ft = l.left(1); + if (ft == "l") return QMetaType::fromType(); + if (ft == "b") return QMetaType::fromType(); + if (ft == "n") return QMetaType::fromType(); + if (ft == "f") return QMetaType::fromType(); + if (ft == "c") return QMetaType::fromType(); + if (ft == "r") return QMetaType::fromType(); + if (ft == "a") return QMetaType::fromType(); + if (ft == "p") return QMetaType::fromType(); + if (ft == "v") return QMetaType::fromType(); + if (ft == "e") return QMetaType::fromType(); + if (ft == "F") return QMetaType::fromType(); + if (ft == "D") return QMetaType::fromType(); + if (ft == "d") return QMetaType::fromType(); + if (ft == "V") return QMetaType::fromType(); + if (ft == "M") return QMetaType::fromType(); + return QMetaType::fromType(); +#endif } @@ -252,7 +275,11 @@ int fontHeight(const QWidget * w) { } # endif #endif +#if QT_VERSION_MAJOR <= 5 return QApplication::fontMetrics().size(0, "0").height(); +#else + return QFontMetricsF(QApplication::font()).size(0, "0").height(); +#endif } @@ -276,3 +303,10 @@ QSize preferredIconSize(float x, const QWidget * w) { double appScale(const QWidget * w) { return qMax(fontHeight(w) / 15., 1.); } + + +void enableHighDPI() { +#if QT_VERSION_MAJOR == 5 + QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true); +#endif +} diff --git a/libs/utils/qad_types.h b/libs/utils/qad_types.h index 9de13b4..b193370 100644 --- a/libs/utils/qad_types.h +++ b/libs/utils/qad_types.h @@ -20,7 +20,7 @@ #ifndef QAD_TYPES_H #define QAD_TYPES_H -#include +#include #include "propertystorage.h" #include "qad_utils_export.h" @@ -31,6 +31,16 @@ QCoreApplication::setOrganizationName(__TARGET_COMPANY__); \ QCoreApplication::setApplicationVersion(__TARGET_VERSION__); +#if QT_VERSION_MAJOR <= 5 +# define QT_MID_BUTTON Qt::MidButton +# include +template +using QMultiMapIterator = QMapIterator; +#else +# define QT_MID_BUTTON Qt::MiddleButton +#endif + + class QMetaEnum; @@ -167,13 +177,47 @@ inline QRectF enlargedRect(const QRectF & r, qreal dx, qreal dy, qreal v) { return QRectF(r.left() - v + dx, r.top() - v + dy, r.width() + v+v, r.height() + v+v); } -QAD_UTILS_EXPORT QVariant::Type typeFromLetter(const QString & l); +template QSet QList2QSet(const QList & l) { +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + return QSet(l.begin(), l.end()); +#else + return QSet::fromList(l); +#endif +} + +template +void addToMap(QMap & into, const QMap & what) { + QMapIterator it(what); + while (it.hasNext()) { + it.next(); + if (!into.contains(it.key())) + into[it.key()] = it.value(); + } +} + +template +void addToMapOverwrite(QMap & into, const QMap & what) { + QMapIterator it(what); + while (it.hasNext()) { + it.next(); + into[it.key()] = it.value(); + } +} + +QAD_UTILS_EXPORT +#if QT_VERSION_MAJOR <= 5 + QVariant::Type +#else + QMetaType +#endif + typeFromLetter(const QString & l); QAD_UTILS_EXPORT QString uniqueName(QString n, const QStringList & names); QAD_UTILS_EXPORT int fontHeight(const QWidget * w = 0); QAD_UTILS_EXPORT int lineThickness(const QWidget * w = 0); QAD_UTILS_EXPORT QSize preferredIconSize(float x = 1.f, const QWidget * w = 0); QAD_UTILS_EXPORT double appScale(const QWidget * w = 0); +QAD_UTILS_EXPORT void enableHighDPI(); #endif // QAD_TYPES_H diff --git a/libs/utils/qpiconfig.cpp b/libs/utils/qpiconfig.cpp index 1a8b05a..a6d3f80 100644 --- a/libs/utils/qpiconfig.cpp +++ b/libs/utils/qpiconfig.cpp @@ -303,6 +303,9 @@ QPIConfig::QPIConfig(const QString & path, QStringList dirs) { return; } dev->close(); +#if QT_VERSION_MAJOR > 5 + stream.setEncoding(QStringConverter::Utf8); +#endif setFileName(cp); open(QIODevice::ReadOnly); parse(); @@ -347,7 +350,15 @@ void QPIConfig::setString(QString * str) { void QPIConfig::setCodec(const char * codecName) { codec = codecName; +#if QT_VERSION_MAJOR <= 5 stream.setCodec(codecName); +#else + QString cn = QString(codecName).toLower().remove(' ').remove('-').trimmed(); + QStringConverter::Encoding sc = QStringConverter::System; + if (cn == "utf8" ) sc = QStringConverter::Utf8 ; + else if (cn == "utf16") sc = QStringConverter::Utf16; + stream.setEncoding(sc); +#endif parse(); } @@ -770,8 +781,10 @@ void QPIConfig::parse(QString content) { stream.seek(0); other.clear(); lines = centry = 0; +#if QT_VERSION_MAJOR <= 5 if (!codec.isEmpty()) stream.setCodec(codec.toLatin1().data()); +#endif while (!stream.atEnd()) { other.push_back(QString()); src = str = parseLine(stream.readLine()); diff --git a/libs/widgets/ecombobox.cpp b/libs/widgets/ecombobox.cpp index 546dfc6..c8125ab 100644 --- a/libs/widgets/ecombobox.cpp +++ b/libs/widgets/ecombobox.cpp @@ -106,7 +106,13 @@ void EComboBox::filterChanged(const QString & text, bool first) { return; } for (int i = 0; i < iv.model()->rowCount(); ++i) { - iv.setRowHidden(i, pi, !iv.model()->index(i, 0, pi).data().toString().contains(QRegExp(text, Qt::CaseInsensitive))); + iv.setRowHidden(i, pi, !iv.model()->index(i, 0, pi).data().toString().contains( + #if QT_VERSION_MAJOR <= 5 + QRegExp(text, Qt::CaseInsensitive) + #else + QRegularExpression(text, QRegularExpression::CaseInsensitiveOption) + #endif + )); iv.model()->setData(iv.model()->index(i, 0), iv.model()->index(i, 0, pi).data().toString(), Qt::ToolTipRole); } iv.show(); diff --git a/libs/widgets/evalspinbox.cpp b/libs/widgets/evalspinbox.cpp index 6c8197e..b0ad5bb 100644 --- a/libs/widgets/evalspinbox.cpp +++ b/libs/widgets/evalspinbox.cpp @@ -2,7 +2,11 @@ #include #include #include -#include +#if QT_VERSION_MAJOR <= 5 +# include +#else +# include +#endif #include #include #include @@ -292,7 +296,13 @@ void EvalSpinBox::focusOutEvent(QFocusEvent * event) { void EvalSpinBox::wheelEvent(QWheelEvent * event) { if (event->modifiers().testFlag(Qt::ShiftModifier)) - stepByDouble(event->delta() > 0 ? 0.1 : -0.1); + stepByDouble( +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) + event->delta() +#else + event->angleDelta().y() +#endif + > 0 ? 0.1 : -0.1); else QAbstractSpinBox::wheelEvent(event); } @@ -304,8 +314,8 @@ void EvalSpinBox::stepByDouble(double steps) { QString t = text(); if (eval->check(t)) { t = eval->expression(); - //QRegExp re("(\\-?\\d+)"); - QRegExp re("[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)"); +#if QT_VERSION_MAJOR <= 5 +/* QRegExp re("[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)"); int pos = 0; if ((pos = re.indexIn(t)) != -1) { double v = t.mid(pos, re.matchedLength()).toDouble(); @@ -316,6 +326,10 @@ void EvalSpinBox::stepByDouble(double steps) { double v = steps; t = QString::number(v) + t; } +#else*/ + QRegularExpression re("[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)"); + /// TODO andrey +#endif eval->check(t); lineEdit()->setText(eval->expression()); } diff --git a/libs/widgets/qcodeedit.cpp b/libs/widgets/qcodeedit.cpp index 6cfd349..3e63623 100644 --- a/libs/widgets/qcodeedit.cpp +++ b/libs/widgets/qcodeedit.cpp @@ -482,7 +482,13 @@ bool QCodeEdit::eventFilter(QObject * o, QEvent * e) { break; case QEvent::DragMove: if (!isEnabled()) break; - drag_cursor = ui->textCode->cursorForPosition(((QDragMoveEvent*)e)->pos()); + drag_cursor = ui->textCode->cursorForPosition( +#if QT_VERSION_MAJOR <= 5 + ((QDragMoveEvent*)e)->pos() +#else + ((QDragMoveEvent*)e)->position().toPoint() +#endif + ); repaintCursor(); break; case QEvent::MouseButtonRelease: diff --git a/libs/widgets/qcodeedit.h b/libs/widgets/qcodeedit.h index 144b89c..ec83c71 100644 --- a/libs/widgets/qcodeedit.h +++ b/libs/widgets/qcodeedit.h @@ -226,7 +226,8 @@ public slots: void setShowSpaces(bool yes); void setShowLineNumbers(bool yes); void search(const QString & t); - void searchNext(bool next = true); + void searchNext(bool next); + void searchNext() {searchNext(true);} void searchPrevious(); void hideSearch(); void setWordCompletitionEnabled(bool on) {word_complete = on;} diff --git a/libs/widgets/qpiconfigwidget.cpp b/libs/widgets/qpiconfigwidget.cpp index dfb1ad7..7ca2bad 100644 --- a/libs/widgets/qpiconfigwidget.cpp +++ b/libs/widgets/qpiconfigwidget.cpp @@ -61,7 +61,13 @@ bool QPIConfigWidget::eventFilter(QObject * o, QEvent * e) { if (((QMouseEvent * )e)->buttons() == Qt::RightButton) { qApp->processEvents(); itemClicked(pi, 1); - popupMenu.popup(((QMouseEvent * )e)->globalPos()); + popupMenu.popup( +#if QT_VERSION_MAJOR <= 5 + ((QMouseEvent * )e)->globalPos() +#else + ((QMouseEvent * )e)->globalPosition().toPoint() +#endif + ); } } } diff --git a/libs/widgets/qvariantedit.cpp b/libs/widgets/qvariantedit.cpp index caee456..5f7d8a9 100644 --- a/libs/widgets/qvariantedit.cpp +++ b/libs/widgets/qvariantedit.cpp @@ -210,99 +210,167 @@ void QVariantEdit::_recreate(const QVariant & new_value) { return; } _delete(); +#if QT_VERSION_MAJOR <= 5 switch (new_value.type()) { +#else + switch (new_value.metaType().id()) { +#endif +#if QT_VERSION_MAJOR <= 5 case QVariant::Bool: +#else + case QMetaType::Bool: +#endif _check = new QCheckBox(this); _check->setAutoFillBackground(true); _cur_edit = _check; connect(_check, SIGNAL(toggled(bool)), this, SLOT(_changed())); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::Int: +#else + case QMetaType::Int: +#endif _spin = new QDoubleSpinBox(this); _spin->setDecimals(0); _spin->setRange(-0x7FFFFFFF, 0x7FFFFFFF); _cur_edit = _spin; connect(_spin, SIGNAL(valueChanged(double)), this, SLOT(_changed())); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::UInt: +#else + case QMetaType::UInt: +#endif _spin = new QDoubleSpinBox(this); _spin->setDecimals(0); _spin->setRange(0, 0xFFFFFFFF); _cur_edit = _spin; connect(_spin, SIGNAL(valueChanged(double)), this, SLOT(_changed())); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::LongLong: +#else + case QMetaType::LongLong: +#endif _spin = new QDoubleSpinBox(this); _spin->setDecimals(0); _spin->setRange(-0x7FFFFFFFFFFFFFFFL, 0x7FFFFFFFFFFFFFFFL); _cur_edit = _spin; connect(_spin, SIGNAL(valueChanged(double)), this, SLOT(_changed())); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::ULongLong: +#else + case QMetaType::ULongLong: +#endif _spin = new QDoubleSpinBox(this); _spin->setDecimals(0); _spin->setRange(0L, 0x7FFFFFFFFFFFFFFFL); _cur_edit = _spin; connect(_spin, SIGNAL(valueChanged(double)), this, SLOT(_changed())); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::Double: +#else + case QMetaType::Double: +#endif _espin = new EvalSpinBox(this); //_spin->setDecimals(5); //_spin->setRange(-1E+199, 1E+199); _cur_edit = _espin; connect(_espin, SIGNAL(valueChanged(double)), this, SLOT(_changed())); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::Color: +#else + case QMetaType::QColor: +#endif _color = new ColorButton(this); _color->setUseAlphaChannel(true); _cur_edit = _color; connect(_color, SIGNAL(colorChanged(QColor)), this, SLOT(_changed())); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::String: +#else + case QMetaType::QString: +#endif _line = new CLineEdit(this); _cur_edit = _line; connect(_line, SIGNAL(textChanged(QString)), this, SLOT(_changed())); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::StringList: +#else + case QMetaType::QStringList: +#endif _list = new StringListEdit(this); _cur_edit = _list; connect(_list, SIGNAL(valueChanged()), this, SLOT(_changed())); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::Rect: +#else + case QMetaType::QRect: +#endif _rect = new QRectEdit(this); _rect->setDecimals(0); _cur_edit = _rect; connect(_rect, SIGNAL(valueChanged(QRectF)), this, SLOT(_changed())); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::RectF: +#else + case QMetaType::QRectF: +#endif _rect = new QRectEdit(this); _rect->setDecimals(3); _cur_edit = _rect; connect(_rect, SIGNAL(valueChanged(QRectF)), this, SLOT(_changed())); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::Point: +#else + case QMetaType::QPoint: +#endif _point = new QPointEdit(this); _point->setDecimals(0); _cur_edit = _point; connect(_point, SIGNAL(valueChanged(QPointF)), this, SLOT(_changed())); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::PointF: +#else + case QMetaType::QPointF: +#endif _point = new QPointEdit(this); _point->setDecimals(3); _cur_edit = _point; connect(_point, SIGNAL(valueChanged(QPointF)), this, SLOT(_changed())); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::Date: +#else + case QMetaType::QDate: +#endif _date = new QDateEdit(this); _cur_edit = _date; connect(_date, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(_changed())); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::Time: +#else + case QMetaType::QTime: +#endif _date = new QTimeEdit(this); _cur_edit = _date; connect(_date, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(_changed())); break; +#if QT_VERSION_MAJOR <= 5 case QVariant::DateTime: +#else + case QMetaType::QDateTime: +#endif _date = new QDateTimeEdit(this); _cur_edit = _date; connect(_date, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(_changed())); @@ -351,23 +419,107 @@ void QVariantEdit::_recreate(const QVariant & new_value) { QVariant QVariantEdit::value() const { +#if QT_VERSION_MAJOR <= 5 switch (_value.type()) { - case QVariant::Bool: return _check->isChecked(); - case QVariant::Int: return int(_spin->value()); - case QVariant::UInt: return (unsigned int)(_spin->value()); - case QVariant::LongLong: return qlonglong(_spin->value()); - case QVariant::ULongLong: return qulonglong(_spin->value()); - case QVariant::Double: return _espin->value(); - case QVariant::Color: return _color->color(); - case QVariant::String: return _line->text(); - case QVariant::StringList: return _list->value(); - case QVariant::Rect: return _rect->value().toRect(); - case QVariant::RectF: return _rect->value(); - case QVariant::Point: return _point->value().toPoint(); - case QVariant::PointF: return _point->value(); - case QVariant::Date: return _date->date(); - case QVariant::Time: return _date->time(); - case QVariant::DateTime: return _date->dateTime(); +#else + switch (_value.metaType().id()) { +#endif +#if QT_VERSION_MAJOR <= 5 + case QVariant::Bool: +#else + case QMetaType::Bool: +#endif + return _check->isChecked(); +#if QT_VERSION_MAJOR <= 5 + case QVariant::Int: +#else + case QMetaType::Int: +#endif + return int(_spin->value()); +#if QT_VERSION_MAJOR <= 5 + case QVariant::UInt: +#else + case QMetaType::UInt: +#endif + return (unsigned int)(_spin->value()); +#if QT_VERSION_MAJOR <= 5 + case QVariant::LongLong: +#else + case QMetaType::LongLong: +#endif + return qlonglong(_spin->value()); +#if QT_VERSION_MAJOR <= 5 + case QVariant::ULongLong: +#else + case QMetaType::ULongLong: +#endif + return qulonglong(_spin->value()); +#if QT_VERSION_MAJOR <= 5 + case QVariant::Double: +#else + case QMetaType::Double: +#endif + return _espin->value(); +#if QT_VERSION_MAJOR <= 5 + case QVariant::Color: +#else + case QMetaType::QColor: +#endif + return _color->color(); +#if QT_VERSION_MAJOR <= 5 + case QVariant::String: +#else + case QMetaType::QString: +#endif + return _line->text(); +#if QT_VERSION_MAJOR <= 5 + case QVariant::StringList: +#else + case QMetaType::QStringList: +#endif + return _list->value(); +#if QT_VERSION_MAJOR <= 5 + case QVariant::Rect: +#else + case QMetaType::QRect: +#endif + return _rect->value().toRect(); +#if QT_VERSION_MAJOR <= 5 + case QVariant::RectF: +#else + case QMetaType::QRectF: +#endif + return _rect->value(); +#if QT_VERSION_MAJOR <= 5 + case QVariant::Point: +#else + case QMetaType::QPoint: +#endif + return _point->value().toPoint(); +#if QT_VERSION_MAJOR <= 5 + case QVariant::PointF: +#else + case QMetaType::QPointF: +#endif + return _point->value(); +#if QT_VERSION_MAJOR <= 5 + case QVariant::Date: +#else + case QMetaType::QDate: +#endif + return _date->date(); +#if QT_VERSION_MAJOR <= 5 + case QVariant::Time: +#else + case QMetaType::QTime: +#endif + return _date->time(); +#if QT_VERSION_MAJOR <= 5 + case QVariant::DateTime: +#else + case QMetaType::QDateTime: +#endif + return _date->dateTime(); default: if (_value.canConvert() && _enum) { QAD::Enum ret; diff --git a/libs/widgets/session_manager.cpp b/libs/widgets/session_manager.cpp index 0774eea..cf79ad6 100644 --- a/libs/widgets/session_manager.cpp +++ b/libs/widgets/session_manager.cpp @@ -8,6 +8,7 @@ #endif #include "session_manager.h" #include "qad_locations.h" +#include "qad_types.h" SessionManager::SessionManager(QString file) { @@ -107,7 +108,7 @@ void SessionManager::save() { sr.setValue(floats[i].first, *floats[i].second, false); QSet all_list; foreach (QObject * c, tsc) { - all_list |= QSet::fromList(c->findChildren()); + all_list |= QList2QSet(c->findChildren()); } QMap funcs = metaFunctions(all_list, "sessionSave"); //qDebug() << "check for save" << all_list.size(); @@ -231,7 +232,7 @@ void SessionManager::load(bool onlyMainwindow) { *floats[i].second = sr.getValue(floats[i].first, *floats[i].second).toFloat(); QSet all_list; foreach (QObject * c, tsc) { - all_list |= QSet::fromList(c->findChildren()); + all_list |= QList2QSet(c->findChildren()); } QMap funcs = metaFunctions(all_list, "sessionLoad"); //qDebug() << "check for load" << all_list.size(); diff --git a/libs/widgets/session_manager.h b/libs/widgets/session_manager.h index 4d55e11..10b81c3 100644 --- a/libs/widgets/session_manager.h +++ b/libs/widgets/session_manager.h @@ -117,8 +117,10 @@ private: public slots: void save(); - void load(bool onlyMainwindow = false); - void clear(bool with_filename = true); + void load(bool onlyMainwindow); + void load() {load(false);} + void clear(bool with_filename); + void clear() {clear(true);} signals: void loading(QPIConfig & ); diff --git a/utils/blockeditor/blockeditor_main.cpp b/utils/blockeditor/blockeditor_main.cpp index bf103af..e2f8e34 100644 --- a/utils/blockeditor/blockeditor_main.cpp +++ b/utils/blockeditor/blockeditor_main.cpp @@ -4,9 +4,7 @@ int main(int argc, char * argv[]) { QApplication a(argc, argv); -#if QT_VERSION >= 0x050000 - a.setAttribute(Qt::AA_UseHighDpiPixmaps, true); -#endif + enableHighDPI(); a.setWindowIcon(QIcon(":/icons/blockview.png")); BlockEditor w; if (a.arguments().size() > 1) diff --git a/utils/piconnedit/piconnedit_main.cpp b/utils/piconnedit/piconnedit_main.cpp index 4cbd265..487a84a 100644 --- a/utils/piconnedit/piconnedit_main.cpp +++ b/utils/piconnedit/piconnedit_main.cpp @@ -2,6 +2,7 @@ #include "piqt_connection_edit.h" #include #include +#include #include #include @@ -9,9 +10,7 @@ int main(int argc, char * argv[]) { PIINTROSPECTION_START QApplication a(argc, argv); -#if QT_VERSION >= 0x050000 - a.setAttribute(Qt::AA_UseHighDpiPixmaps, true); -#endif + enableHighDPI(); ConnectionEdit w; if (a.arguments().size() > 1) { QPIConfig cfg(a.arguments()[1]); diff --git a/utils/pidumper/pidumper.h b/utils/pidumper/pidumper.h index 677fe1f..852475d 100644 --- a/utils/pidumper/pidumper.h +++ b/utils/pidumper/pidumper.h @@ -4,7 +4,6 @@ #include "ui_pidumper.h" #include #include -#include #include #include #include "piqt.h" diff --git a/utils/pidumper/pidumper_main.cpp b/utils/pidumper/pidumper_main.cpp index 5f2a368..edbe584 100644 --- a/utils/pidumper/pidumper_main.cpp +++ b/utils/pidumper/pidumper_main.cpp @@ -4,9 +4,7 @@ int main(int argc, char * argv[]) { QApplication a(argc, argv); -#if QT_VERSION >= 0x050000 - a.setAttribute(Qt::AA_UseHighDpiPixmaps, true); -#endif + enableHighDPI(); PIDumper w; w.show(); return a.exec(); diff --git a/utils/piintrospector/piintrospector.h b/utils/piintrospector/piintrospector.h index 7b4d7cd..7a89da0 100644 --- a/utils/piintrospector/piintrospector.h +++ b/utils/piintrospector/piintrospector.h @@ -4,7 +4,6 @@ #include "ui_piintrospector.h" #include #include -#include #include #include #include "piqt.h" diff --git a/utils/piintrospector/piintrospector_main.cpp b/utils/piintrospector/piintrospector_main.cpp index 3d25393..ed13494 100644 --- a/utils/piintrospector/piintrospector_main.cpp +++ b/utils/piintrospector/piintrospector_main.cpp @@ -1,13 +1,35 @@ #include +#include #include "piintrospector.h" +#include "qcodeedit.h" int main(int argc, char * argv[]) { QApplication a(argc, argv); -#if QT_VERSION >= 0x050000 - a.setAttribute(Qt::AA_UseHighDpiPixmaps, true); -#endif + enableHighDPI(); QPIIntrospector w; + /*QCodeEdit w; + w.setEditorFont(QFont("dejavu sans mono", 10)); + w.setText( + "Telegram.addCommand(\"Поискать 💰\", \"find_money\");\n" + "Telegram.addCommand(\"🔍Исследования\", \"research\");\n" + "Telegram.addCommand(\"📖Инфо/🌍Планета\", \"planet_info\");\n" + "Telegram.addCommand(\"📖Инфо/💻Дерево исследований\", \"research_map\");\n" + "Telegram.addCommand(\"📖Инфо/🌌Сканер планет\", \"map_info\");\n" + "Telegram.addCommand(\"🛠Строительство/📖Инфо\", \"planet_info\");\n" + "Telegram.addCommand(\"🛠Строительство/⛏Шахта\", \"info_plant\");\n" + "Telegram.addCommand(\"🛠Строительство/⛏Шахта/📖Инфо\", \"info_plant\");\n" + "Telegram.addCommand(\"🛠Строительство/⛏Шахта/🛠Cтроить ⛏Шахту\", \"build_plant\");\n" + "Telegram.addCommand(\"🛠Строительство/⚡️Электростанция\", \"info_solar\");\n" + "Telegram.addCommand(\"🛠Строительство/⚡️Электростанция/📖Инфо\", \"info_solar\");\n" + "Telegram.addCommand(\"🛠Строительство/⚡️Электростанция/🛠Cтроить ⚡️Электростанцию\", \"build_solar\");\n" + "Telegram.addCommand(\"🛠Строительство/🔋Аккумулятор\", \"info_accum\");\n" + "Telegram.addCommand(\"🛠Строительство/🔋Аккумулятор/📖Инфо\", \"info_accum\");\n" + "Telegram.addCommand(\"🛠Строительство/🔋Аккумулятор/🛠Cтроить 🔋Аккумулятор\", \"build_accum\");\n" + "Telegram.addCommand(\"🛠Строительство/📦Хранилище\", \"info_storage\");\n" + "Telegram.addCommand(\"🛠Строительство/📦Хранилище/📖Инфо\", \"info_storage\");\n" + ); + //w.textEdit()->setCursorWidth(1);*/ w.show(); return a.exec(); } diff --git a/utils/qpicalculator/main.cpp b/utils/qpicalculator/main.cpp index afb41cf..82e2ee7 100644 --- a/utils/qpicalculator/main.cpp +++ b/utils/qpicalculator/main.cpp @@ -1,12 +1,11 @@ #include +#include "qad_types.h" #include "mainwindow.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); -#if QT_VERSION >= 0x050000 - a.setAttribute(Qt::AA_UseHighDpiPixmaps, true); -#endif + enableHighDPI(); MainWindow w; w.show(); return a.exec();