ICF 3.1.1.10
Technical documentation of ICF Libraries
CDocPreviewGuiComp.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#pragma once
7
8
9// Qt includes
10#include <QtCore/QFileSystemWatcher>
11#include <QtCore/QTimer>
12#include <QtCore/QDateTime>
13#include <QtCore/QFutureWatcher>
14#include <QtWidgets/QGraphicsView>
15
16// ICF includes
22
24
25#include <GeneratedFiles/idocgui/ui_CDocPreviewGuiComp.h>
26
27
28namespace idocgui
29{
30
31
38 public istdgui::TDesignerGuiObserverCompBase<Ui::CDocPreviewGuiComp, ifile::IFileNameParam>,
39 virtual protected ifile::IFileTypeInfo
40{
41 Q_OBJECT
42
43public:
45
46 I_BEGIN_COMPONENT(CDocPreviewGuiComp);
47 I_REGISTER_SUBELEMENT(FileTypeInfo);
48 I_REGISTER_SUBELEMENT_INTERFACE(FileTypeInfo, ifile::IFileTypeInfo, ExtractFileTypeInfo);
49 I_REGISTER_SUBELEMENT(CurrentViewCommands);
50 I_REGISTER_SUBELEMENT_INTERFACE(CurrentViewCommands, istd::IChangeable, ExtractCurrentViewCommands);
51 I_REGISTER_SUBELEMENT_INTERFACE(CurrentViewCommands, ibase::ICommandsProvider, ExtractCurrentViewCommands);
52 I_REGISTER_SUBELEMENT_INTERFACE(CurrentViewCommands, imod::IModel, ExtractCurrentViewCommands);
53 I_ASSIGN(m_documentTemplateCompPtr, "DocumentTemplate", "Template of all supported documents", true, "DocumentTemplate");
54 I_ASSIGN(m_isAsyncLoadEnabledAttrPtr, "AsynchronPreviewGenerationEnabled", "If enabled, the preview generation will be done in a separated thread", true, true);
55 I_ASSIGN(m_noAvailableLabelAttrPtr, "NoAvailableLabel", "Text used for no available preview state", false, "");
56 I_ASSIGN(m_noAvailableIconPathAttrPtr, "NoAvailableIconPath", "Path to the icon used for no available preview state", true, ":/IcfIcons/Cancel");
57 I_END_COMPONENT;
58
60
61protected:
62 iproc::CTaskState UpdateObjectFromFile(const QByteArray& docTypeId, QString filePath);
64
65 // reimplemented (istdgui::TGuiObserverWrap)
66 void UpdateGui(const istd::IChangeable::ChangeSet& changeSet) override;
67
68 // reimplemented (istdgui::CGuiComponentBase)
69 void OnGuiCreated() override;
70 void OnGuiDestroyed() override;
71 void OnGuiRetranslate() override;
72
73 // reimplemented (icomp::CComponentBase)
74 void OnComponentCreated() override;
75 void OnComponentDestroyed() override;
76
77 // reimplemented (ifile::IFileTypeInfo)
78 bool GetFileExtensions(QStringList& result, const istd::IChangeable* dataObjectPtr = nullptr, int flags = -1, bool doAppend = false) const override;
79 QString GetTypeDescription(const QString* extensionPtr = nullptr) const override;
80
81Q_SIGNALS:
82 void LoadingFinished(QByteArray docTypeId, bool isSuccess);
83
84private Q_SLOTS:
85 void UpdateFilePreview();
86 void OnLoadingFinished(QByteArray docTypeId, bool isSuccess);
87
88private:
89 // static template methods for subelement access
90 template <class InterfaceType>
91 static InterfaceType* ExtractFileTypeInfo(CDocPreviewGuiComp& component)
92 {
93 return &component;
94 }
95
96 template <class InterfaceType>
97 static InterfaceType* ExtractCurrentViewCommands(CDocPreviewGuiComp& component)
98 {
99 return &component.m_currentView;
100 }
101
105 class PreviewWidget: public QGraphicsView
106 {
107 public:
108 explicit PreviewWidget(QWidget* parent = nullptr);
109
110 protected:
111 // reimplemented (QWidget)
112 void resizeEvent(QResizeEvent* eventPtr);
113 };
114
115 struct ViewInfo
116 {
117 int pageIndex = 0;
118 const ifile::IFilePersistence* loaderPtr = nullptr;
119 std::unique_ptr<istd::IChangeable> documentPtr;
120 std::unique_ptr<istd::IPolymorphic> viewPtr;
121 std::unique_ptr<QWidget> widgetPtr;
122 };
123
124 class CurrentView: public ibase::ICommandsProvider
125 {
126 public:
127 void SetView(const ViewInfo* viewInfoPtr);
128
129 // reimplemented (ibase::ICommandsProvider)
130 virtual const ibase::IHierarchicalCommand* GetCommands() const;
131
132 private:
133 const ViewInfo* m_viewInfoPtr = nullptr;
134 };
135
136 I_REF(idoc::IDocumentTemplate, m_documentTemplateCompPtr);
137 I_ATTR(bool, m_isAsyncLoadEnabledAttrPtr);
138 I_TEXTATTR(m_noAvailableLabelAttrPtr);
139 I_ATTR(QByteArray, m_noAvailableIconPathAttrPtr);
140
141 std::map<QByteArray, ViewInfo> m_docTypeToViewMap;
142 struct FileTypeInfo
143 {
144 QByteArray docTypeId;
145 QString description;
146 };
147 std::map<QString, FileTypeInfo> m_extensionToDocTypeMap;
148
149 QFileSystemWatcher m_fileSystemObserver;
150
151 QDateTime m_lastFileTimestamp;
152 QString m_lastFilePath;
153
154 imod::TModelWrap<CurrentView> m_currentView;
155
156 iproc::CTaskState m_loadState;
157
158 istd::CSingleAsyncCaller m_asyncCaller;
159 QTimer m_retryTimer;
160};
161
162
163} // namespace idocgui
164
165
Interface for a provider of the heriarchical commands.
Common interface for a document template.
Component for the preview of the file contents.
void LoadingFinished(QByteArray docTypeId, bool isSuccess)
void OnComponentDestroyed() override
void UpdateGui(const istd::IChangeable::ChangeSet &changeSet) override
QString GetTypeDescription(const QString *extensionPtr=nullptr) const override
Get description of object type associated with single extension.
bool GetFileExtensions(QStringList &result, const istd::IChangeable *dataObjectPtr=nullptr, int flags=-1, bool doAppend=false) const override
Get file extensions supported by this loader.
void OnGuiDestroyed() override
Called just before GUI is released.
void OnGuiCreated() override
Called just after GUI is initialized.
iproc::CTaskState UpdateObjectFromFile(const QByteArray &docTypeId, QString filePath)
void OnComponentCreated() override
void OnGuiRetranslate() override
Called from widget event filter when GUI should be retranslated.
istdgui::TDesignerGuiObserverCompBase< Ui::CDocPreviewGuiComp, ifile::IFileNameParam > BaseClass
Interface providing loading and saving of data objects.
Provide loading and saving of objects.
Common interface for model objects, that supports Model/Observer design pattern.
Definition IModel.h:29
This model wrapper provides a simple connection between a concrete istd::IChangeable implementation a...
Definition TModelWrap.h:28
Represent state of asynchronous operation.
Definition CTaskState.h:28
Call some function asynchronously in separated thread.
Set of change flags (its IDs).
Definition IChangeable.h:38
Common interface for data model objects, which can be changed.
Definition IChangeable.h:32
Common interface to define the hierarchical graph structures.
Base class for all Qt GUI components.
This package contains Qt implementations related to Document/View concept.

© Witold Gantzke and Kirill Lepskiy