Skip to content

Commit

Permalink
include red and green field colour wishlist.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samweli committed Nov 22, 2024
1 parent 41d740c commit 0170794
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
2 changes: 2 additions & 0 deletions LDMP/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# API related constants
API_URL = "https://api2.trends.earth"
TIMEOUT = 30


6 changes: 6 additions & 0 deletions LDMP/definitions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

# Styles

GREEN_HIGHLIGHT = "border: 1px solid green;"
RED_HIGHLIGHT = "border: 1px solid red;"

6 changes: 3 additions & 3 deletions LDMP/gui/DlgDatasetMetadata.ui
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<item row="4" column="0">
<widget class="QTextEdit" name="te_author">
<property name="readOnly">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
Expand All @@ -77,7 +77,7 @@
<item row="12" column="0">
<widget class="QTextEdit" name="te_citation">
<property name="readOnly">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
Expand All @@ -98,7 +98,7 @@
<item row="10" column="0">
<widget class="QLineEdit" name="le_source">
<property name="readOnly">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
Expand Down
54 changes: 54 additions & 0 deletions LDMP/metadata_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from qgis.PyQt import QtWidgets
from qgis.PyQt import uic

from .definitions import GREEN_HIGHLIGHT, RED_HIGHLIGHT

Ui_DlgDatasetMetadata, _ = uic.loadUiType(
str(Path(__file__).parents[0] / "gui/DlgDatasetMetadata.ui")
)
Expand Down Expand Up @@ -67,6 +69,11 @@ def __init__(self, parent=None):
self.btn_add_default_category.clicked.connect(self.add_default_categories)
self.btn_remove_category.clicked.connect(self.remove_categories)

self.le_title.textChanged.connect(self.update_style)
self.te_author.textChanged.connect(self.update_style)
self.le_source.textChanged.connect(self.update_style)
self.te_citation.textChanged.connect(self.update_style)

def add_new_category(self):
text, ok = QtWidgets.QInputDialog.getText(
self,
Expand Down Expand Up @@ -127,15 +134,62 @@ def update_ui(self):
if self.metadata.title():
self.le_title.setText(self.metadata.title())

if self.metadata.abstract():
self.te_citation.setText(self.metadata.abstract())

if self.metadata.identifier():
self.le_source.setText(self.metadata.identifier())

contacts = self.metadata.contacts()
if len(contacts) > 0:
contact = contacts[0]
self.te_author.setPlainText(contact.name)

self.categories_model.setStringList(self.metadata.categories())

self.update_style()

def update_style(self):

self.le_title.setStyleSheet(GREEN_HIGHLIGHT) \
if self.le_title.text() != "" else (
self.le_title.setStyleSheet(RED_HIGHLIGHT))


self.te_author.setStyleSheet(GREEN_HIGHLIGHT) \
if self.te_author.toPlainText() != "" else (
self.te_author.setStyleSheet(RED_HIGHLIGHT))

self.le_source.setStyleSheet(GREEN_HIGHLIGHT) \
if self.le_source.text() != "" else (
self.le_source.setStyleSheet(RED_HIGHLIGHT))

self.te_citation.setStyleSheet(GREEN_HIGHLIGHT) \
if self.te_citation.toPlainText() != "" else (
self.te_citation.setStyleSheet(RED_HIGHLIGHT))


def save_metadata(self):
if self.metadata is None:
self.metadata = qgis.core.QgsLayerMetadata()

self.metadata.setTitle(self.le_title.text())
self.metadata.setEncoding("UTF-8")

self.metadata.setAbstract(self.te_citation.toPlainText())

self.metadata.setIdentifier(self.le_source.text())

contacts = self.metadata.contacts()
if len(contacts) > 0:
del contacts[0]

contact = qgis.core.QgsAbstractMetadataBase.Contact()
contact.name = self.te_author.toPlainText()
contacts.insert(0, contact)

self.metadata.setContacts(contacts)

if self.categories_model.rowCount() > 0:
self.metadata.setKeywords(
{"gmd:topicCategory": self.categories_model.stringList()}
Expand Down

0 comments on commit 0170794

Please sign in to comment.