Skip to content

Commit

Permalink
Update results display (#278)
Browse files Browse the repository at this point in the history
* investigate #276

* update md title generation

* no more deformation + tweaking

* Update results display

* set row minimum height

* Update date and title display

close#276
  • Loading branch information
SimonSAMPERE committed Oct 22, 2019
1 parent f856098 commit ef314ce
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
45 changes: 27 additions & 18 deletions modules/results/display.py
Expand Up @@ -8,15 +8,9 @@

# PyQT
# from QByteArray
from qgis.PyQt.QtCore import QSettings, QObject, pyqtSignal
from qgis.PyQt.QtCore import QSettings, QObject, pyqtSignal, Qt
from qgis.PyQt.QtGui import QIcon, QPixmap
from qgis.PyQt.QtWidgets import (
QTableWidgetItem,
QComboBox,
QPushButton,
QLabel,
QHeaderView,
)
from qgis.PyQt.QtWidgets import QTableWidgetItem, QComboBox, QPushButton, QLabel

# Plugin modules
from .cache import CacheManager
Expand Down Expand Up @@ -124,6 +118,14 @@ def show_results(self, api_results, pg_connections=dict()):
else:
tbl_result.setRowCount(api_results.get("total"))

# dimensions
hheader = tbl_result.horizontalHeader()
hheader.setSectionResizeMode(1)
hheader.setSectionResizeMode(1, 3)
hheader.setSectionResizeMode(2, 3)

vheader = tbl_result.verticalHeader()

# Looping inside the table lines. For each of them, showing the title,
# abstract, geometry type, and a button that allow to add the data
# to the canvas.
Expand All @@ -141,18 +143,22 @@ def show_results(self, api_results, pg_connections=dict()):

# COLUMN 1 - Title and abstract
# Displaying the metadata title inside a button
btn_md_title = QPushButton(plg_tools.format_button_title(md_title))
btn_title = plg_tools.format_button_title(md_title)
btn_md_title = QPushButton(btn_title)
# Connecting the button to the full metadata popup
btn_md_title.pressed.connect(partial(self.md_asked.emit, md_id))
# Putting the abstract as a tooltip on this button
btn_md_title.setToolTip(i.get("abstract", "")[:300])
# Insert it in column 1
tbl_result.setCellWidget(count, 0, btn_md_title)


# COLUMN 2 - Data last update
tbl_result.setItem(
count, 1, QTableWidgetItem(plg_tools.handle_date(i.get("_modified")))
)
lbl_date = QLabel(tbl_result)
lbl_date.setText(plg_tools.handle_date(i.get("_modified")))
lbl_date.setMargin(5)
lbl_date.setAlignment(Qt.AlignCenter)
tbl_result.setCellWidget(count, 1, lbl_date)

# COLUMN 3 - Geometry type
lbl_geom = QLabel(tbl_result)
Expand Down Expand Up @@ -193,7 +199,7 @@ def show_results(self, api_results, pg_connections=dict()):
lbl_geom.setToolTip(
self.tr("Unknown geometry", context=__class__.__name__)
)

lbl_geom.setAlignment(Qt.AlignCenter)
tbl_result.setCellWidget(count, 2, lbl_geom)

# COLUMN 4 - Add options
Expand Down Expand Up @@ -456,12 +462,15 @@ def show_results(self, api_results, pg_connections=dict()):
combo.model().sort(0) # sort alphabetically on option prefix. see: #113
tbl_result.setCellWidget(count, 3, combo)

# make the widget (button or combobox) width the same as the column width
tbl_result.cellWidget(count, 3).setFixedWidth(hheader.sectionSize(3))
count += 1
# dimensions
header = tbl_result.horizontalHeader()
header.setSectionResizeMode(0, QHeaderView.Stretch)
header.setSectionResizeMode(1, QHeaderView.ResizeToContents)
header.setSectionResizeMode(2, QHeaderView.ResizeToContents)

# dimensions bis
hheader.setSectionResizeMode(3, 3)

vheader.setMinimumSectionSize(30)
vheader.setSectionResizeMode(3)
# method ending
return None

Expand Down
6 changes: 0 additions & 6 deletions modules/search_form.py
Expand Up @@ -364,12 +364,6 @@ def init_steps(self):
""" Called by Isogeo.search_slot method in case of reset or "_default"
quicksearch. It initialise the widgets that don't need to be updated
"""
self.tbl_result.horizontalHeader().setSectionResizeMode(1)
self.tbl_result.horizontalHeader().setSectionResizeMode(1, 0)
self.tbl_result.horizontalHeader().setSectionResizeMode(2, 0)
self.tbl_result.horizontalHeader().resizeSection(1, 80)
self.tbl_result.horizontalHeader().resizeSection(2, 50)
self.tbl_result.verticalHeader().setSectionResizeMode(3)
# Geographical operator cbb
self.cbb_geo_op.clear()
for key in self.dict_operation.keys():
Expand Down
7 changes: 5 additions & 2 deletions modules/tools.py
Expand Up @@ -72,8 +72,11 @@ def format_button_title(self, title):
:param str title: title to format
"""
words = title.split(" ")
if len(words) == 1 and len(words[0]) > 22:
final_text = "\n" + words[0][:19] + "..."
if len(words) == 1:
if len(words[0]) > 28:
final_text = words[0][:25] + "..."
else:
final_text = words[0]
return final_text
else:
pass
Expand Down

0 comments on commit ef314ce

Please sign in to comment.