Skip to content

Commit 059075a

Browse files
committed
[ui] Improve image gallery (fix issues raised by copilot)
1 parent d5a38b8 commit 059075a

File tree

5 files changed

+84
-127
lines changed

5 files changed

+84
-127
lines changed

meshroom/core/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ def loadClasses(folder: str, packageName: str, classType: type) -> list[type]:
119119
classes.append(p)
120120
except Exception as exc:
121121
if classType == BaseSubmitter:
122-
logging.warning(f" Could not load submitter {pluginName} from package '{package.__name__}'")
123-
logging.warning(exc)
122+
logging.warning(f" Could not load submitter {pluginName} from package '{package.__name__}'\n{exc}")
124123
else:
125124
tb = traceback.extract_tb(exc.__traceback__)
126125
last_call = tb[-1]

meshroom/ui/qml/ImageGallery/ImageDelegate.qml

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Item {
2020
property int layoutMode: 0 // 0: grid, 1: list
2121

2222
property variant parentModel
23-
property int selectedIndex: parentModel.selectedIndex
23+
property int selectedIndex: parentModel ? parentModel.selectedIndex : -1
2424
property bool isCurrentItem: cellID >= 0 && cellID === selectedIndex
2525

2626
signal pressed(var mouse)
@@ -124,20 +124,6 @@ Item {
124124
sourceComponent: root.layoutMode === 0 ? gridDelegate : listDelegate
125125
}
126126

127-
Component {
128-
id: thumbnailItem
129-
Image {
130-
id: thumbnail
131-
anchors.fill: parent
132-
anchors.margins: 4
133-
asynchronous: true
134-
autoTransform: true
135-
fillMode: Image.PreserveAspectFit
136-
smooth: false
137-
cache: false
138-
}
139-
}
140-
141127
Component {
142128
id: gridDelegate
143129
ColumnLayout {
@@ -212,39 +198,26 @@ Item {
212198
Rectangle {
213199
color: Qt.darker(list_imageLabel.palette.base, 1.15)
214200
Layout.fillHeight: true
215-
Layout.preferredWidth: 24 + list_thumbnail.width + 4
201+
Layout.preferredWidth: 100
216202

217203
border.color: isCurrentItem ? list_imageLabel.palette.highlight : Qt.darker(list_imageLabel.palette.highlight)
218204
border.width: imageMA.containsMouse || root.isCurrentItem ? 2 : 0
219205

220-
RowLayout {
206+
Image {
207+
id: list_thumbnail
221208
anchors.fill: parent
222209
anchors.margins: 4
223-
spacing: 4
224-
225-
BusyIndicator {
226-
id: list_busyIndicator
227-
Layout.preferredWidth: childrenRect.width
228-
Layout.preferredHeight: childrenRect.height
229-
running: list_thumbnail.status != Image.Ready
230-
}
231-
232-
Item {
233-
Layout.fillWidth: true
234-
}
235-
236-
Image {
237-
id: list_thumbnail
238-
Layout.preferredWidth: 100
239-
Layout.fillHeight: true
240-
source: root.thumbnailSource
241-
asynchronous: true
242-
autoTransform: true
243-
fillMode: Image.PreserveAspectFit
244-
smooth: false
245-
cache: false
246-
onStatusChanged: root.thumbnailStatus = status
247-
}
210+
source: root.thumbnailSource
211+
asynchronous: true
212+
autoTransform: true
213+
fillMode: Image.PreserveAspectFit
214+
smooth: false
215+
cache: false
216+
onStatusChanged: root.thumbnailStatus = status
217+
}
218+
BusyIndicator {
219+
anchors.centerIn: parent
220+
running: list_thumbnail.status != Image.Ready
248221
}
249222
}
250223

meshroom/ui/qml/ImageGallery/ImageGallery.qml

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ Panel {
3131
property bool readOnly: false
3232

3333
enum LayoutModes {
34-
Thumbnail=0,
34+
Grid=0,
3535
List=1
3636
}
3737

38-
property int displayMode: ImageGallery.LayoutModes.Thumbnail
39-
property string nextDisplayModeName: "List"
38+
property int displayMode: ImageGallery.LayoutModes.Grid
39+
property int defaultCellWidth: displayMode === ImageGallery.LayoutModes.Grid ? 160 : 400
40+
property int defaultCellHeight: displayMode === ImageGallery.LayoutModes.Grid ? 160 : thumbnailSizeSlider.value / 2
4041

4142
property var filesByType: ({})
4243
property int nbMeshroomScenes: 0
@@ -133,13 +134,8 @@ Panel {
133134
}
134135

135136
function toggleDisplayMode() {
136-
if (displayMode === ImageGallery.LayoutModes.Thumbnail) {
137-
displayMode = ImageGallery.LayoutModes.List
138-
nextDisplayModeName = "Thumbnail"
139-
} else {
140-
displayMode = ImageGallery.LayoutModes.Thumbnail
141-
nextDisplayModeName = "List"
142-
}
137+
displayMode = displayMode === ImageGallery.LayoutModes.Grid ?
138+
ImageGallery.LayoutModes.List : ImageGallery.LayoutModes.Grid
143139
}
144140

145141
headerBar: RowLayout {
@@ -151,10 +147,10 @@ Panel {
151147
}
152148

153149
MaterialToolButton {
154-
text: root.displayMode == ImageGallery.LayoutModes.Thumbnail ? MaterialIcons.view_list : MaterialIcons.view_module
150+
text: root.displayMode === ImageGallery.LayoutModes.Grid ? MaterialIcons.view_list : MaterialIcons.view_module
155151
font.pointSize: 11
156152
padding: 2
157-
ToolTip.text: "Switch the layout to " + nextDisplayModeName
153+
ToolTip.text: "Switch the layout to " + root.displayMode === ImageGallery.LayoutModes.Grid ? "List" : "Grid"
158154
ToolTip.visible: hovered
159155
onClicked: root.toggleDisplayMode()
160156
}
@@ -223,13 +219,13 @@ Panel {
223219
roleName = roleNameAndCmd[0]
224220
cmd = roleNameAndCmd[1]
225221
}
226-
if (cmd == "isReconstructed")
222+
if (cmd === "isReconstructed")
227223
return _reconstruction.isReconstructed(item.model.object);
228224

229225
var value = item.model.object.childAttribute(roleName).value;
230-
if (cmd == "basename")
226+
if (cmd === "basename")
231227
return Filepath.basename(value);
232-
if (cmd == "asString")
228+
if (cmd === "asString")
233229
return value.toString();
234230

235231
return value
@@ -243,16 +239,8 @@ Panel {
243239
layoutMode: root.displayMode
244240
viewpoint: object.value
245241
cellID: DelegateModel.filteredIndex
246-
width: layoutMode === ImageGallery.LayoutModes.Thumbnail ?
247-
(layoutLoader.item ? layoutLoader.item.cellWidth : 160) :
248-
(layoutLoader.item ? layoutLoader.item.width : 400)
249-
height: {
250-
if (layoutMode === ImageGallery.LayoutModes.Thumbnail) {
251-
return layoutLoader.item ? layoutLoader.item.cellHeight : 160
252-
} else {
253-
return thumbnailSizeSlider.value / 2
254-
}
255-
}
242+
width: layoutLoader.item ? layoutLoader.item.cellWidth : root.defaultCellWidth
243+
height: layoutLoader.item ? layoutLoader.item.cellHeight : root.defaultCellHeight
256244

257245
readOnly: m.readOnly
258246
displayViewId: displayViewIdsAction.checked
@@ -362,13 +350,13 @@ Panel {
362350
Layout.fillHeight: true
363351
visible: !intrinsicsFilterButton.checked
364352

365-
sourceComponent: root.displayMode === ImageGallery.LayoutModes.Thumbnail ? gridViewComponent : listViewComponent
353+
sourceComponent: root.displayMode === ImageGallery.LayoutModes.Grid ? gridViewComponent : listViewComponent
366354

367355
onLoaded: {
368356
if (item) {
369357
// Pass necessary properties to the loaded component
370358
item.m = m
371-
item.root = root
359+
item.gallery = root
372360
item.searchBar = searchBar
373361
item.displayViewIdsAction = displayViewIdsAction
374362
item.intrinsicsFilterButton = intrinsicsFilterButton

meshroom/ui/qml/ImageGallery/ImageGridView.qml

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ImageGridView.qml
2-
31
import QtQuick
42
import QtQuick.Controls
53
import QtQuick.Layouts
@@ -11,11 +9,11 @@ import MaterialIcons 2.2
119
import Utils 1.0
1210

1311
GridView {
14-
id: grid
12+
id: root
1513

16-
// Exposed properties from parent - with default values
14+
// Exposed properties from ImageGallery
1715
property var m: null
18-
property var root: null
16+
property var gallery: null
1917
property var searchBar: null
2018
property var thumbnailSizeSlider: null
2119
property var displayViewIdsAction: null
@@ -39,49 +37,48 @@ GridView {
3937
cellHeight: cellWidth
4038
highlightFollowsCurrentItem: true
4139
keyNavigationEnabled: true
42-
property bool updateSelectedViewFromGrid: true
4340

4441
// Update grid current item when selected view changes
4542
Connections {
4643
target: _reconstruction
4744
function onSelectedViewIdChanged() {
4845
if (_reconstruction.selectedViewId > -1) {
49-
grid.updateCurrentIndexFromSelectionViewId()
46+
root.updateCurrentIndexFromSelectionViewId()
5047
}
5148
}
5249
}
5350

5451
function makeCurrentItemVisible() {
55-
grid.positionViewAtIndex(grid.currentIndex, GridView.Visible)
52+
root.positionViewAtIndex(root.currentIndex, GridView.Visible)
5653
}
5754

5855
function updateCurrentIndexFromSelectionViewId() {
5956
if (!sortedModel) return
6057
var idx = sortedModel.find(_reconstruction.selectedViewId, "viewId")
61-
if (idx >= 0 && grid.currentIndex !== idx) {
62-
grid.currentIndex = idx
58+
if (idx >= 0 && root.currentIndex !== idx) {
59+
root.currentIndex = idx
6360
}
6461
}
6562

6663
onCurrentItemChanged: {
67-
if (grid.updateSelectedViewFromGrid && grid.currentItem) {
68-
if (tempCameraInit !== null && grid.currentIndex == 0)
64+
if (root.currentItem) {
65+
if (tempCameraInit !== null && root.currentIndex == 0)
6966
_reconstruction.selectedViewId = -1
70-
_reconstruction.selectedViewId = grid.currentItem.viewpoint.get("viewId").value
67+
_reconstruction.selectedViewId = root.currentItem.viewpoint.get("viewId").value
7168
}
7269
}
7370

7471
// Update grid item when corresponding thumbnail is computed
7572
Connections {
7673
target: ThumbnailCache
7774
function onThumbnailCreated(imgSource, callerID) {
78-
let item = grid.itemAtIndex(callerID);
75+
let item = root.itemAtIndex(callerID);
7976
if (item && item.source === imgSource) {
8077
item.updateThumbnail()
8178
return
8279
}
83-
for (let idx = 0; idx < grid.count; idx++) {
84-
item = grid.itemAtIndex(idx)
80+
for (let idx = 0; idx < root.count; idx++) {
81+
item = root.itemAtIndex(idx)
8582
if (item && item.source === imgSource) {
8683
item.updateThumbnail()
8784
}
@@ -95,25 +92,25 @@ GridView {
9592
Keys.priority: Keys.BeforeItem
9693
Keys.onPressed: function(event) {
9794
if (event.modifiers & Qt.AltModifier) {
98-
if (event.key === Qt.Key_Right && root && root.cameraInits) {
99-
_reconstruction.cameraInitIndex = Math.min(root.cameraInits.count - 1, root.cameraInitIndex + 1)
95+
if (event.key === Qt.Key_Right && gallery && gallery.cameraInits) {
96+
_reconstruction.cameraInitIndex = Math.min(gallery.cameraInits.count - 1, gallery.cameraInitIndex + 1)
10097
event.accepted = true
10198
} else if (event.key === Qt.Key_Left) {
102-
_reconstruction.cameraInitIndex = Math.max(0, root.cameraInitIndex - 1)
99+
_reconstruction.cameraInitIndex = Math.max(0, gallery.cameraInitIndex - 1)
103100
event.accepted = true
104101
}
105102
} else {
106103
if (event.key === Qt.Key_Right) {
107-
grid.moveCurrentIndexRight()
104+
root.moveCurrentIndexRight()
108105
event.accepted = true
109106
} else if (event.key === Qt.Key_Left) {
110-
grid.moveCurrentIndexLeft()
107+
root.moveCurrentIndexLeft()
111108
event.accepted = true
112109
} else if (event.key === Qt.Key_Up) {
113-
grid.moveCurrentIndexUp()
110+
root.moveCurrentIndexUp()
114111
event.accepted = true
115112
} else if (event.key === Qt.Key_Down) {
116-
grid.moveCurrentIndexDown()
113+
root.moveCurrentIndexDown()
117114
event.accepted = true
118115
} else if (event.key === Qt.Key_Tab) {
119116
if (searchBar)
@@ -144,7 +141,7 @@ GridView {
144141
Column {
145142
id: noImageImagePlaceholder
146143
anchors.centerIn: parent
147-
visible: (m && m.viewpoints ? m.viewpoints.count !== 0 : false) && !dropImagePlaceholder.visible && grid.count === 0 && (!intrinsicsFilterButton || !intrinsicsFilterButton.checked)
144+
visible: (m && m.viewpoints ? m.viewpoints.count !== 0 : false) && !dropImagePlaceholder.visible && root.count === 0 && (!intrinsicsFilterButton || !intrinsicsFilterButton.checked)
148145
spacing: 4
149146
Label {
150147
anchors.horizontalCenter: parent.horizontalCenter
@@ -173,9 +170,9 @@ GridView {
173170
nbMeshroomScenes = filesByType["meshroomScenes"].length
174171
}
175172
onDropped: function(drop) {
176-
if (nbMeshroomScenes == nbDraggedFiles || nbMeshroomScenes == 0) {
177-
if (root)
178-
root.filesDropped(filesByType)
173+
if (nbMeshroomScenes === nbDraggedFiles || nbMeshroomScenes === 0) {
174+
if (gallery)
175+
gallery.filesDropped(filesByType)
179176
} else {
180177
if (errorDialog)
181178
errorDialog.open()
@@ -186,7 +183,7 @@ GridView {
186183
Rectangle {
187184
visible: dropArea.containsDrag
188185
anchors.fill: parent
189-
color: root ? root.palette.window : palette.window
186+
color: gallery ? gallery.palette.window : palette.window
190187
opacity: 0.8
191188
}
192189

@@ -222,7 +219,7 @@ GridView {
222219
anchors.fill: parent
223220
onPressed: function(mouse) {
224221
if (mouse.button == Qt.LeftButton)
225-
grid.forceActiveFocus()
222+
root.forceActiveFocus()
226223
mouse.accepted = false
227224
}
228225
}

0 commit comments

Comments
 (0)