Skip to content
Draft
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
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ on:
pull_request:

jobs:
pyqt6-check:
uses: opengisch/qgis-plugin-ci/.github/workflows/pyqt6_test.yml@master
with:
plugin_path: document_management_system

test:
runs-on: ubuntu-latest

Expand Down
24 changes: 12 additions & 12 deletions document_management_system/core/document_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@


class Role(Enum):
RelationRole = Qt.UserRole + 1
RelationIdRole = Qt.UserRole + 2
AggregateRole = Qt.UserRole + 3
FieldRole = Qt.UserRole + 4
RelationRole = Qt.ItemDataRole.UserRole + 1
RelationIdRole = Qt.ItemDataRole.UserRole + 2
AggregateRole = Qt.ItemDataRole.UserRole + 3
FieldRole = Qt.ItemDataRole.UserRole + 4


class DocumentModel(QAbstractTableModel):

DocumentIdRole = Qt.UserRole + 1
DocumentPathRole = Qt.UserRole + 2
DocumentNameRole = Qt.UserRole + 3
DocumentExistsRole = Qt.UserRole + 4
DocumentToolTipRole = Qt.UserRole + 5
DocumentIsImageRole = Qt.UserRole + 6
DocumentIdRole = Qt.ItemDataRole.UserRole + 1
DocumentPathRole = Qt.ItemDataRole.UserRole + 2
DocumentNameRole = Qt.ItemDataRole.UserRole + 3
DocumentExistsRole = Qt.ItemDataRole.UserRole + 4
DocumentToolTipRole = Qt.ItemDataRole.UserRole + 5
DocumentIsImageRole = Qt.ItemDataRole.UserRole + 6

def __init__(self, parent: QObject = None):
super(DocumentModel, self).__init__(parent)
Expand Down Expand Up @@ -71,7 +71,7 @@ def headerData(self, section: int, orientation: Qt.Orientation, role: int = ...)
return None

def flags(self, index: QModelIndex) -> Qt.ItemFlags:
flags = Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsEditable
flags = Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemIsSelectable | Qt.ItemFlag.ItemIsEditable
return flags

def data(self, index: QModelIndex, role: int = ...):
Expand All @@ -80,7 +80,7 @@ def data(self, index: QModelIndex, role: int = ...):

return self._document_list[index.row()][role]

def setData(self, index: QModelIndex, value, role: int = Qt.EditRole) -> bool:
def setData(self, index: QModelIndex, value, role: int = Qt.ItemDataRole.EditRole) -> bool:
if index.row() < 0 or index.row() >= self.rowCount(QModelIndex()):
return False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
#
# -----------------------------------------------------------

from PyQt5.QtQuick import QQuickImageProvider
try:
from qgis.PyQt.QtQuick import QQuickImageProvider
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@3nids This resulted in an import error with my build, which i could not resolve. Is this try/except fine?

except ImportError:
from PyQt6.QtQuick import QQuickImageProvider

from qgis.PyQt.QtCore import QFileInfo
from qgis.PyQt.QtWidgets import QFileIconProvider


class FileTypeIconImageProvider(QQuickImageProvider):
def __init__(self, maxSize):
super().__init__(QQuickImageProvider.Pixmap)
super().__init__(QQuickImageProvider.ImageType.Pixmap)

self._maxSize = maxSize
self._provider = QFileIconProvider()
Expand Down
8 changes: 6 additions & 2 deletions document_management_system/core/preview_image_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
#
# -----------------------------------------------------------

from PyQt5.QtQuick import QQuickImageProvider
try:
from qgis.PyQt.QtQuick import QQuickImageProvider
except ImportError:
from PyQt6.QtQuick import QQuickImageProvider

from qgis.PyQt.QtCore import QMimeDatabase
from qgis.PyQt.QtGui import QImageReader


class PreviewImageProvider(QQuickImageProvider):

def __init__(self):
super().__init__(QQuickImageProvider.Image)
super().__init__(QQuickImageProvider.ImageType.Image)

# use an image reader to ensure image orientation and transforms are correctly handled
self._imageReader = QImageReader()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class TreeWidgetItemType(Enum):


class TreeWidgetItemRole(IntEnum):
Type = Qt.UserRole + 1
Layer = Qt.UserRole + 2
Feature = Qt.UserRole + 3
LinkFeature = Qt.UserRole + 4
Type = Qt.ItemDataRole.UserRole + 1
Layer = Qt.ItemDataRole.UserRole + 2
Feature = Qt.ItemDataRole.UserRole + 3
LinkFeature = Qt.ItemDataRole.UserRole + 4


