Skip to content

Commit

Permalink
Refactor icon usage for re-usability
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishcampbell committed Aug 11, 2024
1 parent 874bc84 commit 4d5a2c6
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 150 deletions.
15 changes: 4 additions & 11 deletions kart/gui/conflictsdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from qgis.PyQt import uic
from qgis.PyQt.QtCore import QSize, Qt
from qgis.PyQt.QtGui import QIcon, QFont
from qgis.PyQt.QtGui import QFont
from qgis.PyQt.QtWidgets import (
QDialog,
QTreeWidgetItem,
Expand All @@ -17,16 +17,9 @@
QTreeWidgetItemIterator,
)

pluginPath = os.path.split(os.path.dirname(__file__))[0]
from kart.gui import icons


def icon(f):
return QIcon(os.path.join(pluginPath, "img", f))


layerIcon = icon("layer.png")
featureIcon = icon("layer.png")

WIDGET, BASE = uic.loadUiType(
os.path.join(os.path.dirname(__file__), "conflictsdialog.ui")
)
Expand Down Expand Up @@ -84,7 +77,7 @@ def fillConflictsTree(self):
for path, conflicts in self.conflicts.items():
topItem = QTreeWidgetItem()
topItem.setText(0, path)
topItem.setIcon(0, layerIcon)
topItem.setIcon(0, icons.layerIcon)
self.treeConflicts.addTopLevelItem(topItem)
self.treeItems[path] = {}
for fid, conflict in conflicts.items():
Expand Down Expand Up @@ -352,7 +345,7 @@ class ConflictItem(QTreeWidgetItem):
def __init__(self, path, fid, conflict):
QTreeWidgetItem.__init__(self)
self.setText(0, fid)
self.setIcon(0, featureIcon)
self.setIcon(0, icons.featureIcon)
self.setSizeHint(0, QSize(self.sizeHint(0).width(), 25))
self.conflict = conflict
self.fid = fid
Expand Down
25 changes: 8 additions & 17 deletions kart/gui/diffviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from qgis.PyQt import uic
from qgis.PyQt.QtCore import Qt, pyqtSignal
from qgis.PyQt.QtGui import QIcon, QColor, QBrush
from qgis.PyQt.QtGui import QColor, QBrush
from qgis.PyQt.QtWidgets import (
QVBoxLayout,
QTableWidgetItem,
Expand Down Expand Up @@ -35,6 +35,8 @@
from qgis.gui import QgsMapCanvas, QgsMessageBar, QgsMapToolPan

from .mapswipetool import MapSwipeTool

from kart.gui import icons
from kart.utils import setting, DIFFSTYLES

ADDED, MODIFIED, REMOVED, UNCHANGED = 0, 1, 2, 3
Expand All @@ -53,17 +55,6 @@
pluginPath = os.path.split(os.path.dirname(__file__))[0]


def icon(f):
return QIcon(os.path.join(pluginPath, "img", f))


vectorDatasetIcon = icon("vector-polyline.png")
tableIcon = icon("table.png")
featureIcon = icon("geometry.png")
addedIcon = icon("add.png")
removedIcon = icon("remove.png")
modifiedIcon = icon("edit.png")

pointsStyle = os.path.join(
pluginPath, "resources", "diff_styles", "geomdiff_points.qml"
)
Expand Down Expand Up @@ -311,13 +302,13 @@ def fillTree(self):
datasetItem = DatasetItem(dataset, crs is None)
addedItem = QTreeWidgetItem()
addedItem.setText(0, "Added")
addedItem.setIcon(0, addedIcon)
addedItem.setIcon(0, icons.addedIcon)
removedItem = QTreeWidgetItem()
removedItem.setText(0, "Removed")
removedItem.setIcon(0, removedIcon)
removedItem.setIcon(0, icons.removeIcon)
modifiedItem = QTreeWidgetItem()
modifiedItem.setText(0, "Modified")
modifiedItem.setIcon(0, modifiedIcon)
modifiedItem.setIcon(0, icons.modifiedIcon)

subItems = {"I": addedItem, "U": modifiedItem, "D": removedItem}
changes = {feat["id"]: feat for feat in changes}
Expand Down Expand Up @@ -627,7 +618,7 @@ def _recoverVersion(self, layer):
class FeatureItem(QTreeWidgetItem):
def __init__(self, fid, old, new, dataset):
QTreeWidgetItem.__init__(self)
self.setIcon(0, featureIcon)
self.setIcon(0, icons.featureIcon)
self.setText(0, fid)
self.old = old
self.new = new
Expand All @@ -639,7 +630,7 @@ class DatasetItem(QTreeWidgetItem):
def __init__(self, dataset, isTable):
QTreeWidgetItem.__init__(self)
self.dataset = dataset
self.setIcon(0, tableIcon if isTable else vectorDatasetIcon)
self.setIcon(0, icons.tableIcon if isTable else icons.vectorDatasetIcon)
self.setText(0, dataset)


Expand Down
101 changes: 40 additions & 61 deletions kart/gui/dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from qgis.PyQt import uic
from qgis.PyQt.QtCore import Qt, QMimeData, QByteArray, QDataStream, QIODevice

from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import (
QDockWidget,
QTreeWidgetItem,
Expand Down Expand Up @@ -32,6 +31,7 @@
KartException,
checkKartInstalled,
)
from kart.gui import icons
from kart.gui.diffviewer import DiffViewerDialog
from kart.gui.historyviewer import HistoryDialog
from kart.gui.conflictsdialog import ConflictsDialog
Expand All @@ -54,35 +54,6 @@

pluginPath = os.path.split(os.path.dirname(__file__))[0]


def icon(f):
return QIcon(os.path.join(pluginPath, "img", f))


repoIcon = icon("repository.png")
addRepoIcon = icon("addrepo.png")
createRepoIcon = icon("createrepo.png")
cloneRepoIcon = icon("clone.png")
logIcon = icon("log.png")
importIcon = icon("import.png")
checkoutIcon = icon("checkout.png")
commitIcon = icon("commit.png")
discardIcon = icon("reset.png")
datasetIcon = icon("dataset.png")
vectorDatasetIcon = icon("vector-polyline.png")
tableIcon = icon("table.png")
mergeIcon = icon("merge.png")
addtoQgisIcon = icon("openinqgis.png")
diffIcon = icon("changes.png")
abortIcon = icon("abort.png")
resolveIcon = icon("resolve.png")
pushIcon = icon("push.png")
pullIcon = icon("pull.png")
removeIcon = icon("remove.png")
refreshIcon = icon("refresh.png")
propertiesIcon = icon("info.png")
patchIcon = icon("patch.png")

WIDGET, BASE = uic.loadUiType(os.path.join(os.path.dirname(__file__), "dockwidget.ui"))


Expand Down Expand Up @@ -172,7 +143,7 @@ def wrapper():
class RefreshableItem(QTreeWidgetItem):
def actions(self):
actions = [
("Refresh", self.refreshContent, refreshIcon),
("Refresh", self.refreshContent, icons.refreshIcon),
("divider", None, None),
]
actions.extend(self._actions())
Expand All @@ -188,7 +159,7 @@ def __init__(self):
QTreeWidgetItem.__init__(self)

self.setText(0, "Repositories")
self.setIcon(0, repoIcon)
self.setIcon(0, icons.repoIcon)
self.setChildIndicatorPolicy(QTreeWidgetItem.ShowIndicator)

self.populate()
Expand All @@ -202,9 +173,9 @@ def populate(self):

def _actions(self):
actions = [
("Add existing repository...", self.addRepo, addRepoIcon),
("Create new repository...", self.createRepo, createRepoIcon),
("Clone repository...", self.cloneRepo, cloneRepoIcon),
("Add existing repository...", self.addRepo, icons.addRepoIcon),
("Create new repository...", self.createRepo, icons.createRepoIcon),
("Clone repository...", self.cloneRepo, icons.cloneRepoIcon),
]

return actions
Expand Down Expand Up @@ -284,7 +255,7 @@ def __init__(self, repo):
self.populated = False

self.setTitle()
self.setIcon(0, repoIcon)
self.setIcon(0, icons.repoIcon)
self.setChildIndicatorPolicy(QTreeWidgetItem.ShowIndicator)

def refreshContent(self):
Expand Down Expand Up @@ -323,44 +294,52 @@ def actions(self):
if self.repo.isMerging():
actions.extend(
[
("Resolve conflicts...", self.resolveConflicts, resolveIcon),
("Continue merge", self.continueMerge, mergeIcon),
("Abort merge", self.abortMerge, abortIcon),
("Resolve conflicts...", self.resolveConflicts, icons.resolveIcon),
("Continue merge", self.continueMerge, icons.mergeIcon),
("Abort merge", self.abortMerge, icons.abortIcon),
]
)
else:
actions.extend(
[
("Show log...", self.showLog, logIcon),
("Show working copy changes...", self.showChanges, diffIcon),
("Discard working copy changes", self.discardChanges, discardIcon),
("Commit working copy changes...", self.commitChanges, commitIcon),
("Switch branch...", self.switchBranch, checkoutIcon),
("Merge into current branch...", self.mergeBranch, mergeIcon),
("Show log...", self.showLog, icons.logIcon),
("Show working copy changes...", self.showChanges, icons.diffIcon),
(
"Discard working copy changes",
self.discardChanges,
icons.discardIcon,
),
(
"Commit working copy changes...",
self.commitChanges,
icons.commitIcon,
),
("Switch branch...", self.switchBranch, icons.checkoutIcon),
("Merge into current branch...", self.mergeBranch, icons.mergeIcon),
("divider", None, None),
("Pull...", self.pull, pullIcon),
("Push...", self.push, pushIcon),
("Pull...", self.pull, icons.pullIcon),
("Push...", self.push, icons.pushIcon),
("divider", None, None),
(
"Import dataset from file...",
self.importLayerFromFile,
importIcon,
icons.importIcon,
),
(
"Import dataset from database...",
self.importLayerFromDatabase,
importIcon,
icons.importIcon,
),
("Apply patch...", self.applyPatch, patchIcon),
("Apply patch...", self.applyPatch, icons.patchIcon),
]
)

actions.extend(
[
("divider", None, None),
("Refresh", self.refreshContent, refreshIcon),
("Properties...", self.showProperties, propertiesIcon),
("Remove this repository", self.removeRepository, removeIcon),
("Refresh", self.refreshContent, icons.refreshIcon),
("Properties...", self.showProperties, icons.propertiesIcon),
("Remove this repository", self.removeRepository, icons.removeIcon),
]
)

Expand Down Expand Up @@ -624,7 +603,7 @@ def __init__(self, repo):
self.repo = repo

self.setText(0, "Datasets")
self.setIcon(0, datasetIcon)
self.setIcon(0, icons.datasetIcon)

self.populate()

Expand All @@ -650,32 +629,32 @@ def __init__(self, name, repo, isTable):
self.isTable = isTable

self.setText(0, name)
self.setIcon(0, tableIcon if isTable else vectorDatasetIcon)
self.setIcon(0, icons.tableIcon if isTable else icons.vectorDatasetIcon)

def actions(self):
actions = [("Add to QGIS project", self.addToProject, addtoQgisIcon)]
actions = [("Add to QGIS project", self.addToProject, icons.addtoQgisIcon)]
if not self.repo.isMerging():
actions.extend(
[
("divider", None, None),
("Show log...", self.showLog, logIcon),
("Show log...", self.showLog, icons.logIcon),
(
"Show working copy changes for this dataset...",
self.showChanges,
diffIcon,
icons.diffIcon,
),
(
"Discard working copy changes for this dataset",
self.discardChanges,
discardIcon,
icons.discardIcon,
),
(
"Commit working copy changes for this dataset...",
self.commitChanges,
commitIcon,
icons.commitIcon,
),
("divider", None, None),
("Remove from repository", self.removeFromRepo, removeIcon),
("Remove from repository", self.removeFromRepo, icons.removeIcon),
]
)

Expand Down
Loading

0 comments on commit 4d5a2c6

Please sign in to comment.