Initial commit

This commit is contained in:
torsten committed 2026-08-13 18:33:10 +02:00
commit b7d90b9afe
16245 files changed
+3396666

No files matched your search

@@ -0,0 +1,268 @@
/*
**
** @RDE_HEADER@
** Shows a crash when using QGraphicsItems and ESRI-Graphics in same scene
** $Id$
** $HeadURL$
** $Author$
**
** -----------------------------------------------------------------------------------------------
**
** Hardware-Environment: Intel-PC
** Software-Environment: Windows 7, Qt 5.7. ArcGISRuntimeQt 100
**
** Language ........: C++ 11
**
** -----------------------------------------------------------------------------------------------
**
** Author ...........: Jörg Turla, SPD G, Tel. 3132
**
** -----------------------------------------------------------------------------------------------
**
** Notes .........:
**
** 16.01.2017, JT : Initial
**
** -----------------------------------------------------------------------------------------------
*/
#include <QtCore/QDir>
#include <QtCore/QUrl>
#include <QtCore/QDebug>
#include <QtGui/QPainterPath>
#include <QtGui/QSurface>
#include <QtWidgets/QApplication>
#include <QtWidgets/QDesktopWidget>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QGraphicsScene>
#include <QtWidgets/QGraphicsPathItem>
#include <QtWidgets/QMainWindow>
#include <arcgis/Map.h>
#include <arcgis/MapGraphicsView.h>
#include <arcgis/Basemap.h>
#include <arcgis/ArcGISTiledLayer.h>
#include <arcgis/Layer.h>
#include <arcgis/GraphicsOverlay.h>
#include <arcgis/PolygonBuilder.h>
#include <arcgis/Point.h>
#include <arcgis/SimpleFillSymbol.h>
#include <arcgis/DictionaryRenderer.h>
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* The class MapWindow creates a tiled base map from an UTM based TPK from Bremen. Loading the map will be done
* by clicking the "Load Map" button. The next 2 buttons creates graphics on top of the map, as follows:
*
* (1) Draw QGraphicsPathItem
* The "Draw QGraphicsPathItem" is creating an QGraphicsItemPath. The QGraphicsItemPath has a blue border line and
* is filled with a tranparent green color. See drawQGraphicPathItem().
*
* (2) Draw Overlay
* The "Draw Overlay" is creating GraphicsOverlay with one simple polygon. See buildSymbol().
*
* All is working as expected when using only one of each button, restart the program and click the other one.
* Each of both drawings are ok. In one case you will see a red filled polygon and in other case a green polygon
* with a border is drawn on the map.
*
* But now restart the program click "Draw QGraphicsPathItem" the green area with
* a blue border is visible now. After that click "Draw Overlay". The red area of GraphicOverlay polygon appears
* on the map. But the green filling of the QGraphicsItemPath has been vanished.
*
* Restart: Next click the buttons in reversed order ( "Draw Overlay" first and next "Draw QGraphicsPathItem"). On Windows
* the behaviour is the same as before - the green polygon filling is not drawn. On Linux a crash in the OpenGl
* Driver appears.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
class MapWindow : public QWidget
{
Esri::ArcGISRuntime::ArcGISTiledLayer * m_tiledLayer;
Esri::ArcGISRuntime::Basemap * m_basemap;
Esri::ArcGISRuntime::Map * m_map;
Esri::ArcGISRuntime::MapGraphicsView * m_mapView;
private:
public:
MapWindow() : QWidget(), m_tiledLayer(nullptr)
{
m_basemap = new Esri::ArcGISRuntime::Basemap(this);
m_map = new Esri::ArcGISRuntime::Map(this);
m_map->setAutoFetchLegendInfos(true);
m_mapView = new Esri::ArcGISRuntime::MapGraphicsView(this);
m_mapView->setObjectName(QLatin1String("EsriMapView"));
m_mapView->setFrameShape(QFrame::NoFrame);
m_mapView->setWrapAroundMode(Esri::ArcGISRuntime::WrapAroundMode::Disabled);
m_mapView->setFixedSize(900,900);
QPushButton * btn1 = new QPushButton(QStringLiteral("Load Map"), this);
QPushButton * btn2 = new QPushButton(QStringLiteral("Draw QGraphicsPathItem"), this);
QPushButton * btn3 = new QPushButton(QStringLiteral("Draw Overlay (Esri primitive)"), this);
btn2->setEnabled(false);
btn3->setEnabled(false);
connect( btn1, &QPushButton::clicked, this, [this](bool) { initMap(); });
connect( btn2, &QPushButton::clicked, this, [this](bool) { drawQGraphicPathItem(); });
connect( btn3, &QPushButton::clicked, this, [this](bool) { buildSymbol(); });
QVBoxLayout * layout = new QVBoxLayout(this);
layout->addWidget(btn1);
layout->addWidget(btn2);
layout->addWidget(btn3);
layout->addWidget(m_mapView,2);
connect(m_map, &Esri::ArcGISRuntime::Map::doneLoading, this, [this,btn2,btn3](Esri::ArcGISRuntime::Error loadError)
{
if (loadError.isEmpty())
{
btn2->setEnabled(true);
btn3->setEnabled(true);
} else {
qCritical() << loadError.message();
qCritical() << loadError.additionalMessage();
// Esri::ArcGISRuntime::ErrorDomainType errorDomain = loadError.domain();
// Esri::ArcGISRuntime::ExtendedErrorType extendedErr = loadError.extendedErrorType();
}
});
} // MapWindow()
void initMap()
{
//m_tiledLayer = new Esri::ArcGISRuntime::ArcGISTiledLayer(QUrl("http://192.168.133.90:6080/arcgis/rest/services/BremenGeoTiffUTM/MapServer"));
Esri::ArcGISRuntime::TileCache * tpkCache = new Esri::ArcGISRuntime::TileCache("/usr/share/arcgis/resources/Topographic.tpk", this);
m_tiledLayer = new Esri::ArcGISRuntime::ArcGISTiledLayer(tpkCache);
m_basemap->baseLayers()->append(m_tiledLayer);
m_map->setBasemap(m_basemap);
Esri::ArcGISRuntime::GraphicsOverlayListModel * graphicsOverlayListModel = m_mapView->graphicsOverlays();
Esri::ArcGISRuntime::GraphicsOverlay * graphicalOverlay = new Esri::ArcGISRuntime::GraphicsOverlay();
graphicalOverlay->setSelectionColor(Qt::magenta);
graphicsOverlayListModel->append(graphicalOverlay);
m_mapView->setMap(m_map);
} // void initMap()
~MapWindow() = default;
void buildSymbol()
{
Esri::ArcGISRuntime::GraphicsOverlay * layer = new Esri::ArcGISRuntime::GraphicsOverlay(this);
m_mapView->graphicsOverlays()->append(layer);
//layer->setRenderingMode(Esri::ArcGISRuntime::GraphicsRenderingMode::Static);
layer->setRenderingMode(Esri::ArcGISRuntime::GraphicsRenderingMode::Dynamic);
Esri::ArcGISRuntime::PolygonBuilder builder( m_map->spatialReference() );
builder.addPoint( Esri::ArcGISRuntime::Point( 0, 0,m_map->spatialReference()) );
builder.addPoint( Esri::ArcGISRuntime::Point( 0,5878900,m_map->spatialReference()) );
builder.addPoint( Esri::ArcGISRuntime::Point(493200,5880900,m_map->spatialReference()) );
builder.addPoint( Esri::ArcGISRuntime::Point(495200, 0,m_map->spatialReference()) );
Esri::ArcGISRuntime::Graphic * graphic = new Esri::ArcGISRuntime::Graphic(this);
Esri::ArcGISRuntime::SimpleFillSymbol * simpleFillSym = new Esri::ArcGISRuntime::SimpleFillSymbol(this);
simpleFillSym->setColor( QColor("red") );
simpleFillSym->setStyle( Esri::ArcGISRuntime::SimpleFillSymbolStyle::Solid );
graphic->setGeometry( builder.toPolygon() );
graphic->setSymbol(simpleFillSym);
//add the graphic to the graphics overlay
layer->graphics()->append(graphic);
} // void buildSymbol()
void drawQGraphicPathItem()
{
QGraphicsScene * scene = m_mapView->scene();
QGraphicsPathItem * pathItem = scene->addPath( QPainterPath() );
QColor drawColor("darkblue");
QColor fillColor("green");
fillColor.setAlphaF( 0.5 );
pathItem -> setFlags( QGraphicsItem::ItemIgnoresTransformations );
pathItem -> setPen ( QPen(drawColor) );
pathItem -> setBrush ( QBrush(fillColor) );
pathItem -> setZValue( 100 );
QPainterPath painterPath;
painterPath.moveTo(QPointF(200,200));
painterPath.lineTo(QPointF(700,200));
painterPath.lineTo(QPointF(450,700));
painterPath.lineTo(QPointF(200,700));
painterPath.closeSubpath();
pathItem -> setPath( painterPath );
} // void drawQGraphicPathItem()
}; // MapWindow
int main(int argc, char* argv[])
{
QApplication app(argc,argv);
// ESRI :
#ifdef Q_OS_WIN
// Force usage of OpenGL ES through ANGLE on Windows
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
#endif
// : ESRI
MapWindow * mapWin = new MapWindow();
QDesktopWidget wid;
int width = mapWin->frameGeometry().width();
int height = mapWin->frameGeometry().height();
int screenWidth = wid.screen()->width();
int screenHeight = wid.screen()->height();
mapWin->setGeometry((screenWidth / 2) - (width / 2), (screenHeight / 2) - (height / 2), width, height);
mapWin->show();
app.setQuitOnLastWindowClosed(true);
int retval = app.exec();
delete mapWin;
return retval;
} // main