class RelationEditorDocumentSideWidget(QgsAbstractRelationEditorWidget, WidgetUi):
Expand Down Expand Up @@ -87,14 +87,14 @@ def __init__(self, config, parent):
self.mToggleEditingToolButton.setDefaultAction(self.actionToggleEditing)
self.mSaveEditsToolButton.setDefaultAction(self.actionSaveEdits)
self.mShowFormToolButton.setDefaultAction(self.actionShowForm)
self.mShowFormToolButton.setToolButtonStyle(Qt.ToolButtonIconOnly)
self.mShowFormToolButton.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonIconOnly)
self.mLinkFeaturesToolButton.setDefaultAction(self.actionLinkFeature)
self.mLinkFeaturesToolButton.setToolButtonStyle(Qt.ToolButtonIconOnly)
self.mLinkFeaturesToolButton.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonIconOnly)
self.mUnlinkFeaturesToolButton.setDefaultAction(self.actionUnlinkFeature)
self.mUnlinkFeaturesToolButton.setToolButtonStyle(Qt.ToolButtonIconOnly)
self.mUnlinkFeaturesToolButton.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonIconOnly)

# TreeWidgetItem menu
self.mFeaturesTreeWidget.setContextMenuPolicy(Qt.ActionsContextMenu)
self.mFeaturesTreeWidget.setContextMenuPolicy(Qt.ContextMenuPolicy.ActionsContextMenu)
self.mFeaturesTreeWidget.addAction(self.actionShowForm)
self.mFeaturesTreeWidget.addAction(self.actionUnlinkFeature)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from qgis.PyQt.QtQuickWidgets import QQuickWidget
except ImportError:
# https://github.com/qgis/QGIS/pull/60123
from PyQt5.QtQuickWidgets import QQuickWidget
from qgis.PyQt.QtQuickWidgets import QQuickWidget
import os
from enum import Enum
from qgis.PyQt.QtCore import QDir, QTimer, QUrl, QVariant, pyqtSignal, pyqtProperty, pyqtSlot
Expand Down Expand Up @@ -123,7 +123,7 @@ def __init__(self, config, parent):
self.view.engine().addImageProvider("fileTypeSmallIconProvider", self._fileTypeSmallIconProvider)
self.view.engine().addImageProvider("fileTypeBigIconProvider", self._fileTypeBigIconProvider)
self.view.setSource(QUrl.fromLocalFile(os.path.join(os.path.dirname(__file__), "../qml/DocumentList.qml")))
self.view.setResizeMode(QQuickWidget.SizeRootObjectToView)
self.view.setResizeMode(QQuickWidget.ResizeMode.SizeRootObjectToView)
self.layout().addWidget(self.view)

# Set initial state for add / remove etc.buttons
Expand Down Expand Up @@ -331,15 +331,15 @@ def addDroppedDocument(self, fileUrl):
fields = self.relation().referencingLayer().fields()

# For generated relations insert the referenced layer field
if self.relation().type() == QgsRelation.Generated:
if self.relation().type() == QgsRelation.RelationType.Generated:
polyRel = self.relation().polymorphicRelation()
keyAttrs[fields.indexFromName(polyRel.referencedLayerField())] = polyRel.layerRepresentation(
self.relation().referencedLayer()
)

if self.nmRelation().isValid():
# only normal relations support m:n relation
if self.nmRelation().type() != QgsRelation.Normal:
if self.nmRelation().type() != QgsRelation.RelationType.Normal:
QMessageBox.critical(
self,
self.tr("Add document"),
Expand Down
1 change: 1 addition & 0 deletions document_management_system/metadata.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[general]
name=Document Management System
qgisMinimumVersion=3.18
qgisMaximumVersion=4.99
description=Provides an interface to handle document management system relations
about=Provides a an interface to handle document management system relations on both sides (document and object side). It supports both 1-N and N-M relations.
version=dev
Expand Down
26 changes: 12 additions & 14 deletions document_management_system/qml/DocumentList.qml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Dialogs 1.1
import QtQuick.Layouts 1.15
import QtQuick 6.5
import QtQuick.Controls 6.4
import QtQuick.Layouts 2.15
import QtQuick.Dialogs 6.5

Item {

Expand Down Expand Up @@ -99,18 +99,17 @@ Item {
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: {
listView.currentIndex = index
onClicked: function(mouse) {
gridView.currentIndex = index

if(mouse.button == Qt.RightButton)
{
if (mouse.button === Qt.RightButton) {
contextMenu.documentPath = DocumentPath
contextMenu.popup()
}
}
onDoubleClicked: DocumentExists ? Qt.openUrlExternally(DocumentPath)
: showMessageDialog(qsTr("Inexisting document"),
qsTr("Document '%1' does't exists.").arg(DocumentPath));
qsTr("Document '%1' doesn't exists.").arg(DocumentPath))
}
}
}
Expand Down Expand Up @@ -181,18 +180,17 @@ Item {
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: {
gridView.currentIndex = index
onClicked: function(mouse) {
listView.currentIndex = index

if(mouse.button == Qt.RightButton)
{
if (mouse.button === Qt.RightButton) {
contextMenu.documentPath = DocumentPath
contextMenu.popup()
}
}
onDoubleClicked: DocumentExists ? Qt.openUrlExternally(DocumentPath)
: showMessageDialog(qsTr("Inexisting document"),
qsTr("Document '%1' doesn't exists.").arg(DocumentPath))
qsTr("Document '%1' does't exists.").arg(DocumentPath));
}
}
}
Expand Down
Loading