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>
17#include <QtGui/QShortcut>
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>
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>
48class CObjectCollectionViewAttr:
public iqtgui::TRestorableGuiWrap<
49 iqtgui::TDesignerGuiObserverCompBase<Ui::CObjectCollectionViewComp, imtbase::IObjectCollection>>
52 typedef iqtgui::TRestorableGuiWrap<
53 iqtgui::TDesignerGuiObserverCompBase<Ui::CObjectCollectionViewComp, imtbase::IObjectCollection>> BaseClass;
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);
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);
72 QList<bool> m_enabledStates;
76class CObjectCollectionViewComp:
77 public CObjectCollectionViewAttr,
78 public imod::CMultiModelDispatcherBase,
83 typedef CObjectCollectionViewAttr BaseClass;
84 typedef imod::CMultiModelDispatcherBase BaseClass2;
86 I_BEGIN_COMPONENT(CObjectCollectionViewComp);
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
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)"
105 I_ASSIGN(m_centerToolBarCommandGroupIdAttrPtr,
"CenterToolBarCommandGroupId",
106 R
"(Commands with the specified group ID will be placed in the center of the toolbar
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)"
114 I_ASSIGN(m_rightToolBarCommandGroupIdAttrPtr,
"RightToolBarCommandGroupId",
115 R
"(Commands with the specified group ID will be placed in the right part of the toolbar
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)"
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,
"");
136 MI_DOCUMENT_TYPE_VISUAL_STATUS_BASE = 0,
137 MI_LAST = MI_DOCUMENT_TYPE_VISUAL_STATUS_BASE + 1000
140 CObjectCollectionViewComp();
142 void SetFilterString(
const QString& text);
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;
152 virtual bool Serialize(iser::IArchive& archive)
override;
155 ICollectionViewDelegate* GetViewDelegatePtr(
const QByteArray& typeId);
156 const ICollectionViewDelegate* GetViewDelegate(
const QByteArray& typeId)
const;
158 virtual void OnPageSelectionUpdated();
161 virtual void OnRestoreSettings(
const QSettings& settings)
override;
162 virtual void OnSaveSettings(QSettings& settings)
const override;
165 virtual void UpdateGui(
const istd::IChangeable::ChangeSet& changeSet)
override;
166 virtual void OnGuiModelAttached()
override;
167 virtual void OnGuiModelDetached()
override;
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;
177 virtual void OnModelChanged(
int modelId,
const istd::IChangeable::ChangeSet& changeSet)
override;
180 virtual void OnComponentCreated()
override;
181 virtual void OnComponentDestroyed()
override;
184 class PageSelection:
virtual public iprm::ISelectionParam,
virtual public iprm::IOptionsList
189 void SetParent(CObjectCollectionViewComp* parentPtr);
191 void SetPageCount(
int pageCount);
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;
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;
208 virtual bool Serialize(iser::IArchive& archive)
override;
211 CObjectCollectionViewComp* m_parentPtr;
214 int m_selectedPageIndex;
217 template <
typename InterfaceType>
218 static InterfaceType* ExtractPageSelection(CObjectCollectionViewComp& component)
220 return &component.m_pageSelection;
224 class Commands:
virtual public ibase::ICommandsProvider
229 void SetParent(CObjectCollectionViewComp* parentPtr);
233 virtual const ibase::IHierarchicalCommand* GetCommands()
const override;
236 CObjectCollectionViewComp* m_parentPtr;
239 template <
typename InterfaceType>
240 static InterfaceType* ExtractCommands(CObjectCollectionViewComp& component)
242 return &component.m_commands;
245 class FocusDecorationFactory:
public iwidgets::CFocusDecorator::IGraphicsEffectFactory
249 virtual std::unique_ptr<QGraphicsEffect> CreateEffect()
const override;
253 void UpdateCommands();
255 QVector<QByteArray> GetMetaInfoIds(
const QByteArray& typeId)
const;
256 QStringList GetMetaInfoHeaders(
const QByteArray& typeId)
const;
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);
266 virtual bool eventFilter(QObject*
object, QEvent* event)
override;
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();
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);
286 void EmitUpdateGui(
const istd::IChangeable::ChangeSet& changeSet);
289 class SignalSemaphore
292 SignalSemaphore(
int& counter)
294 m_counter = &counter;
310 int m_semaphoreCounter;
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;
320 class TableModel:
public QAbstractTableModel
323 TableModel(CObjectCollectionViewComp& parent);
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);
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;
342 virtual bool canFetchMore(
const QModelIndex &parent)
const override;
343 virtual void fetchMore(
const QModelIndex &parent)
override;
347 qsizetype m_fetchedRowCount;
348 mutable imtbase::ICollectionInfo::Ids m_ids;
351 QStringList m_columns;
354 CObjectCollectionViewComp& m_parent;
355 mutable QMap<QByteArray, ICollectionViewDelegate::ObjectMetaInfo> m_metaInfoMap;
357 imtcol::CObjectTypeIdFilter m_objectTypeIdFilter;
360 QStandardItemModel m_typeModel;
361 TableModel m_tableModel;
363 imod::TModelWrap<CObjectCollectionViewDelegate> m_defaultViewDelegate;
365 typedef QMap<QByteArray, ICollectionViewDelegate*> ViewDelegateMap;
366 ViewDelegateMap m_viewDelegateMap;
368 QByteArray m_currentTypeId;
369 imod::TModelWrap<PageSelection> m_pageSelection;
370 imod::TModelWrap<Commands> m_commands;
372 typedef QMap<QString, QVariant> ColumnSettings;
373 typedef QVector<ColumnSettings> ColumnsList;
374 typedef QMap<QString, ColumnsList> TypeIdColumnsSettings;
375 mutable TypeIdColumnsSettings m_typeIdColumnsSettings;
377 iqtgui::IGuiObject* m_currentInformationViewPtr;
381 QTimer m_textFilterTimer;
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);
400 imtgui::CCommandToolBar m_collectionCommandsLeftToolBar;
401 imtgui::CCommandToolBar m_collectionCommandsCenterToolBar;
402 imtgui::CCommandToolBar m_collectionCommandsRightToolBar;
QVector< ICollectionViewDelegate::SummaryInformation > ObjectMetaInfo