diff --git a/5_using_rubber_band_with_canvas/CMakeLists.txt b/5_using_rubber_band_with_canvas/CMakeLists.txt index c683891..36d8a3b 100644 --- a/5_using_rubber_band_with_canvas/CMakeLists.txt +++ b/5_using_rubber_band_with_canvas/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.6) PROJECT(timtut5) SET(CMAKE_COLOR_MAKEFILE ON) # set path to additional CMake modules -SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake_find_rules ${CMAKE_MODULE_PATH}) +SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) FIND_PACKAGE(QGIS REQUIRED) IF (NOT QGIS_FOUND) MESSAGE (SEND_ERROR "QGIS dependency was not found!") @@ -66,16 +66,17 @@ SET (QT_USE_QTSQL TRUE) SET (QT_USE_QTSVG TRUE) SET (QT_USE_QTXML TRUE) SET (QT_USE_QTNETWORK TRUE) -FIND_PACKAGE(Qt4 REQUIRED) -INCLUDE( ${QT_USE_FILE} ) +FIND_PACKAGE(Qt5 REQUIRED COMPONENTS Core Widgets Xml Svg) + +# INCLUDE( ${QT_USE_FILE} ) ######################################################## # Build -QT4_WRAP_UI (timtut5_UIS_H ${timtut5_UIS}) +QT5_WRAP_UI (timtut5_UIS_H ${timtut5_UIS}) -QT4_WRAP_CPP (timtut5_MOC_SRCS ${timtut5_MOC_HDRS}) +QT5_WRAP_CPP (timtut5_MOC_SRCS ${timtut5_MOC_HDRS}) -QT4_ADD_RESOURCES(timtut5_RCC_SRCS ${timtut5_RCCS}) +QT5_ADD_RESOURCES(timtut5_RCC_SRCS ${timtut5_RCCS}) ADD_EXECUTABLE (timtut5 ${timtut5_SRCS} ${timtut5_MOC_SRCS} ${timtut5_RCC_SRCS} ${timtut5_UIS_H}) @@ -88,14 +89,11 @@ INCLUDE_DIRECTORIES( . ) -#This is probably no longer needed, but I will leave it in for Win machines for the moment -IF(QT_QTSQL_FOUND) - FIND_LIBRARY(QT_QTSQL_LIBRARY NAMES QtSql QtSql5 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH) - SET(QT_LIBRARIES ${QT_LIBRARIES} ${QT_QTSQL_LIBRARY}) -ENDIF(QT_QTSQL_FOUND) - TARGET_LINK_LIBRARIES(timtut5 - ${QT_LIBRARIES} + Qt5::Core + Qt5::Widgets + Qt5::Xml + Qt5::Svg ${QGIS_CORE_LIBRARY} ${QGIS_GUI_LIBRARY} ${GEOS_LIBRARY} @@ -112,5 +110,3 @@ ENDIF (MSVC) ######################################################## # Install - - diff --git a/5_using_rubber_band_with_canvas/cmake_find_rules/FindGDAL.cmake b/5_using_rubber_band_with_canvas/cmake/FindGDAL.cmake similarity index 100% rename from 5_using_rubber_band_with_canvas/cmake_find_rules/FindGDAL.cmake rename to 5_using_rubber_band_with_canvas/cmake/FindGDAL.cmake diff --git a/5_using_rubber_band_with_canvas/cmake/FindGEOS.cmake b/5_using_rubber_band_with_canvas/cmake/FindGEOS.cmake new file mode 100644 index 0000000..f7ef380 --- /dev/null +++ b/5_using_rubber_band_with_canvas/cmake/FindGEOS.cmake @@ -0,0 +1,187 @@ +# Find GEOS +# ~~~~~~~~~ +# Copyright (c) 2008, Mateusz Loskot +# (based on FindGDAL.cmake by Magnus Homann) +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# +# CMake module to search for GEOS library +# +# If it's found it sets GEOS_FOUND to TRUE +# and following variables are set: +# GEOS_INCLUDE_DIR +# GEOS_LIBRARY +# + +INCLUDE (${CMAKE_SOURCE_DIR}/cmake/MacPlistMacros.cmake) + +IF(WIN32) + + IF (MINGW) + FIND_PATH(GEOS_INCLUDE_DIR geos_c.h "$ENV{LIB_DIR}/include" /usr/local/include /usr/include c:/msys/local/include) + FIND_LIBRARY(GEOS_LIBRARY NAMES geos_c PATHS "$ENV{LIB_DIR}/lib" /usr/local/lib /usr/lib c:/msys/local/lib) + ENDIF (MINGW) + + IF (MSVC) + FIND_PATH(GEOS_INCLUDE_DIR geos_c.h $ENV{LIB_DIR}/include $ENV{INCLUDE}) + FIND_LIBRARY(GEOS_LIBRARY NAMES geos_c_i geos_c PATHS + "$ENV{LIB_DIR}/lib" + $ENV{LIB} + ) + ENDIF (MSVC) + +ELSEIF(APPLE AND QGIS_MAC_DEPS_DIR) + + FIND_PATH(GEOS_INCLUDE_DIR geos_c.h "$ENV{LIB_DIR}/include" ) + FIND_LIBRARY(GEOS_LIBRARY NAMES geos_c PATHS "$ENV{LIB_DIR}/lib" ) + +ELSE(WIN32) + + IF(UNIX) + # try to use framework on mac + # want clean framework path, not unix compatibility path + IF (APPLE) + IF (CMAKE_FIND_FRAMEWORK MATCHES "FIRST" + OR CMAKE_FRAMEWORK_PATH MATCHES "ONLY" + OR NOT CMAKE_FIND_FRAMEWORK) + SET (CMAKE_FIND_FRAMEWORK_save ${CMAKE_FIND_FRAMEWORK} CACHE STRING "" FORCE) + SET (CMAKE_FIND_FRAMEWORK "ONLY" CACHE STRING "" FORCE) + FIND_LIBRARY(GEOS_LIBRARY GEOS) + IF (GEOS_LIBRARY) + # they're all the same in a framework + SET (GEOS_INCLUDE_DIR ${GEOS_LIBRARY}/Headers CACHE PATH "Path to a file.") + # set GEOS_CONFIG to make later test happy, not used here, may not exist + SET (GEOS_CONFIG ${GEOS_LIBRARY}/unix/bin/geos-config CACHE FILEPATH "Path to a program.") + # version in info.plist + GET_VERSION_PLIST (${GEOS_LIBRARY}/Resources/Info.plist GEOS_VERSION) + IF (NOT GEOS_VERSION) + MESSAGE (FATAL_ERROR "Could not determine GEOS version from framework.") + ENDIF (NOT GEOS_VERSION) + STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1" GEOS_VERSION_MAJOR "${GEOS_VERSION}") + STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\2" GEOS_VERSION_MINOR "${GEOS_VERSION}") + IF (GEOS_VERSION_MAJOR LESS 3) + MESSAGE (FATAL_ERROR "GEOS version is too old (${GEOS_VERSION}). Use 3.0.0 or higher.") + ENDIF (GEOS_VERSION_MAJOR LESS 3) + ENDIF (GEOS_LIBRARY) + SET (CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK_save} CACHE STRING "" FORCE) + ENDIF () + ENDIF (APPLE) + + IF(CYGWIN) + FIND_LIBRARY(GEOS_LIBRARY NAMES geos_c PATHS /usr/lib /usr/local/lib) + ENDIF(CYGWIN) + + IF (NOT GEOS_INCLUDE_DIR OR NOT GEOS_LIBRARY OR NOT GEOS_CONFIG) + # didn't find OS X framework, and was not set by user + SET(GEOS_CONFIG_PREFER_PATH "$ENV{GEOS_HOME}/bin" CACHE STRING "preferred path to GEOS (geos-config)") + FIND_PROGRAM(GEOS_CONFIG geos-config + ${GEOS_CONFIG_PREFER_PATH} + $ENV{LIB_DIR}/bin + /usr/local/bin/ + /usr/bin/ + ) + #MESSAGE("DBG GEOS_CONFIG ${GEOS_CONFIG}") + + IF (GEOS_CONFIG) + + EXEC_PROGRAM(${GEOS_CONFIG} + ARGS --version + OUTPUT_VARIABLE GEOS_VERSION) + STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1" GEOS_VERSION_MAJOR "${GEOS_VERSION}") + STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\2" GEOS_VERSION_MINOR "${GEOS_VERSION}") + + IF (GEOS_VERSION_MAJOR LESS 3 OR (GEOS_VERSION_MAJOR EQUAL 3 AND GEOS_VERSION_MINOR LESS 3) ) + MESSAGE (FATAL_ERROR "GEOS version is too old (${GEOS_VERSION}). Use 3.3.0 or higher.") + ENDIF (GEOS_VERSION_MAJOR LESS 3 OR (GEOS_VERSION_MAJOR EQUAL 3 AND GEOS_VERSION_MINOR LESS 3) ) + + # set INCLUDE_DIR to prefix+include + EXEC_PROGRAM(${GEOS_CONFIG} + ARGS --prefix + OUTPUT_VARIABLE GEOS_PREFIX) + + FIND_PATH(GEOS_INCLUDE_DIR + geos_c.h + ${GEOS_PREFIX}/include + /usr/local/include + /usr/include + ) + + ## extract link dirs for rpath + EXEC_PROGRAM(${GEOS_CONFIG} + ARGS --libs + OUTPUT_VARIABLE GEOS_CONFIG_LIBS ) + + ## split off the link dirs (for rpath) + ## use regular expression to match wildcard equivalent "-L*" + ## with is a space or a semicolon + STRING(REGEX MATCHALL "[-][L]([^ ;])+" + GEOS_LINK_DIRECTORIES_WITH_PREFIX + "${GEOS_CONFIG_LIBS}" ) + #MESSAGE("DBG GEOS_LINK_DIRECTORIES_WITH_PREFIX=${GEOS_LINK_DIRECTORIES_WITH_PREFIX}") + + ## remove prefix -L because we need the pure directory for LINK_DIRECTORIES + + IF (GEOS_LINK_DIRECTORIES_WITH_PREFIX) + STRING(REGEX REPLACE "[-][L]" "" GEOS_LINK_DIRECTORIES ${GEOS_LINK_DIRECTORIES_WITH_PREFIX} ) + ENDIF (GEOS_LINK_DIRECTORIES_WITH_PREFIX) + + ### XXX - mloskot: geos-config --libs does not return -lgeos_c, so set it manually + ## split off the name + ## use regular expression to match wildcard equivalent "-l*" + ## with is a space or a semicolon + #STRING(REGEX MATCHALL "[-][l]([^ ;])+" + # GEOS_LIB_NAME_WITH_PREFIX + # "${GEOS_CONFIG_LIBS}" ) + #MESSAGE("DBG GEOS_CONFIG_LIBS=${GEOS_CONFIG_LIBS}") + #MESSAGE("DBG GEOS_LIB_NAME_WITH_PREFIX=${GEOS_LIB_NAME_WITH_PREFIX}") + SET(GEOS_LIB_NAME_WITH_PREFIX -lgeos_c CACHE STRING INTERNAL) + + ## remove prefix -l because we need the pure name + + IF (GEOS_LIB_NAME_WITH_PREFIX) + STRING(REGEX REPLACE "[-][l]" "" GEOS_LIB_NAME ${GEOS_LIB_NAME_WITH_PREFIX} ) + ENDIF (GEOS_LIB_NAME_WITH_PREFIX) + #MESSAGE("DBG GEOS_LIB_NAME=${GEOS_LIB_NAME}") + + IF (APPLE) + IF (NOT GEOS_LIBRARY) + # work around empty GEOS_LIBRARY left by framework check + # while still preserving user setting if given + # ***FIXME*** need to improve framework check so below not needed + SET(GEOS_LIBRARY ${GEOS_LINK_DIRECTORIES}/lib${GEOS_LIB_NAME}.dylib CACHE STRING INTERNAL FORCE) + ENDIF (NOT GEOS_LIBRARY) + ELSE (APPLE) + FIND_LIBRARY(GEOS_LIBRARY NAMES ${GEOS_LIB_NAME} PATHS ${GEOS_LIB_DIRECTORIES}/lib) + ENDIF (APPLE) + #MESSAGE("DBG GEOS_LIBRARY=${GEOS_LIBRARY}") + + ELSE(GEOS_CONFIG) + MESSAGE("FindGEOS.cmake: geos-config not found. Please set it manually. GEOS_CONFIG=${GEOS_CONFIG}") + ENDIF(GEOS_CONFIG) + ENDIF(NOT GEOS_INCLUDE_DIR OR NOT GEOS_LIBRARY OR NOT GEOS_CONFIG) + ENDIF(UNIX) +ENDIF(WIN32) + +IF(GEOS_INCLUDE_DIR AND NOT GEOS_VERSION) + FILE(READ ${GEOS_INCLUDE_DIR}/geos_c.h VERSIONFILE) + STRING(REGEX MATCH "#define GEOS_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+" GEOS_VERSION ${VERSIONFILE}) + STRING(REGEX MATCH "[0-9]+\\.[0-9]\\.[0-9]+" GEOS_VERSION ${GEOS_VERSION}) +ENDIF(GEOS_INCLUDE_DIR AND NOT GEOS_VERSION) + +IF (GEOS_INCLUDE_DIR AND GEOS_LIBRARY) + SET(GEOS_FOUND TRUE) +ENDIF (GEOS_INCLUDE_DIR AND GEOS_LIBRARY) + +IF (GEOS_FOUND) + + IF (NOT GEOS_FIND_QUIETLY) + MESSAGE(STATUS "Found GEOS: ${GEOS_LIBRARY} (${GEOS_VERSION})") + ENDIF (NOT GEOS_FIND_QUIETLY) + +ELSE (GEOS_FOUND) + + MESSAGE(GEOS_INCLUDE_DIR=${GEOS_INCLUDE_DIR}) + MESSAGE(GEOS_LIBRARY=${GEOS_LIBRARY}) + MESSAGE(FATAL_ERROR "Could not find GEOS") + +ENDIF (GEOS_FOUND) diff --git a/5_using_rubber_band_with_canvas/cmake_find_rules/FindQGIS.cmake b/5_using_rubber_band_with_canvas/cmake/FindQGIS.cmake similarity index 100% rename from 5_using_rubber_band_with_canvas/cmake_find_rules/FindQGIS.cmake rename to 5_using_rubber_band_with_canvas/cmake/FindQGIS.cmake diff --git a/5_using_rubber_band_with_canvas/cmake/MacPlistMacros.cmake b/5_using_rubber_band_with_canvas/cmake/MacPlistMacros.cmake new file mode 100644 index 0000000..b123872 --- /dev/null +++ b/5_using_rubber_band_with_canvas/cmake/MacPlistMacros.cmake @@ -0,0 +1,12 @@ +# Mac Plist Macros + +FUNCTION (GET_VERSION_PLIST PLISTFILE OUTVAR) + SET (PVERSION "") + IF (EXISTS ${PLISTFILE}) + FILE (READ "${PLISTFILE}" info_plist) + STRING (REGEX REPLACE "\n" "" info_plist "${info_plist}") + STRING (REGEX MATCH "CFBundleShortVersionString[ \t]*([0-9\\.]*)" PLISTVERSION "${info_plist}") + STRING (REGEX REPLACE "CFBundleShortVersionString[ \t]*([0-9\\.]*)" "\\1" PVERSION "${PLISTVERSION}") + ENDIF (EXISTS ${PLISTFILE}) + SET (${OUTVAR} ${PVERSION} PARENT_SCOPE) +ENDFUNCTION (GET_VERSION_PLIST) diff --git a/5_using_rubber_band_with_canvas/cmake_find_rules/FindGEOS.cmake b/5_using_rubber_band_with_canvas/cmake_find_rules/FindGEOS.cmake deleted file mode 100644 index 520ba36..0000000 --- a/5_using_rubber_band_with_canvas/cmake_find_rules/FindGEOS.cmake +++ /dev/null @@ -1,45 +0,0 @@ - -# CMake module to search for GEOS library -# -# If it's found it sets GEOS_FOUND to TRUE -# and following variables are set: -# GEOS_INCLUDE_DIR -# GEOS_LIBRARY - - -FIND_PATH(GEOS_INCLUDE_DIR geos.h - /usr/local/include - /usr/include - #MSVC - "$ENV{LIB_DIR}/include" - #mingw - c:/msys/local/include - ) - -FIND_LIBRARY(GEOS_LIBRARY NAMES geos PATHS - /usr/local/lib - /usr/lib - #MSVC - "$ENV{LIB_DIR}/lib" - #mingw - c:/msys/local/lib - ) - -IF (GEOS_INCLUDE_DIR AND GEOS_LIBRARY) - SET(GEOS_FOUND TRUE) -ENDIF (GEOS_INCLUDE_DIR AND GEOS_LIBRARY) - - -IF (GEOS_FOUND) - - IF (NOT GEOS_FIND_QUIETLY) - MESSAGE(STATUS "Found GEOS: ${GEOS_LIBRARY}") - ENDIF (NOT GEOS_FIND_QUIETLY) - -ELSE (GEOS_FOUND) - - IF (GEOS_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find GEOS") - ENDIF (GEOS_FIND_REQUIRED) - -ENDIF (GEOS_FOUND) diff --git a/5_using_rubber_band_with_canvas/main.cpp b/5_using_rubber_band_with_canvas/main.cpp index 3285180..4c46988 100644 --- a/5_using_rubber_band_with_canvas/main.cpp +++ b/5_using_rubber_band_with_canvas/main.cpp @@ -30,7 +30,7 @@ int main(int argc, char ** argv) { // Start the Application - QgsApplication app(argc, argv, TRUE); + QgsApplication app(argc, argv, true); MainWindow * mypMainWindow = new MainWindow(); mypMainWindow->show(); // Start the Application Event Loop diff --git a/5_using_rubber_band_with_canvas/mainwindow.cpp b/5_using_rubber_band_with_canvas/mainwindow.cpp index 3e433a6..6d0f1e0 100644 --- a/5_using_rubber_band_with_canvas/mainwindow.cpp +++ b/5_using_rubber_band_with_canvas/mainwindow.cpp @@ -18,26 +18,34 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "mainwindow.h" +#include +#include // // QGIS Includes // #include #include #include -#include +#include #include #include -// +#include +#include +#include // + // Needed fr rubber band support // -#include +#include +#include +#include + // // QGIS Map tools // #include "qgsmaptoolpan.h" #include "qgsmaptoolzoom.h" -MainWindow::MainWindow(QWidget* parent, Qt::WFlags fl) +MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags fl) : QMainWindow(parent,fl) { //required by Qt4 to initialise the ui @@ -47,13 +55,13 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags fl) #if defined(Q_WS_MAC) QString myPluginsDir = "/Users/timsutton/apps/qgis.app/Contents/MacOS/lib/qgis"; #else - QString myPluginsDir = "/home/timlinux/apps/lib/qgis"; + QString myPluginsDir = "/usr/lib/qgis"; #endif QgsProviderRegistry::instance(myPluginsDir); // Create the Map Canvas - mpMapCanvas= new QgsMapCanvas(0, 0); + mpMapCanvas= new QgsMapCanvas(); mpMapCanvas->enableAntiAliasing(true); mpMapCanvas->setCanvasColor(QColor(255, 255, 255)); mpMapCanvas->freeze(false); @@ -81,15 +89,14 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags fl) //create the maptools mpPanTool = new QgsMapToolPan(mpMapCanvas); mpPanTool->setAction(mpActionPan); - mpZoomInTool = new QgsMapToolZoom(mpMapCanvas, FALSE); // false = in + mpZoomInTool = new QgsMapToolZoom(mpMapCanvas, false); // false = in mpZoomInTool->setAction(mpActionZoomIn); - mpZoomOutTool = new QgsMapToolZoom(mpMapCanvas, TRUE ); //true = out + mpZoomOutTool = new QgsMapToolZoom(mpMapCanvas, true ); //true = out mpZoomOutTool->setAction(mpActionZoomOut); //create the rubber band - bool myPolygonFlag=true; - mpRubberBand = new QgsRubberBand(mpMapCanvas, myPolygonFlag ); - mpRubberBand->show(); + mpRubberBand = new QgsRubberBand(mpMapCanvas, QgsWkbTypes::PolygonGeometry ); + mpRubberBand->setVisible( true ); } MainWindow::~MainWindow() @@ -131,38 +138,72 @@ void MainWindow::addLayer() return; } // render strategy for grayscale image (will be rendered as pseudocolor) - mypLayer->setDrawingStyle( QgsRasterLayer::SingleBandPseudoColor ); - mypLayer->setColorShadingAlgorithm( QgsRasterLayer::PseudoColorShader ); - mypLayer->setContrastEnhancementAlgorithm( - QgsContrastEnhancement::StretchToMinimumMaximum, false ); - mypLayer->setMinimumValue( mypLayer->grayBandName(), 0.0, false ); - mypLayer->setMaximumValue( mypLayer->grayBandName(), 10.0 ); + mypLayer->setContrastEnhancement( + QgsContrastEnhancement::StretchToMinimumMaximum); + + QgsRasterShader *rasterShader = new QgsRasterShader(); + QgsColorRampShader *colorRampShader = new QgsColorRampShader(); + colorRampShader->setColorRampType(QgsColorRampShader::Interpolated); + + QgsRasterBandStats stats = mypLayer->dataProvider()->bandStatistics(1); + + qDebug("Min value: %f", stats.minimumValue); + qDebug("Max value: %f", stats.maximumValue); + QList colorRampItems; + QgsColorRampShader::ColorRampItem firstItem; + firstItem.value = stats.minimumValue; + firstItem.label = printf("%f", stats.minimumValue); + firstItem.color = QColor( 100, 149, 237 ); + colorRampItems.append( firstItem ); + + + QgsColorRampShader::ColorRampItem secondItem; + secondItem.value = stats.maximumValue; + secondItem.label = printf("%f", stats.maximumValue); + secondItem.color = QColor( 165, 42, 42 ); + colorRampItems.append( secondItem ); + + colorRampShader->setColorRampItemList( colorRampItems ); + rasterShader->setRasterShaderFunction( colorRampShader ); + + QgsSingleBandPseudoColorRenderer *rasterRenderer = new QgsSingleBandPseudoColorRenderer( mypLayer->dataProvider(), 1, rasterShader ); + + mypLayer->setRenderer( rasterRenderer ); + // mypLayer->setDrawingStyle( QgsRasterLayer::SingleBandPseudoColor ); + // mypLayer->setColorShadingAlgorithm( QgsRasterLayer::PseudoColorShader ); + // mypLayer->setContrastEnhancementAlgorithm( + // QgsContrastEnhancement::StretchToMinimumMaximum, false ); + // mypLayer->setMinimumValue( mypLayer->grayBandName(), 0.0, false ); + // mypLayer->setMaximumValue( mypLayer->grayBandName(), 10.0 ); + //create a layerset - QList myList; + QList layers; // Add the layers to the Layer Set - myList.append(QgsMapCanvasLayer(mypLayer, TRUE));//bool visibility + layers.append(mypLayer);//bool visibility // set the canvas to the extent of our layer mpMapCanvas->setExtent(mypLayer->extent()); // Add the Vector Layer to the Layer Registry - QgsMapLayerRegistry::instance()->addMapLayer(mypLayer, TRUE); + QgsProject::instance()->addMapLayer(mypLayer, true); // Set the Map Canvas Layer Set - mpMapCanvas->setLayerSet(myList); + mpMapCanvas->setLayers(layers); } void MainWindow::on_mpToolShowRubberBand_clicked() { - QgsPoint myPoint1 = mpMapCanvas->getCoordinateTransform()->toMapCoordinates(10, 10); + QgsPointXY myPoint1 = mpMapCanvas->getCoordinateTransform()->toMapCoordinates(10.0, 10.0); mpRubberBand->addPoint(myPoint1); - QgsPoint myPoint2 = mpMapCanvas->getCoordinateTransform()->toMapCoordinates(20, 10); + QgsPointXY myPoint2 = mpMapCanvas->getCoordinateTransform()->toMapCoordinates(20.0, 10.0); mpRubberBand->addPoint(myPoint2); - QgsPoint myPoint3 = mpMapCanvas->getCoordinateTransform()->toMapCoordinates(20, 20); + QgsPointXY myPoint3 = mpMapCanvas->getCoordinateTransform()->toMapCoordinates(20.0, 20.0); mpRubberBand->addPoint(myPoint3); - QgsPoint myPoint4 = mpMapCanvas->getCoordinateTransform()->toMapCoordinates(10, 20); + QgsPointXY myPoint4 = mpMapCanvas->getCoordinateTransform()->toMapCoordinates(10.0, 20.0); mpRubberBand->addPoint(myPoint4); + QgsPointXY myPoint5 = mpMapCanvas->getCoordinateTransform()->toMapCoordinates(10.0, 10.0); + mpRubberBand->addPoint(myPoint5); } void MainWindow::on_mpToolHideRubberBand_clicked() { - bool myPolygonFlag=true; - mpRubberBand->reset(myPolygonFlag); + mpRubberBand->reset(QgsWkbTypes::PolygonGeometry); + mpRubberBand->setVisible( false ); } diff --git a/5_using_rubber_band_with_canvas/mainwindow.h b/5_using_rubber_band_with_canvas/mainwindow.h index ebb8759..e24f72e 100644 --- a/5_using_rubber_band_with_canvas/mainwindow.h +++ b/5_using_rubber_band_with_canvas/mainwindow.h @@ -41,7 +41,7 @@ class MainWindow : public QMainWindow, private Ui::MainWindowBase { Q_OBJECT; public: - MainWindow(QWidget* parent = 0, Qt::WFlags fl = 0 ); + MainWindow(QWidget* parent = 0, Qt::WindowFlags fl = 0 ); ~MainWindow(); public slots: void zoomInMode();