PageRenderTime 83ms CodeModel.GetById 46ms RepoModel.GetById 1ms app.codeStats 0ms

/src/providers/arcgisrest/qgsafsdataitemguiprovider.cpp

https://github.com/DelazJ/QGIS
C++ | 141 lines | 108 code | 16 blank | 17 comment | 18 complexity | 9c043a4d859086c769f496a33ff780f5 MD5 | raw file
Possible License(s): GPL-2.0, CC-BY-SA-3.0, MIT, 0BSD, BSD-3-Clause
  1. /***************************************************************************
  2. qgsafsdataitemguiprovider.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 "qgsafsdataitemguiprovider.h"
  16. #include "qgsafsdataitems.h"
  17. #include "qgsafssourceselect.h"
  18. #include "qgsnewhttpconnection.h"
  19. #include "qgsowsconnection.h"
  20. #include <QDesktopServices>
  21. #include <QMessageBox>
  22. void QgsAfsDataItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu *menu, const QList<QgsDataItem *> &, QgsDataItemGuiContext )
  23. {
  24. if ( QgsAfsRootItem *rootItem = qobject_cast< QgsAfsRootItem * >( item ) )
  25. {
  26. QAction *actionNew = new QAction( tr( "New Connection…" ), menu );
  27. connect( actionNew, &QAction::triggered, this, [rootItem] { newConnection( rootItem ); } );
  28. menu->addAction( actionNew );
  29. }
  30. else if ( QgsAfsConnectionItem *connectionItem = qobject_cast< QgsAfsConnectionItem * >( item ) )
  31. {
  32. QAction *actionRefresh = new QAction( tr( "Refresh" ), menu );
  33. connect( actionRefresh, &QAction::triggered, this, [connectionItem] { refreshConnection( connectionItem ); } );
  34. menu->addAction( actionRefresh );
  35. menu->addSeparator();
  36. QAction *actionEdit = new QAction( tr( "Edit Connection…" ), menu );
  37. connect( actionEdit, &QAction::triggered, this, [connectionItem] { editConnection( connectionItem ); } );
  38. menu->addAction( actionEdit );
  39. QAction *actionDelete = new QAction( tr( "Delete Connection…" ), menu );
  40. connect( actionDelete, &QAction::triggered, this, [connectionItem] { deleteConnection( connectionItem ); } );
  41. menu->addAction( actionDelete );
  42. QAction *viewInfo = new QAction( tr( "View Service Info" ), menu );
  43. connect( viewInfo, &QAction::triggered, this, [ = ]
  44. {
  45. QDesktopServices::openUrl( QUrl( connectionItem->url() ) );
  46. } );
  47. menu->addAction( viewInfo );
  48. }
  49. else if ( QgsAfsFolderItem *folderItem = qobject_cast< QgsAfsFolderItem * >( item ) )
  50. {
  51. QAction *viewInfo = new QAction( tr( "View Service Info" ), menu );
  52. connect( viewInfo, &QAction::triggered, this, [ = ]
  53. {
  54. QDesktopServices::openUrl( QUrl( folderItem->path() ) );
  55. } );
  56. menu->addAction( viewInfo );
  57. }
  58. else if ( QgsAfsServiceItem *serviceItem = qobject_cast< QgsAfsServiceItem * >( item ) )
  59. {
  60. QAction *viewInfo = new QAction( tr( "View Service Info" ), menu );
  61. connect( viewInfo, &QAction::triggered, this, [ = ]
  62. {
  63. QDesktopServices::openUrl( QUrl( serviceItem->path() ) );
  64. } );
  65. menu->addAction( viewInfo );
  66. }
  67. else if ( QgsAfsParentLayerItem *layerItem = qobject_cast< QgsAfsParentLayerItem * >( item ) )
  68. {
  69. QAction *viewInfo = new QAction( tr( "View Service Info" ), menu );
  70. connect( viewInfo, &QAction::triggered, this, [ = ]
  71. {
  72. QDesktopServices::openUrl( QUrl( layerItem->path() ) );
  73. } );
  74. menu->addAction( viewInfo );
  75. }
  76. else if ( QgsAfsLayerItem *layerItem = qobject_cast< QgsAfsLayerItem * >( item ) )
  77. {
  78. QAction *viewInfo = new QAction( tr( "View Service Info" ), menu );
  79. connect( viewInfo, &QAction::triggered, this, [ = ]
  80. {
  81. QDesktopServices::openUrl( QUrl( layerItem->path() ) );
  82. } );
  83. menu->addAction( viewInfo );
  84. menu->addSeparator();
  85. }
  86. }
  87. void QgsAfsDataItemGuiProvider::newConnection( QgsDataItem *item )
  88. {
  89. QgsNewHttpConnection nc( nullptr, QgsNewHttpConnection::ConnectionOther, QStringLiteral( "qgis/connections-arcgisfeatureserver/" ), QString(), QgsNewHttpConnection::FlagShowHttpSettings );
  90. nc.setWindowTitle( tr( "Create a New ArcGIS Feature Server Connection" ) );
  91. if ( nc.exec() )
  92. {
  93. item->refresh();
  94. }
  95. }
  96. void QgsAfsDataItemGuiProvider::editConnection( QgsDataItem *item )
  97. {
  98. QgsNewHttpConnection nc( nullptr, QgsNewHttpConnection::ConnectionOther, QStringLiteral( "qgis/connections-arcgisfeatureserver/" ), item->name(), QgsNewHttpConnection::FlagShowHttpSettings );
  99. nc.setWindowTitle( tr( "Modify ArcGIS Feature Server Connection" ) );
  100. if ( nc.exec() )
  101. {
  102. // the parent should be updated
  103. item->refresh();
  104. if ( item->parent() )
  105. item->parent()->refreshConnections();
  106. }
  107. }
  108. void QgsAfsDataItemGuiProvider::deleteConnection( QgsDataItem *item )
  109. {
  110. if ( QMessageBox::question( nullptr, QObject::tr( "Delete Connection" ),
  111. QObject::tr( "Are you sure you want to delete the connection to %1?" ).arg( item->name() ),
  112. QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
  113. return;
  114. QgsOwsConnection::deleteConnection( QStringLiteral( "arcgisfeatureserver" ), item->name() );
  115. // the parent should be updated
  116. if ( item->parent() )
  117. item->parent()->refreshConnections();
  118. }
  119. void QgsAfsDataItemGuiProvider::refreshConnection( QgsDataItem *item )
  120. {
  121. item->refresh();
  122. // the parent should be updated
  123. if ( item->parent() )
  124. item->parent()->refreshConnections();
  125. }