Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
LETG
Rename bands
Commits
71f26e65
Commit
71f26e65
authored
Sep 14, 2021
by
PIERSON Julie
Browse files
removing unused buttons and color column in table widget
parent
caa9813e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
133 deletions
+96
-133
BandTableWidget.py
BandTableWidget.py
+94
-96
bandtablewidgetbase.ui
bandtablewidgetbase.ui
+2
-37
No files found.
BandTableWidget.py
View file @
71f26e65
...
...
@@ -56,9 +56,9 @@ class BandTableWidget(BASE, WIDGET):
self
.
btnRemove
.
setIcon
(
QgsApplication
.
getThemeIcon
(
'/symbologyRemove.svg'
))
self
.
btnUp
.
setIcon
(
QgsApplication
.
getThemeIcon
(
'/mActionArrowUp.svg'
))
self
.
btnDown
.
setIcon
(
QgsApplication
.
getThemeIcon
(
'/mActionArrowDown.svg'
))
self
.
btnLoad
.
setIcon
(
QgsApplication
.
getThemeIcon
(
'/mActionFileOpen.svg'
))
self
.
btnSave
.
setIcon
(
QgsApplication
.
getThemeIcon
(
'/mActionFileSave.svg'
))
self
.
btnAuto
.
setIcon
(
QgsApplication
.
getThemeIcon
(
'/mActionReload.svg'
))
#
self.btnLoad.setIcon(QgsApplication.getThemeIcon('/mActionFileOpen.svg'))
#
self.btnSave.setIcon(QgsApplication.getThemeIcon('/mActionFileSave.svg'))
#
self.btnAuto.setIcon(QgsApplication.getThemeIcon('/mActionReload.svg'))
self
.
layer
=
None
...
...
@@ -67,7 +67,7 @@ class BandTableWidget(BASE, WIDGET):
item
=
QTreeWidgetItem
()
item
.
setText
(
0
,
'0.00'
)
item
.
setText
(
1
,
'0.00'
)
item
.
setBackground
(
2
,
QBrush
(
QColor
(
127
,
127
,
127
)))
#
item.setBackground(2, QBrush(QColor(127, 127, 127)))
self
.
bandClassTree
.
addTopLevelItem
(
item
)
@
pyqtSlot
()
...
...
@@ -97,75 +97,75 @@ class BandTableWidget(BASE, WIDGET):
self
.
bandClassTree
.
insertTopLevelItem
(
currentIndex
-
1
,
item
)
self
.
bandClassTree
.
setCurrentItem
(
item
)
@
pyqtSlot
()
def
on_btnLoad_clicked
(
self
):
fileName
,
_
=
QFileDialog
.
getOpenFileName
(
None
,
self
.
tr
(
'Import Colors and elevations from XML'
),
QDir
.
homePath
(),
self
.
tr
(
'XML files (*.xml *.XML)'
))
if
fileName
==
''
:
return
doc
=
QDomDocument
()
with
codecs
.
open
(
fileName
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
content
=
f
.
read
()
if
not
doc
.
setContent
(
content
):
QMessageBox
.
critical
(
None
,
self
.
tr
(
'Error parsing XML'
),
self
.
tr
(
'The XML file could not be loaded'
))
return
self
.
bandClassTree
.
clear
()
reliefColorList
=
doc
.
elementsByTagName
(
'ReliefColor'
)
for
i
in
range
(
reliefColorList
.
length
()):
elem
=
reliefColorList
.
at
(
i
).
toElement
()
item
=
QTreeWidgetItem
()
item
.
setText
(
0
,
elem
.
attribute
(
'MinElevation'
))
item
.
setText
(
1
,
elem
.
attribute
(
'MaxElevation'
))
item
.
setBackground
(
2
,
QBrush
(
QColor
(
int
(
elem
.
attribute
(
'red'
)),
int
(
elem
.
attribute
(
'green'
)),
int
(
elem
.
attribute
(
'blue'
)))))
self
.
bandClassTree
.
addTopLevelItem
(
item
)
@
pyqtSlot
()
def
on_btnSave_clicked
(
self
):
fileName
,
_
=
QFileDialog
.
getSaveFileName
(
None
,
self
.
tr
(
'Export Colors and elevations as XML'
),
QDir
.
homePath
(),
self
.
tr
(
'XML files (*.xml *.XML)'
))
if
fileName
==
''
:
return
if
not
fileName
.
lower
().
endswith
(
'.xml'
):
fileName
+=
'.xml'
doc
=
QDomDocument
()
colorsElem
=
doc
.
createElement
(
'ReliefColors'
)
doc
.
appendChild
(
colorsElem
)
colors
=
self
.
reliefColors
()
for
c
in
colors
:
elem
=
doc
.
createElement
(
'ReliefColor'
)
elem
.
setAttribute
(
'MinElevation'
,
str
(
c
.
minElevation
))
elem
.
setAttribute
(
'MaxElevation'
,
str
(
c
.
maxElevation
))
elem
.
setAttribute
(
'red'
,
str
(
c
.
color
.
red
()))
elem
.
setAttribute
(
'green'
,
str
(
c
.
color
.
green
()))
elem
.
setAttribute
(
'blue'
,
str
(
c
.
color
.
blue
()))
colorsElem
.
appendChild
(
elem
)
with
codecs
.
open
(
fileName
,
'w'
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
doc
.
toString
(
2
))
@
pyqtSlot
()
def
on_btnAuto_clicked
(
self
):
if
self
.
layer
is
None
:
return
relief
=
QgsRelief
(
self
.
layer
,
system
.
getTempFilename
(),
'GTiff'
)
colors
=
relief
.
calculateOptimizedReliefClasses
()
self
.
populateColors
(
colors
)
#
@pyqtSlot()
#
def on_btnLoad_clicked(self):
#
fileName, _ = QFileDialog.getOpenFileName(None,
#
self.tr('Import Colors and elevations from XML'),
#
QDir.homePath(),
#
self.tr('XML files (*.xml *.XML)'))
#
if fileName == '':
#
return
#
#
doc = QDomDocument()
#
with codecs.open(fileName, 'r', encoding='utf-8') as f:
#
content = f.read()
#
#
if not doc.setContent(content):
#
QMessageBox.critical(None,
#
self.tr('Error parsing XML'),
#
self.tr('The XML file could not be loaded'))
#
return
#
#
self.bandClassTree.clear()
#
reliefColorList = doc.elementsByTagName('ReliefColor')
#
for i in range(reliefColorList.length()):
#
elem = reliefColorList.at(i).toElement()
#
item = QTreeWidgetItem()
#
item.setText(0, elem.attribute('MinElevation'))
#
item.setText(1, elem.attribute('MaxElevation'))
#
item.setBackground(2, QBrush(QColor(int(elem.attribute('red')),
#
int(elem.attribute('green')),
#
int(elem.attribute('blue')))))
#
self.bandClassTree.addTopLevelItem(item)
#
#
@pyqtSlot()
#
def on_btnSave_clicked(self):
#
fileName, _ = QFileDialog.getSaveFileName(None,
#
self.tr('Export Colors and elevations as XML'),
#
QDir.homePath(),
#
self.tr('XML files (*.xml *.XML)'))
#
#
if fileName == '':
#
return
#
#
if not fileName.lower().endswith('.xml'):
#
fileName += '.xml'
#
#
doc = QDomDocument()
#
colorsElem = doc.createElement('ReliefColors')
#
doc.appendChild(colorsElem)
#
#
colors = self.reliefColors()
#
for c in colors:
#
elem = doc.createElement('ReliefColor')
#
elem.setAttribute('MinElevation', str(c.minElevation))
#
elem.setAttribute('MaxElevation', str(c.maxElevation))
#
elem.setAttribute('red', str(c.color.red()))
#
elem.setAttribute('green', str(c.color.green()))
#
elem.setAttribute('blue', str(c.color.blue()))
#
colorsElem.appendChild(elem)
#
#
with codecs.open(fileName, 'w', encoding='utf-8') as f:
#
f.write(doc.toString(2))
#
#
@pyqtSlot()
#
def on_btnAuto_clicked(self):
#
if self.layer is None:
#
return
#
#
relief = QgsRelief(self.layer, system.getTempFilename(), 'GTiff')
#
colors = relief.calculateOptimizedReliefClasses()
#
self.populateColors(colors)
@
pyqtSlot
(
QTreeWidgetItem
,
int
)
def
on_bandClassTree_itemDoubleClicked
(
self
,
item
,
column
):
...
...
@@ -188,32 +188,31 @@ class BandTableWidget(BASE, WIDGET):
decimals
=
2
)
if
ok
:
item
.
setText
(
1
,
str
(
d
))
elif
column
==
2
:
c
=
QColorDialog
.
getColor
(
item
.
background
(
2
).
color
(),
None
,
self
.
tr
(
'Select color for relief class'
))
if
c
.
isValid
():
item
.
setBackground
(
2
,
QBrush
(
c
))
#
elif column == 2:
#
c = QColorDialog.getColor(item.background(2).color(),
#
None,
#
self.tr('Select color for relief class'))
#
if c.isValid():
#
item.setBackground(2, QBrush(c))
def
reliefColors
(
self
):
colors
=
[]
for
i
in
range
(
self
.
bandClassTree
.
topLevelItemCount
()):
item
=
self
.
bandClassTree
.
topLevelItem
(
i
)
if
item
:
c
=
QgsRelief
.
ReliefColor
(
item
.
background
(
2
).
color
(),
float
(
item
.
text
(
0
)),
c
=
QgsRelief
.
ReliefColor
(
float
(
item
.
text
(
0
)),
float
(
item
.
text
(
1
)))
colors
.
append
(
c
)
return
colors
def
populateColors
(
self
,
colors
):
self
.
bandClassTree
.
clear
()
for
c
in
colors
:
item
=
QTreeWidgetItem
()
item
.
setText
(
0
,
str
(
c
.
minElevation
))
item
.
setText
(
1
,
str
(
c
.
maxElevation
))
item
.
setBackground
(
2
,
QBrush
(
c
.
color
))
self
.
bandClassTree
.
addTopLevelItem
(
item
)
#
def populateColors(self, colors):
#
self.bandClassTree.clear()
#
for c in colors:
#
item = QTreeWidgetItem()
#
item.setText(0, str(c.minElevation))
#
item.setText(1, str(c.maxElevation))
#
item.setBackground(2, QBrush(c.color))
#
self.bandClassTree.addTopLevelItem(item)
def
setLayer
(
self
,
layer
):
self
.
layer
=
layer
...
...
@@ -226,19 +225,18 @@ class BandTableWidget(BASE, WIDGET):
item
=
QTreeWidgetItem
()
item
.
setText
(
0
,
v
[
0
])
item
.
setText
(
1
,
v
[
1
])
color
=
QColor
(
int
(
v
[
2
]),
int
(
v
[
3
]),
int
(
v
[
4
]))
item
.
setBackground
(
2
,
QBrush
(
color
))
#
color = QColor(int(v[2]), int(v[3]), int(v[4]))
#
item.setBackground(2, QBrush(color))
self
.
bandClassTree
.
addTopLevelItem
(
item
)
def
value
(
self
):
rColors
=
self
.
reliefColors
()
colors
=
''
for
c
in
rColors
:
colors
+=
'{:f}, {:f}, {:d}, {:d}, {:d};'
.
format
(
c
.
minElevation
,
c
.
maxElevation
,
c
.
color
.
red
(),
c
.
color
.
green
(),
c
.
color
.
blue
())
colors
+=
'{:f}, {:f};'
.
format
(
c
.
minElevation
,
c
.
maxElevation
)
# c.color.red(),
# c.color.green(),
# c.color.blue())
return
colors
[:
-
1
]
...
...
bandtablewidgetbase.ui
View file @
71f26e65
...
...
@@ -18,17 +18,12 @@
<widget
class=
"QTreeWidget"
name=
"bandClassTree"
>
<column>
<property
name=
"text"
>
<string>
Lower bound
</string>
<string>
Band name
</string>
</property>
</column>
<column>
<property
name=
"text"
>
<string>
Upper bound
</string>
</property>
</column>
<column>
<property
name=
"text"
>
<string>
Color
</string>
<string>
Band future name
</string>
</property>
</column>
</widget>
...
...
@@ -88,36 +83,6 @@
</property>
</spacer>
</item>
<item>
<widget
class=
"QToolButton"
name=
"btnLoad"
>
<property
name=
"toolTip"
>
<string>
Load colors from file
</string>
</property>
<property
name=
"text"
>
<string>
…
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"QToolButton"
name=
"btnSave"
>
<property
name=
"toolTip"
>
<string>
Save colors to file
</string>
</property>
<property
name=
"text"
>
<string>
…
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"QToolButton"
name=
"btnAuto"
>
<property
name=
"toolTip"
>
<string>
Generate color table automatically
</string>
</property>
<property
name=
"text"
>
<string>
…
</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment