Skip to content

Commit f05ca34

Browse files
authored
PopupView respects showAttachments and thumbnail size. (#405)
* PopupView respects showAttachments. * Adding bindings for thumbnail width/height.
1 parent 6169714 commit f05ca34

File tree

4 files changed

+176
-23
lines changed

4 files changed

+176
-23
lines changed

uitools/cpp/Esri/ArcGISRuntime/Toolkit/PopupViewController.cpp

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ void PopupViewController::setPopupManager(PopupManager* popupManager)
9090
{
9191
connect(attachments, &QAbstractListModel::rowsInserted , this, &PopupViewController::attachmentCountChanged);
9292
connect(attachments, &QAbstractListModel::rowsRemoved , this, &PopupViewController::attachmentCountChanged);
93+
connect(attachments, &PopupAttachmentListModel::thumbnailWidthChanged , this, &PopupViewController::attachmentThumbnailWidthChanged);
94+
connect(attachments, &PopupAttachmentListModel::thumbnailHeightChanged , this, &PopupViewController::attachmentThumbnailHeightChanged);
9395
}
9496

9597
if (auto displayFields = this->displayFields())
@@ -101,6 +103,8 @@ void PopupViewController::setPopupManager(PopupManager* popupManager)
101103
emit popupManagerChanged();
102104
emit fieldCountChanged();
103105
emit attachmentCountChanged();
106+
emit attachmentThumbnailHeightChanged();
107+
emit attachmentThumbnailWidthChanged();
104108
}
105109

106110
/*!
@@ -118,7 +122,7 @@ QAbstractListModel* PopupViewController::displayFields() const
118122
Popup associated with this PopupManager.
119123
\note This can be null.
120124
*/
121-
QAbstractListModel* PopupViewController::attachments() const
125+
PopupAttachmentListModel* PopupViewController::attachments() const
122126
{
123127
if (!m_popupManager)
124128
return nullptr;
@@ -158,6 +162,18 @@ int PopupViewController::attachmentCount() const
158162
return 0;
159163
}
160164

165+
/*!
166+
\brief Returns whether attachments should be displayed or not
167+
according to the PopupManager.
168+
*/
169+
bool PopupViewController::isShowAttachments() const
170+
{
171+
// This is re-exposed from PopupManager as PopupManager does not have
172+
// NOTIFY/CONSTANT modifiers on its showAttachments property, so the Controller
173+
// re-exposes showAttachments to suppress warnings about this.
174+
return m_popupManager ? m_popupManager->isShowAttachments() : false;
175+
}
176+
161177
/*!
162178
\brief Returns the title of the \c PopupManager.
163179
*/
@@ -169,6 +185,54 @@ QString PopupViewController::title() const
169185
return m_popupManager ? m_popupManager->title() : nullptr;
170186
}
171187

188+
/*!
189+
\brief Returns the minimum attachment thumbnail width.
190+
*/
191+
int PopupViewController::attachmentThumbnailWidth() const
192+
{
193+
auto attachmentModel = attachments();
194+
if (!attachmentModel)
195+
return 0;
196+
197+
return attachmentModel->thumbnailWidth();
198+
}
199+
200+
/*!
201+
\brief Sets the minimum attachment thumbnail width.
202+
*/
203+
void PopupViewController::setAttachmentThumbnailWidth(int width)
204+
{
205+
auto attachmentModel = attachments();
206+
if (!attachmentModel)
207+
return;
208+
209+
attachmentModel->setThumbnailWidth(width);
210+
}
211+
212+
/*!
213+
\brief Returns the minimum attachment thumbnail width.
214+
*/
215+
int PopupViewController::attachmentThumbnailHeight() const
216+
{
217+
auto attachmentModel = attachments();
218+
if (!attachmentModel)
219+
return 0;
220+
221+
return attachmentModel->thumbnailHeight();
222+
}
223+
224+
/*!
225+
\brief Sets the minimum attachment thumbnail height.
226+
*/
227+
void PopupViewController::setAttachmentThumbnailHeight(int height)
228+
{
229+
auto attachmentModel = attachments();
230+
if (!attachmentModel)
231+
return;
232+
233+
attachmentModel->setThumbnailHeight(height);
234+
}
235+
172236
/*!
173237
\fn void Esri::ArcGISRuntime::Toolkit::PopupViewController::popupManagerChanged()
174238
\brief Signal emitted when the \c PopupManager changes.
@@ -186,6 +250,29 @@ QString PopupViewController::title() const
186250
changes.
187251
*/
188252

