PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/src/providers/arcgisrest/qgsamsdataitemguiprovider.cpp

https://github.com/DelazJ/QGIS
C++ | 128 lines | 98 code | 15 blank | 15 comment | 15 complexity | 38fc190fe0d530962123c16640ca6ccf MD5 | raw file
Possible License(s): GPL-2.0, CC-BY-SA-3.0, MIT, 0BSD, BSD-3-Clause
  1. /***************************************************************************
  2. qgsamsdataitemguiprovider.cpp
  3. --------------------------------------
  4. Date : June 2019
  5. Copyright : (C) 2019 by Martin Dobias
  6. Email : wonder dot sk at gmail dot com
  7. ***************************************************************************
  8. * *
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License as published by *
  11. * the Free Software Foundation; either version 2 of the License, or *
  12. * (at your option) any later version. *
  13. * *
  14. ***************************************************************************/
  15. #include "qgsamsdataitemguiprovider.h"
  16. #include "qgsamsdataitems.h"
  17. #include "qgsnewhttpconnection.h"
  18. #include "qgsowsconnection.h"
  19. #include <QDesktopServices>
  20. #include <QMessageBox>
  21. void QgsAmsDataItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu *menu, const QList<QgsDataItem *> &, QgsDataItemGuiContext )
  22. {
  23. if ( QgsAmsRootItem *rootItem = qobject_cast< QgsAmsRootItem * >( item ) )
  24. {
  25. QAction *actionNew = new QAction( tr( "New Connection…" ), menu );
  26. connect( actionNew, &QAction::triggered, this, [rootItem] { newConnection( rootItem ); } );
  27. menu->addAction( actionNew );
  28. }
  29. if ( QgsAmsConnectionItem *connectionItem = qobject_cast< QgsAmsConnectionItem * >( item ) )
  30. {
  31. QAction *actionRefresh = new QAction( tr( "Refresh" ), menu );
  32. connect( actionRefresh, &QAction::triggered, this, [connectionItem] { refreshConnection( connectionItem ); } );
  33. menu->addAction( actionRefresh );
  34. menu->addSeparator();
  35. QAction *actionEdit = new QAction( tr( "Edit Connection…" ), menu );
  36. connect( actionEdit, &QAction::triggered, this, [connectionItem] { editConnection( connectionItem ); } );
  37. menu->addAction( actionEdit );
  38. QAction *actionDelete = new QAction( tr( "Delete Connection…" ), menu );
  39. connect( actionDelete, &QAction::triggered, this, [connectionItem] { deleteConnection( connectionItem ); } );
  40. menu->addAction( actionDelete );
  41. QAction *viewInfo = new QAction( tr( "View Service Info" ), menu );
  42. connect( viewInfo, &QAction::triggered, this, [ = ]
  43. {
  44. QDesktopServices::openUrl( QUrl( connectionItem->url() ) );
  45. } );
  46. menu->addAction( viewInfo );
  47. }
  48. else if ( QgsAmsFolderItem *folderItem = qobject_cast< QgsAmsFolderItem * >( item ) )
  49. {
  50. QAction *viewInfo = new QAction( tr( "View Service Info" ), menu );
  51. connect( viewInfo, &QAction::triggered, this, [ = ]
  52. {
  53. QDesktopServices::openUrl( QUrl( folderItem->path() ) );
  54. } );
  55. menu->addAction( viewInfo );
  56. }
  57. else if ( QgsAmsServiceItem *serviceItem = qobject_cast< QgsAmsServiceItem * >( item ) )
  58. {
  59. QAction *viewInfo = new QAction( tr( "View Service Info" ), menu );
  60. connect( viewInfo, &QAction::triggered, this, [ = ]
  61. {
  62. QDesktopServices::openUrl( QUrl( serviceItem->path() ) );
  63. } );
  64. menu->addAction( viewInfo );
  65. }
  66. else if ( QgsAmsLayerItem *layerItem = qobject_cast< QgsAmsLayerItem * >( item ) )
  67. {
  68. QAction *viewInfo = new QAction( tr( "View Service Info" ), menu );
  69. connect( viewInfo, &QAction::triggered, this, [ = ]
  70. {
  71. QDesktopServices::openUrl( QUrl( layerItem->path() ) );
  72. } );
  73. menu->addAction( viewInfo );
  74. menu->addSeparator();
  75. }
  76. }
  77. void QgsAmsDataItemGuiProvider::newConnection( QgsDataItem *item )
  78. {
  79. QgsNewHttpConnection nc( nullptr, QgsNewHttpConnection::ConnectionOther, QStringLiteral( "qgis/connections-arcgismapserver/" ), QString(), QgsNewHttpConnection::FlagShowHttpSettings );
  80. nc.setWindowTitle( tr( "Create a New ArcGIS Map Server Connection" ) );
  81. if ( nc.exec() )
  82. {
  83. item->refreshConnections();
  84. }
  85. }
  86. void QgsAmsDataItemGuiProvider::editConnection( QgsDataItem *item )
  87. {
  88. QgsNewHttpConnection nc( nullptr, QgsNewHttpConnection::ConnectionOther, QStringLiteral( "qgis/connections-arcgismapserver/" ), item->name(), QgsNewHttpConnection::FlagShowHttpSettings );
  89. nc.setWindowTitle( tr( "Modify ArcGIS Map Server Connection" ) );
  90. if ( nc.exec() )
  91. {
  92. item->refresh();
  93. if ( item->parent() )
  94. item->parent()->refreshConnections();
  95. }
  96. }
  97. void QgsAmsDataItemGuiProvider::deleteConnection( QgsDataItem *item )
  98. {
  99. if ( QMessageBox::question( nullptr, QObject::tr( "Delete Connection" ),
  100. QObject::tr( "Are you sure you want to delete the connection to %1?" ).arg( item->name() ),
  101. QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
  102. return;
  103. QgsOwsConnection::deleteConnection( QStringLiteral( "arcgismapserver" ), item->name() );
  104. if ( item->parent() )
  105. item->parent()->refreshConnections();
  106. }
  107. void QgsAmsDataItemGuiProvider::refreshConnection( QgsDataItem *item )
  108. {
  109. item->refresh();
  110. // the parent should be updated
  111. if ( item->parent() )
  112. item->parent()->refreshConnections();
  113. }