ImagingTools Core SDK
CObjectCollectionViewComp.h
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ImtCore-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QList>
7#include <QtCore/QThread>
8#include <QtCore/QTimer>
9#include <QtCore/QSortFilterProxyModel>
10#include <QtCore/QPropertyAnimation>
11#include <QtGui/QStandardItem>
12#include <QtGui/QStandardItemModel>
13#include <QtWidgets/QMenu>
14#if QT_VERSION >= 0x050000 && QT_VERSION < 0x060000
15#include <QtWidgets/QShortcut>
16#else
17#include <QtGui/QShortcut>
18#endif
19
20// ACF includes
21#include <imod/CMultiModelDispatcherBase.h>
22#include <ibase/ICommandsProvider.h>
23#include <iprm/IOptionsList.h>
24#include <iprm/ISelectionParam.h>
25#include <iqtgui/TDesignerGuiObserverCompBase.h>
26#include <iqtgui/TRestorableGuiWrap.h>
27#include <iqtgui/CHierarchicalCommand.h>
28#include <iser/IArchive.h>
29#include <iwidgets/CFocusDecorator.h>
30
31// ImtCore includes
32#include <imtbase/ISelection.h>
33#include <imtbase/CCollectionFilter.h>
34#include <imtbase/IComplexCollectionFilter.h>
35#include <imtbase/CComplexCollectionFilterHelper.h>
36#include <imtbase/IObjectCollection.h>
37#include <imtbase/TModelUpdateBinder.h>
38#include <imtcol/CObjectTypeIdFilter.h>
39#include <imtgui/CObjectCollectionViewDelegate.h>
40#include <imtgui/CCommandToolBar.h>
41#include <GeneratedFiles/imtgui/ui_CObjectCollectionViewComp.h>
42
43
44namespace imtgui
45{
46
47
48class CObjectCollectionViewAttr: public iqtgui::TRestorableGuiWrap<
49 iqtgui::TDesignerGuiObserverCompBase<Ui::CObjectCollectionViewComp, imtbase::IObjectCollection>>
50{
51public:
52 typedef iqtgui::TRestorableGuiWrap<
53 iqtgui::TDesignerGuiObserverCompBase<Ui::CObjectCollectionViewComp, imtbase::IObjectCollection>> BaseClass;
54
55 I_BEGIN_BASE_COMPONENT(CObjectCollectionViewAttr);
56 I_ASSIGN(m_columnSettingsKeyAttrPtr, "ColumnSettingsKey", "Registry/INI file key for storing column settings", true, "");
57 I_ASSIGN(m_useSearchWidgetAttrPtr, "UseSearchWidget", "Use internal search widget", true, true);
58 I_ASSIGN(m_useCloseButtonAttrPtr, "UseCloseButton", "Add close button to the right", true, false);
59 I_ASSIGN(m_viewRightPanelAttrPtr, "ViewRightPanel", "View right panel", true, true);
60 I_ASSIGN(m_viewFilterAttrPtr, "ViewFilter", "View filter for default", true, false);
61 I_ASSIGN(m_updateOnChangesAttrPtr, "UpdateOnChanges", "Update the view on changes of the observed collection", true, false);
62 I_END_COMPONENT;
63
64protected:
65 I_ATTR(QByteArray, m_columnSettingsKeyAttrPtr);
66 I_ATTR(bool, m_useSearchWidgetAttrPtr);
67 I_ATTR(bool, m_viewRightPanelAttrPtr);
68 I_ATTR(bool, m_viewFilterAttrPtr);
69 I_ATTR(bool, m_useCloseButtonAttrPtr);
70 I_ATTR(bool, m_updateOnChangesAttrPtr);
71
72 QList<bool> m_enabledStates;
73};
74
75
76class CObjectCollectionViewComp:
77 public CObjectCollectionViewAttr,
78 public imod::CMultiModelDispatcherBase,
79 virtual public imtbase::ISelection
80{
81 Q_OBJECT
82public:
83 typedef CObjectCollectionViewAttr BaseClass;
84 typedef imod::CMultiModelDispatcherBase BaseClass2;
85
86 I_BEGIN_COMPONENT(CObjectCollectionViewComp);
87 I_REGISTER_INTERFACE(imtbase::ISelection);
88 I_REGISTER_SUBELEMENT(PageSelection);
89 I_REGISTER_SUBELEMENT_INTERFACE(PageSelection, iprm::ISelectionParam, ExtractPageSelection);
90 I_REGISTER_SUBELEMENT_INTERFACE(PageSelection, imod::IModel, ExtractPageSelection);
91 I_REGISTER_SUBELEMENT_INTERFACE(PageSelection, istd::IChangeable, ExtractPageSelection);
92 I_REGISTER_SUBELEMENT(Commands);
93 I_REGISTER_SUBELEMENT_INTERFACE(Commands, ibase::ICommandsProvider, ExtractCommands);
94 I_REGISTER_SUBELEMENT_INTERFACE(Commands, istd::IChangeable, ExtractCommands);
95 I_REGISTER_SUBELEMENT_INTERFACE(Commands, imod::IModel, ExtractCommands);
96 I_ASSIGN(m_leftToolBarCommandGroupIdAttrPtr, "LeftToolBarCommandGroupId",
97 R"(Commands with the specified group ID will be placed in the left part of the toolbar
98
99NOTE
100(*) This attribute belongs to a group of logically related attributes(LeftToolBarCommandGroupId, CenterToolBarCommandGroupId, RightToolBarCommandGroupId)
101(*) If all attributes are less than 0, then the entire set of commands is placed in the left part of the toolbar
102(*) If at least one attribute is greater than or equal to 0, then commands with the specified group id are placed in the corresponding part of the toolbar
103 If any of the attributes has a group id value less than 0, the corresponding part of the toolbar will remain empty)"
104 , true, -1);
105 I_ASSIGN(m_centerToolBarCommandGroupIdAttrPtr, "CenterToolBarCommandGroupId",
106 R"(Commands with the specified group ID will be placed in the center of the toolbar
107
108NOTE
109(*) This attribute belongs to a group of logically related attributes(LeftToolBarCommandGroupId, CenterToolBarCommandGroupId, RightToolBarCommandGroupId)
110(*) If all attributes are less than 0, then the entire set of commands is placed in the left part of the toolbar
111(*) If at least one attribute is greater than or equal to 0, then commands with the specified group id are placed in the corresponding part of the toolbar
112 If any of the attributes has a group id value less than 0, the corresponding part of the toolbar will remain empty)"
113 , true, -1);
114 I_ASSIGN(m_rightToolBarCommandGroupIdAttrPtr, "RightToolBarCommandGroupId",
115 R"(Commands with the specified group ID will be placed in the right part of the toolbar
116
117NOTE
118(*) This attribute belongs to a group of logically related attributes(LeftToolBarCommandGroupId, CenterToolBarCommandGroupId, RightToolBarCommandGroupId)
119(*) If all attributes are less than 0, then the entire set of commands is placed in the left part of the toolbar
120(*) If at least one attribute is greater than or equal to 0, then commands with the specified group id are placed in the corresponding part of the toolbar
121 If any of the attributes has a group id value less than 0, the corresponding part of the toolbar will remain empty)"
122 , true, -1);
123 I_ASSIGN_MULTI_0(m_viewDelegatesCompPtr, "ViewDelegates", "List of view delegates (corresponding with the object type) used for the collection", false);
124 I_ASSIGN(m_filterParamsGuiCompPtr, "FilterParamsGui", "UI for the additional filtering parameters for the collection", false, "FilterParamsGui");
125 I_ASSIGN_TO(m_filterParamsObserverCompPtr, m_filterParamsGuiCompPtr, false);
126 I_ASSIGN(m_filterSelectionCompPtr, "FilterSelection", "Filter selection", false, "FilterSelection");
127 I_ASSIGN(m_paginationGuiCompPtr, "PaginationGui", "Pagination gui", false, "PaginationGui");
128 I_ASSIGN_TO(m_paginationGuiObserverCompPtr, m_paginationGuiCompPtr, false);
129 I_ASSIGN(m_filterParamsCompPtr, "FilteringParams", "Parameter using for the filterering the table", false, "FilteringParams");
130 I_ASSIGN_TO(m_filterParamsModelCompPtr, m_filterParamsCompPtr, false);
131 I_ASSIGN(m_filterEditPlaceholderTextAttrPtr, "FilterEditPlaceholderText", "Filter text box placeholder text", false, "");
132 I_END_COMPONENT;
133
134 enum ModelId
135 {
136 MI_DOCUMENT_TYPE_VISUAL_STATUS_BASE = 0,
137 MI_LAST = MI_DOCUMENT_TYPE_VISUAL_STATUS_BASE + 1000
138 };
139
140 CObjectCollectionViewComp();
141
142 void SetFilterString(const QString& text);
143
144 // reimplemented (imtbase::ISelection)
145 virtual const imtbase::ICollectionInfo* GetSelectionConstraints() const override;
146 virtual SelectionMode GetSelectionMode() const override;
147 virtual bool SetSelectionMode(SelectionMode mode) override;
148 virtual Ids GetSelectedIds() const override;
149 virtual bool SetSelectedIds(const Ids& selectedIds) override;
150
151 // reimplemented (iser::ISerialize)
152 virtual bool Serialize(iser::IArchive& archive) override;
153
154protected:
155 ICollectionViewDelegate* GetViewDelegatePtr(const QByteArray& typeId);
156 const ICollectionViewDelegate* GetViewDelegate(const QByteArray& typeId) const;
157
158 virtual void OnPageSelectionUpdated();
159
160 // reimplemented (iqtgui::TRestorableGuiWrap)
161 virtual void OnRestoreSettings(const QSettings& settings) override;
162 virtual void OnSaveSettings(QSettings& settings) const override;
163
164 // reimplemented (iqtgui::TGuiObserverWrap)
165 virtual void UpdateGui(const istd::IChangeable::ChangeSet& changeSet) override;
166 virtual void OnGuiModelAttached() override;
167 virtual void OnGuiModelDetached() override;
168
169 // reimplemented (iqtgui::CGuiComponentBase)
170 virtual void OnGuiCreated() override;
171 virtual void OnGuiDestroyed() override;
172 virtual void OnGuiRetranslate() override;
173 virtual void OnGuiDesignChanged() override;
174 virtual void OnGuiModelShown() override;
175
176 // reimplemented (imod::CMultiModelDispatcherBase)
177 virtual void OnModelChanged(int modelId, const istd::IChangeable::ChangeSet& changeSet) override;
178
179 // reimplemented (icomp::CComponentBase)
180 virtual void OnComponentCreated() override;
181 virtual void OnComponentDestroyed() override;
182
183protected:
184 class PageSelection: virtual public iprm::ISelectionParam, virtual public iprm::IOptionsList
185 {
186 public:
187 PageSelection();
188
189 void SetParent(CObjectCollectionViewComp* parentPtr);
190
191 void SetPageCount(int pageCount);
192
193 // reimplemented (iprm::ISelectionParam)
194 virtual const IOptionsList* GetSelectionConstraints() const override;
195 virtual int GetSelectedOptionIndex() const override;
196 virtual bool SetSelectedOptionIndex(int index) override;
197 virtual ISelectionParam* GetSubselection(int index) const override;
198
199 // reimplemented (iprm::IOptionsList)
200 virtual int GetOptionsFlags() const override;
201 virtual int GetOptionsCount() const override;
202 virtual QString GetOptionName(int index) const override;
203 virtual QString GetOptionDescription(int index) const override;
204 virtual QByteArray GetOptionId(int index) const override;
205 virtual bool IsOptionEnabled(int index) const override;
206
207 // reimplemented (iser::ISerializable)
208 virtual bool Serialize(iser::IArchive& archive) override;
209
210 private:
211 CObjectCollectionViewComp* m_parentPtr;
212
213 int m_pageCount;
214 int m_selectedPageIndex;
215 };
216
217 template <typename InterfaceType>
218 static InterfaceType* ExtractPageSelection(CObjectCollectionViewComp& component)
219 {
220 return &component.m_pageSelection;
221 }
222
223
224 class Commands: virtual public ibase::ICommandsProvider
225 {
226 public:
227 Commands();
228
229 void SetParent(CObjectCollectionViewComp* parentPtr);
230
231 protected:
232 // reimplemented (ibase::ICommandsProvider)
233 virtual const ibase::IHierarchicalCommand* GetCommands() const override;
234
235 private:
236 CObjectCollectionViewComp* m_parentPtr;
237 };
238
239 template <typename InterfaceType>
240 static InterfaceType* ExtractCommands(CObjectCollectionViewComp& component)
241 {
242 return &component.m_commands;
243 }
244
245 class FocusDecorationFactory: public iwidgets::CFocusDecorator::IGraphicsEffectFactory
246 {
247 public:
248 // reimplemented (iGraphicsEffectFactory)
249 virtual std::unique_ptr<QGraphicsEffect> CreateEffect() const override;
250 };
251
252private:
253 void UpdateCommands();
254
255 QVector<QByteArray> GetMetaInfoIds(const QByteArray& typeId) const;
256 QStringList GetMetaInfoHeaders(const QByteArray& typeId) const;
257 ICollectionViewDelegate::ObjectMetaInfo GetMetaInfo(const QByteArray& itemId, const QByteArray& typeId) const;
258
259 void EnsureColumnsSettingsSynchronized() const;
260 void RestoreColumnsSettings();
261 void ValidateSectionSize(int logicalIndex, int newSize);
262 void UpdateTypeStatus();
263 void OnFilterUpdate(const istd::IChangeable::ChangeSet&, const iprm::IParamsSet* filterPtr);
264
265 // reimplemented (QObject)
266 virtual bool eventFilter(QObject* object, QEvent* event) override;
267
268private Q_SLOTS:
269 void OnSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
270 void OnItemDoubleClick(const QModelIndex& item);
271 void OnCustomContextMenuRequested(const QPoint& point);
272 void OnSectionResized(int logicalIndex, int oldSize, int newSize);
273 void OnSectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex);
274 void OnSortingChanged(int logicalIndex, Qt::SortOrder order);
275 void OnTypeChanged();
276 void OnTextFilterTimer();
277
278 void OnFilterChanged(const QString& text);
279 void OnSearchShortCut();
280 void OnEscShortCut();
281 void OnDelShortCut();
282 void OnRenameShortCut();
283 void DoUpdateGui(const istd::IChangeable::ChangeSet& changeSet);
284
285Q_SIGNALS:
286 void EmitUpdateGui(const istd::IChangeable::ChangeSet& changeSet);
287
288private:
289 class SignalSemaphore
290 {
291 public:
292 SignalSemaphore(int& counter)
293 {
294 m_counter = &counter;
295 (*m_counter)++;
296 }
297
298 ~SignalSemaphore()
299 {
300 (*m_counter)--;
301 }
302
303 private:
304 int* m_counter;
305 SignalSemaphore()
306 {
307 }
308 };
309
310 int m_semaphoreCounter;
311
312 QShortcut* m_searchShortCutPtr;
313 QShortcut* m_escShortCutPtr;
314 QShortcut* m_delShortCutPtr;
315 QShortcut* m_renameShortCutPtr;
316 iwidgets::CFocusDecorator* m_focusDecoratorPtr;
317 FocusDecorationFactory m_graphicsEffectFactory;
318 QPropertyAnimation* m_filterPanelAnimationPtr;
319
320 class TableModel: public QAbstractTableModel
321 {
322 public:
323 TableModel(CObjectCollectionViewComp& parent);
324 void UpdateFromData(const imtbase::IObjectCollection& collection, const istd::IChangeable::ChangeSet& changes);
325 void AddItem(const imtbase::IObjectCollectionInfo::Id& objectId);
326 void UpdateItem(const imtbase::IObjectCollectionInfo::Id& objectId);
327 void RemoveItem(const imtbase::IObjectCollectionInfo::Id& objectId);
328 void SetTextFilter(const QString& textFilter);
329 void SetSorting(int logicalIndex, Qt::SortOrder order);
330 void SetCurrentTypeId(const QByteArray& typeId);
331 const imtbase::ICollectionFilter& GetFilter() const;
332
333 // reimplemented (QAbstractTableModel)
334 virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
335 virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override;
336 virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
337 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
338 virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
339
340 protected:
341 // reimplemented (QAbstractTableModel)
342 virtual bool canFetchMore(const QModelIndex &parent) const override;
343 virtual void fetchMore(const QModelIndex &parent) override;
344
345 private:
346 int m_batchSize;
347 qsizetype m_fetchedRowCount;
348 mutable imtbase::ICollectionInfo::Ids m_ids;
349 int m_totalRowCount;
351 QStringList m_columns;
352 bool m_isPageMode;
353
354 CObjectCollectionViewComp& m_parent;
355 mutable QMap<QByteArray, ICollectionViewDelegate::ObjectMetaInfo> m_metaInfoMap;
357 imtcol::CObjectTypeIdFilter m_objectTypeIdFilter;
358 };
359
360 QStandardItemModel m_typeModel;
361 TableModel m_tableModel;
362
363 imod::TModelWrap<CObjectCollectionViewDelegate> m_defaultViewDelegate;
364
365 typedef QMap<QByteArray, ICollectionViewDelegate*> ViewDelegateMap;
366 ViewDelegateMap m_viewDelegateMap;
367
368 QByteArray m_currentTypeId;
369 imod::TModelWrap<PageSelection> m_pageSelection;
370 imod::TModelWrap<Commands> m_commands;
371
372 typedef QMap<QString, QVariant> ColumnSettings;
373 typedef QVector<ColumnSettings> ColumnsList;
374 typedef QMap<QString, ColumnsList> TypeIdColumnsSettings;
375 mutable TypeIdColumnsSettings m_typeIdColumnsSettings;
376
377 iqtgui::IGuiObject* m_currentInformationViewPtr;
378
380
381 QTimer m_textFilterTimer;
382
383private:
387 I_ATTR(int, m_leftToolBarCommandGroupIdAttrPtr);
388 I_ATTR(int, m_centerToolBarCommandGroupIdAttrPtr);
389 I_ATTR(int, m_rightToolBarCommandGroupIdAttrPtr);
390 I_MULTIREF(ICollectionViewDelegate, m_viewDelegatesCompPtr);
391 I_REF(iqtgui::IGuiObject, m_filterParamsGuiCompPtr);
392 I_REF(imod::IObserver, m_filterParamsObserverCompPtr);
393 I_REF(iprm::ISelectionParam, m_filterSelectionCompPtr);
394 I_REF(iqtgui::IGuiObject, m_paginationGuiCompPtr);
395 I_REF(imod::IObserver, m_paginationGuiObserverCompPtr);
396 I_REF(iprm::IParamsSet, m_filterParamsCompPtr);
397 I_REF(imod::IModel, m_filterParamsModelCompPtr);
398 I_TEXTATTR(m_filterEditPlaceholderTextAttrPtr);
399
400 imtgui::CCommandToolBar m_collectionCommandsLeftToolBar;
401 imtgui::CCommandToolBar m_collectionCommandsCenterToolBar;
402 imtgui::CCommandToolBar m_collectionCommandsRightToolBar;
403};
404
405
406} // namespace imtgui
407
408
QVector< ICollectionViewDelegate::SummaryInformation > ObjectMetaInfo