1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "assetslibraryview.h"
#include "assetslibrarywidget.h"
#include "designmodecontext.h"
#include "qmldesignerplugin.h"
#include <asynchronousimagecache.h>
#include <bindingproperty.h>
#include <coreplugin/icore.h>
#include <imagecache/imagecachecollector.h>
#include <imagecache/imagecacheconnectionmanager.h>
#include <imagecache/imagecachefontcollector.h>
#include <imagecache/imagecachegenerator.h>
#include <imagecache/imagecachestorage.h>
#include <imagecache/timestampprovider.h>
#include <nodelistproperty.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectmanager.h>
#include <projectexplorer/target.h>
#include <rewriterview.h>
#include <sqlitedatabase.h>
#include <synchronousimagecache.h>
#include <utils/algorithm.h>
#include <qmlitemnode.h>
namespace QmlDesigner {
class AssetsLibraryView::ImageCacheData
{
public:
Sqlite::Database database{Utils::PathString{
Core::ICore::cacheResourcePath("fontimagecache.db").toString()},
Sqlite::JournalMode::Wal,
Sqlite::LockingMode::Normal};
ImageCacheStorage<Sqlite::Database> storage{database};
ImageCacheFontCollector fontCollector;
ImageCacheGenerator fontGenerator{fontCollector, storage};
TimeStampProvider timeStampProvider;
AsynchronousImageCache asynchronousFontImageCache{storage, fontGenerator, timeStampProvider};
SynchronousImageCache synchronousFontImageCache{storage, timeStampProvider, fontCollector};
};
AssetsLibraryView::AssetsLibraryView(ExternalDependenciesInterface &externalDependencies)
: AbstractView{externalDependencies}
{}
AssetsLibraryView::~AssetsLibraryView()
{}
bool AssetsLibraryView::hasWidget() const
{
return true;
}
WidgetInfo AssetsLibraryView::widgetInfo()
{
if (m_widget.isNull()) {
m_widget = new AssetsLibraryWidget{imageCacheData()->asynchronousFontImageCache,
imageCacheData()->synchronousFontImageCache,
this};
auto context = new Internal::AssetsLibraryContext(m_widget.data());
Core::ICore::addContextObject(context);
}
return createWidgetInfo(m_widget.data(), "Assets", WidgetInfo::LeftPane, 0, tr("Assets"));
}
void AssetsLibraryView::customNotification(const AbstractView * /*view*/,
const QString &identifier,
const QList<ModelNode> & /*nodeList*/,
const QList<QVariant> & /*data*/)
{
if (identifier == "delete_selected_assets")
m_widget->deleteSelectedAssets();
}
void AssetsLibraryView::modelAttached(Model *model)
{
AbstractView::modelAttached(model);
m_widget->clearSearchFilter();
setResourcePath(DocumentManager::currentResourcePath().toFileInfo().absoluteFilePath());
}
void AssetsLibraryView::modelAboutToBeDetached(Model *model)
{
AbstractView::modelAboutToBeDetached(model);
}
void AssetsLibraryView::setResourcePath(const QString &resourcePath)
{
if (resourcePath == m_lastResourcePath)
return;
m_lastResourcePath = resourcePath;
if (m_widget.isNull()) {
m_widget = new AssetsLibraryWidget{imageCacheData()->asynchronousFontImageCache,
imageCacheData()->synchronousFontImageCache,
this};
}
m_widget->setResourcePath(resourcePath);
}
AssetsLibraryView::ImageCacheData *AssetsLibraryView::imageCacheData()
{
std::call_once(imageCacheFlag,
[this] { m_imageCacheData = std::make_unique<ImageCacheData>(); });
return m_imageCacheData.get();
}
} // namespace QmlDesigner
|