253+
/*!
254+
\fn void Esri::ArcGISRuntime::Toolkit::PopupViewController::attachmentWidthChanged()
255+
\brief Signal emitted when the attachment minimum width changes.
256+
*/
257+
258+
/*!
259+
\fn void Esri::ArcGISRuntime::Toolkit::PopupViewController::attachmentHeightChanged()
260+
\brief Signal emitted when the attachment minimum height changes.
261+
*/
262+
263+
264+
/*!
265+
\property Esri::ArcGISRuntime::Toolkit::PopupViewController::showAttachments
266+
*/
267+
268+
/*!
269+
\property Esri::ArcGISRuntime::Toolkit::PopupViewController::attachmentThumbnailWidth
270+
*/
271+
272+
/*!
273+
\property Esri::ArcGISRuntime::Toolkit::PopupViewController::attachmentThumbnailHeight
274+
*/
275+
189276
/*!
190277
\property Esri::ArcGISRuntime::Toolkit::PopupViewController::popupManager
191278
*/

uitools/cpp/Esri/ArcGISRuntime/Toolkit/PopupViewController.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ namespace Toolkit
3535
class PopupViewController : public QObject
3636
{
3737
Q_OBJECT
38-
3938
Q_PROPERTY(PopupManager* popupManager READ popupManager WRITE setPopupManager NOTIFY popupManagerChanged)
39+
Q_PROPERTY(QString title READ title NOTIFY popupManagerChanged)
4040
Q_PROPERTY(QAbstractListModel* displayFields READ displayFields NOTIFY popupManagerChanged)
4141
Q_PROPERTY(int fieldCount READ fieldCount NOTIFY fieldCountChanged)
4242
Q_PROPERTY(QAbstractListModel* attachments READ attachments NOTIFY popupManagerChanged)
4343
Q_PROPERTY(int attachmentCount READ attachmentCount NOTIFY attachmentCountChanged)
44-
Q_PROPERTY(QString title READ title NOTIFY popupManagerChanged)
44+
Q_PROPERTY(bool showAttachments READ isShowAttachments NOTIFY popupManagerChanged)
45+
Q_PROPERTY(int attachmentThumbnailWidth READ attachmentThumbnailWidth WRITE setAttachmentThumbnailWidth NOTIFY attachmentThumbnailWidthChanged)
46+
Q_PROPERTY(int attachmentThumbnailHeight READ attachmentThumbnailHeight WRITE setAttachmentThumbnailHeight NOTIFY attachmentThumbnailHeightChanged)
4547

4648
public:
4749
Q_INVOKABLE explicit PopupViewController(QObject* parent = nullptr);
@@ -54,10 +56,18 @@ class PopupViewController : public QObject
5456

5557
QAbstractListModel* displayFields() const;
5658

57-
QAbstractListModel* attachments() const;
59+
PopupAttachmentListModel* attachments() const;
5860

5961
QString title() const;
6062

63+
bool isShowAttachments() const;
64+
65+
int attachmentThumbnailWidth() const;
66+
void setAttachmentThumbnailWidth(int width);
67+
68+
int attachmentThumbnailHeight() const;
69+
void setAttachmentThumbnailHeight(int height);
70+
6171
signals:
6272

6373
void popupManagerChanged();
@@ -66,6 +76,10 @@ class PopupViewController : public QObject
6676

6777
void attachmentCountChanged();
6878

79+
void attachmentThumbnailWidthChanged();
80+
81+
void attachmentThumbnailHeightChanged();
82+
6983
private:
7084
int fieldCount() const;
7185

uitools/import/Esri/ArcGISRuntime/Toolkit/Controller/PopupViewController.qml

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,42 +33,60 @@ QtObject {
3333

3434
/*!
3535
\brief The PopupManager that populates this controller with data.
36-
*/
36+
*/
3737
property var popupManager: null
3838

3939
/*!
4040
\brief A list model containing the key/value fields of the
4141
Popup associated with this PopupManager.
4242
\note This can be null.
43-
*/
43+
*/
4444
readonly property alias displayFields: internal.displayFields
4545

4646
/*!
4747
Exposes the number of rows in the list model returned by `displayFields`.
48-
*/
48+
*/
4949
readonly property alias fieldCount: internal.fieldCount
5050

51-
/*!
52-
\brief A list model containing the attachment images of the
53-
Popup associated with this PopupManager.
54-
\note This can be null.
55-
*/
51+
/*!
52+
\brief A list model containing the attachment images of the
53+
Popup associated with this PopupManager.
54+
\note This can be null.
55+
*/
5656
readonly property alias attachments: internal.attachments
5757

5858
/*!
5959
\brief Exposes the number of rows in the list model returned by
6060
`attachments`.
61-
*/
61+
*/
6262
readonly property alias attachmentCount: internal.attachmentCount
6363

64+
/*!
65+
\brief The minimum attachment thumbnail width.
66+
*/
67+
property alias attachmentThumbnailWidth: internal.attachmentThumbnailWidth
68+
69+
/*!
70+
\brief The minimum attachment thumbnail height.
71+
*/
72+
property alias attachmentThumbnailHeight: internal.attachmentThumbnailHeight
73+
6474
/*!
6575
\brief Returns the title of the PopupManager.
6676
\note This is re-exposed from PopupManager as PopupManager does not have
6777
NOTIFY/CONSTANT modifiers on its title property, so the Controller
68-
re-exposes title to suppress warnings about ths.
69-
*/
78+
re-exposes title to suppress warnings about this.
79+
*/
7080
readonly property alias title: internal.title
7181

82+
/*!
83+
\brief Returns the showAttachments flag of the PopupManager.
84+
\note This is re-exposed from PopupManager as PopupManager does not have
85+
NOTIFY/CONSTANT modifiers on its showAttachments property, so the Controller
86+
re-exposes showAttachments to suppress warnings about this.
87+
*/
88+
readonly property alias showAttachments: internal.showAttachments
89+
7290
/*! \internal */
7391
property QtObject internal : QtObject {
7492
id: internal
@@ -83,41 +101,63 @@ QtObject {
83101

84102
property string title: ""
85103

104+
property bool showAttachments: false
105+
106+
property int attachmentThumbnailWidth: 0
107+
108+
property int attachmentThumbnailHeight: 0
109+
86110
property Connections attachmentConnection: Connections {
87111
target: attachments
88-
onRowsInserted: internal.attachmentCount = attachments.rowCount();
89-
onRowsRemoved: internal.attachmentCount = attachments.rowCount();
112+
function onRowsInserted() {
113+
internal.attachmentCount = attachments.rowCount();
114+
}
115+
function onRowsRemoved() {
116+
internal.attachmentCount = attachments.rowCount();
117+
}
90118
}
91119

92120
property Connections fieldsConnection: Connections {
93121
target: displayFields
94-
onRowsInserted: internal.fieldCount = displayFields.rowCount();
95-
onRowsRemoved: internal.fieldCount = displayFields.rowCount();
122+
function onRowsInserted() {
123+
internal.fieldCount = displayFields.rowCount();
124+
}
125+
function onRowsRemoved() {
126+
internal.fieldCount = displayFields.rowCount();
127+
}
96128
}
97129
}
98130

99131
onPopupManagerChanged: {
132+
// PopupManager properties have no NOTIFY or CONST properties.
133+
// To avoid property warnings we will instead cache
134+
// what comes out of PopupManager.
100135
if (popupManager) {
101136
if (popupManager.attachmentManager) {
102137
internal.attachments = popupManager.attachmentManager.attachmentsModel;
103138
internal.attachmentCount = attachments.rowCount();
139+
internal.attachmentThumbnailWidth = Qt.binding(() => internal.attachments.thumbnailWidth);
140+
internal.attachmentThumbnailHeight = Qt.binding(() => internal.attachments.thumbnailHeight);
104141
} else {
105142
internal.attachments = null;
106143
internal.attachmentCount = 0;
144+
internal.attachmentThumbnailWidth = 0;
145+
internal.attachmentThumbnailHeight = 0;
107146
}
108147

109148
internal.displayFields = popupManager.displayedFields;
110149
internal.fieldCount = displayFields.rowCount();
111150
internal.title = popupManager.title;
112-
151+
internal.showAttachments = popupManager.showAttachments;
113152
} else {
114153
internal.attachments = null;
115154
internal.attachmentCount = 0;
116-
117155
internal.displayFields = null;
118156
internal.fieldCount = 0;
119-
157+
internal.attachmentThumbnailWidth = 0;
158+
internal.attachmentThumbnailHeight = 0;
120159
internal.title = "";
160+
internal.showAttachments = false;
121161
}
122162
}
123163
}

uitools/import/Esri/ArcGISRuntime/Toolkit/PopupView.qml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ Control {
128128
left: parent.left
129129
right: parent.right
130130
}
131-
rows: controller.fieldCount + controller.attachmentCount + 2
131+
132+
// We must account for what is visible, including title headers as rows.
133+
rows: controller.showAttachments ? controller.fieldCount + controller.attachmentCount + 2
134+
: controller.fieldCount + 1
132135

133136
// Title Header
134137
Text {
@@ -154,6 +157,8 @@ Control {
154157
Text {
155158
Layout.columnSpan: 2
156159
Layout.fillWidth: true
160+
visible: controller.showAttachments
161+
enabled: visible
157162
textFormat: Text.StyledText
158163
text: controller.attachmentCount > 0 ? "<h2>Attachments</h2>" : ""
159164
color: palette.text
@@ -164,6 +169,8 @@ Control {
164169
Repeater {
165170
model: controller.attachments
166171
Text {
172+
visible: controller.showAttachments
173+
enabled: visible
167174
Layout.fillWidth: true
168175
text: name
169176
wrapMode: Text.WrapAnywhere
@@ -195,6 +202,11 @@ Control {
195202
Repeater {
196203
model: controller.attachments
197204
Image {
205+
Layout.fillHeight: true
206+
Layout.minimumWidth: controller.attachmentThumbnailWidth
207+
Layout.minimumHeight: controller.attachmentThumbnailHeight
208+
visible: controller.showAttachments
209+
enabled: visible
198210
source: thumbnailUrl
199211
MouseArea {
200212
anchors.fill: parent

0 commit comments

Comments
 (0)