Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions InfoTools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
import os
import subprocess
import sys
import tempfile
from qgis.PyQt import QtWidgets
from qgis.PyQt.QtCore import QRectF, QDateTime, QSettings
from qgis.PyQt.QtGui import QColor, QFont
from qgis.PyQt.QtWidgets import QFileDialog, QApplication
from qgis._core import QgsLayoutExporter, QgsWkbTypes, QgsLayoutItemMap, \
QgsLayout, QgsProject, QgsUnitTypes, QgsLayoutSize, QgsGeometry, \
QgsVectorLayer, QgsFeature, QgsSymbol, QgsSimpleFillSymbolLayer, \
QgsLayoutItemLegend, QgsLayerTreeGroup, QgsLegendStyle, QgsLayoutItem, \
QgsLayoutItemLabel, QgsLayoutItemScaleBar, QgsRectangle, QgsPointXY, QgsIdentifyContext
from qgis._gui import QgsRubberBand, QgisInterface, QgsMapToolIdentifyFeature, QgsMapCanvas, QgsMapToolIdentify
from qgis.utils import iface
from typing import Union

from .InfoToolsDialog import InfoToolsDialog
from .utils import tr, CustomMessageBox, normalize_path
from .config import Config

class InfoTool:
def __init__(self, iface: QgisInterface, parent: QtWidgets = None) -> None:
self.iface = iface
self.dialog = InfoToolsDialog()
self.canvas = self.iface.mapCanvas()
self.dialog.identify_feature.triggered.connect(self.activate_identify_tool)
def run(self) -> None:
self.dialog.show()

def activate_identify_tool(self):
self.tool = IdentifyFeatureTool(self.canvas)
self.canvas.setMapTool(self.tool)


class IdentifyFeatureTool(QgsMapToolIdentifyFeature):

def __init__(self, canvas: QgsMapCanvas):
super().__init__(canvas)
self.canvas = canvas

def canvasReleaseEvent(self, event):
point = self.toMapCoordinates(event.pos())
print(point[0],"elo",point[1])
self.identify_features(point)
def identify_features(self, point: QgsPointXY):
identify_result = QgsMapToolIdentifyFeature.identify(int(point[0]), int(point[1]),self.canvas.layers(True),
QgsMapToolIdentify.DefaultQgsSetting,
QgsIdentifyContext())


for result in identify_result:
layer = result.layerId()
feature = result.feature()
print(f"Warstwa: {layer}, ID: {feature.id()}, Atrybuty: {feature.attributes()}")
33 changes: 33 additions & 0 deletions InfoToolsDialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
import os

from PyQt5.QtWidgets import QMenu
from qgis.PyQt import QtWidgets, uic, QtCore


FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'karta_informacjna_dialog.ui'))


class InfoToolsDialog(QtWidgets.QDialog, FORM_CLASS):
def __init__(self, parent : QtWidgets=None) -> None:
"""Constructor."""
super(InfoToolsDialog, self).__init__(parent)
self.setupUi(self)

self.menu = QMenu(self)

self.identify_feature = self.menu.addAction("Identify Feature(s)")

self.selectObjectPushButton.setMenu(self.menu)
# self.menu.addAction("Identify Feature(s) on Mouse Over")
# self.selectObjectPushButton.setMenu(self.menu)
#
# self.menu.addAction("Identify Features by Polygon")
# self.selectObjectPushButton.setMenu(self.menu)
#
# self.menu.addAction("Identify Features Freehand ")
# self.selectObjectPushButton.setMenu(self.menu)
#
# self.menu.addAction("Identify Features by Radius")
# self.selectObjectPushButton.setMenu(self.menu)
5 changes: 5 additions & 0 deletions giap_dynamic_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from qgis.utils import iface
from qgis.gui import QgsMapTool

from .InfoTools import InfoTool
from .OrtoTools import OrtoAddingTool
from .QuickPrint import PrintMapTool
from .SectionManager.CustomSectionManager import CustomSectionManager
Expand Down Expand Up @@ -857,6 +858,10 @@ def set_custom_action(self) -> None:
self.tbut.setToolTip(tr("Map quick print"))
if oname == "giapMyPrints":
self.tbut.setToolTip(tr("My Prints"))
if oname == 'giapInfoCard':
self.info_card = InfoTool(iface)
self.tbut.setToolTip(tr("Info card"))
self.tbut.clicked.connect(self.info_card.run)
if oname == "giapAreaLength":
giap_tool_bar = iface.mainWindow().findChildren(QToolBar, 'GiapToolBar')[0]
main_widget = giap_tool_bar.findChildren(MainWidget)[0]
Expand Down
9 changes: 8 additions & 1 deletion giap_dynamic_layout.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>1291</width>
<height>178</height>
<height>171</height>
</rect>
</property>
<property name="minimumSize">
Expand Down Expand Up @@ -308,6 +308,13 @@ for the street: Warszawa, Pasaż Ursynowski</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="infoCardButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down
10 changes: 10 additions & 0 deletions giap_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,19 @@ def initGui(self) -> None:
area_length_tool.setAction(self.main_widget.area_length_action)
self.main_widget.runArea.setDefaultAction(self.main_widget.area_length_action)

info_card_tool = QgsMapTool(self.iface.mapCanvas())
info_card_tool.setAction(self.main_widget.area_length_action)
self.main_widget.runArea.setDefaultAction(self.main_widget.area_length_action)

orto_button = self.main_widget.runOrtoTool
orto_button.setIcon(QIcon(os.path.join(self.plugin_dir, 'icons', 'orto_icon2.png')))
self.orto = OrtoAddingTool(self.main_widget, orto_button)

# self.main_widget.infoCardButton.clicked.connect(
# lambda: self.off_on_search_tool(self.visibility_search_tool))
# self.main_widget.infoCardButton.setIcon(
# QIcon(os.path.join(self.plugin_dir, 'icons', 'karta_info.png')))

self.visibility_search_tool = False
self.main_widget.offOnSearchButton.clicked.connect(
lambda: self.off_on_search_tool(self.visibility_search_tool))
Expand Down Expand Up @@ -266,6 +275,7 @@ def load_ribbons(self) -> None:
if not ribbon_conf:
ribbon_conf = RIBBON_DEFAULT
for dtab in ribbon_conf:
# raise
itab, tab = self.main_widget.add_tab(dtab['tab_name'])
for dsec in dtab['sections']:
sec = self.main_widget.add_section(
Expand Down
5 changes: 5 additions & 0 deletions i18n/giap_pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,11 @@ Proszę czekać...</translation>
<source>Area and length</source>
<translation>Powierzchnia i długość</translation>
</message>
<message>
<location filename="../giap_layout.py" line="221"/>
<source>Info card</source>
<translation>info card</translation>
</message>
<message>
<location filename="../giap_dynamic_layout.py" line="132"/>
<source>Do you want to save your changes?</source>
Expand Down
Binary file added icons/karta_info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading