forked from qt-creator/qt-creator
Utils: Move Utils::FileReader::fetchQrc out of FileReader
The FileReader class is about to be removed. Also, centralize the QString::fromUtf8() call, which was effectively present on each caller site. Change-Id: Ia593739ad9ff906b098a5dfc725eb827d10f3848 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -47,15 +47,6 @@ namespace Utils {
|
||||
|
||||
// FileReader
|
||||
|
||||
QByteArray FileReader::fetchQrc(const QString &fileName)
|
||||
{
|
||||
QTC_ASSERT(fileName.startsWith(':'), return QByteArray());
|
||||
QFile file(fileName);
|
||||
bool ok = file.open(QIODevice::ReadOnly);
|
||||
QTC_ASSERT(ok, qWarning() << fileName << "not there!"; return QByteArray());
|
||||
return file.readAll();
|
||||
}
|
||||
|
||||
Result<> FileReader::fetch(const FilePath &filePath)
|
||||
{
|
||||
const Result<QByteArray> contents = filePath.fileContents();
|
||||
@@ -413,6 +404,15 @@ FilePath commonPath(const FilePaths &paths)
|
||||
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
|
||||
QString fetchQrc(const QString &fileName)
|
||||
{
|
||||
QTC_ASSERT(fileName.startsWith(':'), return QString());
|
||||
QFile file(fileName);
|
||||
bool ok = file.open(QIODevice::ReadOnly);
|
||||
QTC_ASSERT(ok, qWarning() << fileName << "not there!"; return QString());
|
||||
return QString::fromUtf8(file.readAll());
|
||||
}
|
||||
|
||||
static QUrl filePathToQUrl(const FilePath &filePath)
|
||||
{
|
||||
return QUrl::fromLocalFile(filePath.toFSPathString());
|
||||
|
@@ -112,6 +112,8 @@ QTCREATOR_UTILS_EXPORT FilePaths getOpenFilePaths(
|
||||
QFileDialog::Options options = {});
|
||||
#endif
|
||||
|
||||
QString fetchQrc(const QString &fileName); // Only for internal resourcesm
|
||||
|
||||
} // namespace FileUtils
|
||||
|
||||
// for actually finding out if e.g. directories are writable on Windows
|
||||
@@ -142,7 +144,6 @@ T withNtfsPermissions(const std::function<T()> &task)
|
||||
class QTCREATOR_UTILS_EXPORT FileReader
|
||||
{
|
||||
public:
|
||||
static QByteArray fetchQrc(const QString &fileName); // Only for internal resources
|
||||
Result<> fetch(const FilePath &filePath);
|
||||
bool fetch(const FilePath &filePath, QString *errorString);
|
||||
const QByteArray &data() const { return m_data; }
|
||||
|
@@ -96,7 +96,7 @@ EffectComposerWidget::EffectComposerWidget(EffectComposerView *view)
|
||||
layout->addWidget(m_quickWidget.data());
|
||||
|
||||
setStyleSheet(QmlDesigner::Theme::replaceCssColors(
|
||||
QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css"))));
|
||||
Utils::FileUtils::fetchQrc(":/qmldesigner/stylesheet.css")));
|
||||
|
||||
QmlDesigner::QmlDesignerPlugin::trackWidgetFocusTime(this, QmlDesigner::Constants::EVENT_EFFECTCOMPOSER_TIME);
|
||||
|
||||
|
@@ -164,7 +164,7 @@ private:
|
||||
{
|
||||
#ifdef WITH_TESTS
|
||||
// Uncomment for testing with local json data.
|
||||
// setJson(FileReader::fetchQrc(":/learning/testdata/courses.json"), m_model); return;
|
||||
// setJson(FileUtils::fetchQrc(":/learning/testdata/courses.json"), m_model); return;
|
||||
#endif // WITH_TESTS
|
||||
|
||||
using namespace Tasking;
|
||||
|
@@ -187,7 +187,7 @@ AssetsLibraryWidget::AssetsLibraryWidget(AsynchronousImageCache &mainImageCache,
|
||||
updateSearch();
|
||||
|
||||
setStyleSheet(Theme::replaceCssColors(
|
||||
QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css"))));
|
||||
Utils::FileUtils::fetchQrc(":/qmldesigner/stylesheet.css")));
|
||||
|
||||
m_qmlSourceUpdateShortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_F6), this);
|
||||
connect(m_qmlSourceUpdateShortcut, &QShortcut::activated, this, &AssetsLibraryWidget::reloadQmlSource);
|
||||
|
@@ -166,7 +166,7 @@ ContentLibraryWidget::ContentLibraryWidget()
|
||||
updateSearch();
|
||||
|
||||
setStyleSheet(Theme::replaceCssColors(
|
||||
QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css"))));
|
||||
Utils::FileUtils::fetchQrc(":/qmldesigner/stylesheet.css")));
|
||||
|
||||
m_qmlSourceUpdateShortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_F11), this);
|
||||
connect(m_qmlSourceUpdateShortcut, &QShortcut::activated, this, &ContentLibraryWidget::reloadQmlSource);
|
||||
|
@@ -35,7 +35,7 @@ CurveEditor::CurveEditor(CurveEditorModel *model, QWidget *parent)
|
||||
setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
m_toolbar->setStyleSheet(Theme::replaceCssColors(
|
||||
QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css"))));
|
||||
Utils::FileUtils::fetchQrc(":/qmldesigner/stylesheet.css")));
|
||||
|
||||
auto *splitter = new QSplitter;
|
||||
splitter->addWidget(m_tree);
|
||||
|
@@ -86,8 +86,8 @@ Edit3DWidget::Edit3DWidget(Edit3DView *view)
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
|
||||
QByteArray sheet = Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css");
|
||||
setStyleSheet(Theme::replaceCssColors(QString::fromUtf8(sheet)));
|
||||
QString sheet = Utils::FileUtils::fetchQrc(":/qmldesigner/stylesheet.css");
|
||||
setStyleSheet(Theme::replaceCssColors(sheet));
|
||||
|
||||
Core::Context context(Constants::qml3DEditorContextId);
|
||||
m_context = new Core::IContext(this);
|
||||
|
@@ -301,8 +301,8 @@ FormEditorWidget::FormEditorWidget(FormEditorView *view)
|
||||
|
||||
fillLayout->addWidget(m_graphicsView.data());
|
||||
|
||||
QByteArray sheet = Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css");
|
||||
setStyleSheet(Theme::replaceCssColors(QString::fromUtf8(sheet)));
|
||||
QString sheet = Utils::FileUtils::fetchQrc(":/qmldesigner/stylesheet.css");
|
||||
setStyleSheet(Theme::replaceCssColors(sheet));
|
||||
|
||||
IContext::attach(this,
|
||||
Context(Constants::qmlFormEditorContextId, Constants::qtQuickToolsMenuContextId),
|
||||
|
@@ -160,7 +160,7 @@ ItemLibraryWidget::ItemLibraryWidget(AsynchronousImageCache &imageCache)
|
||||
updateSearch();
|
||||
|
||||
setStyleSheet(Theme::replaceCssColors(
|
||||
QString::fromUtf8(::Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css"))));
|
||||
::Utils::FileUtils::fetchQrc(":/qmldesigner/stylesheet.css")));
|
||||
|
||||
m_qmlSourceUpdateShortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_F5), this);
|
||||
connect(m_qmlSourceUpdateShortcut, &QShortcut::activated, this, &ItemLibraryWidget::reloadQmlSource);
|
||||
|
@@ -199,7 +199,7 @@ MaterialBrowserWidget::MaterialBrowserWidget(AsynchronousImageCache &imageCache,
|
||||
updateSearch();
|
||||
|
||||
setStyleSheet(Theme::replaceCssColors(
|
||||
QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css"))));
|
||||
Utils::FileUtils::fetchQrc(":/qmldesigner/stylesheet.css")));
|
||||
|
||||
m_qmlSourceUpdateShortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_F8), this);
|
||||
connect(m_qmlSourceUpdateShortcut, &QShortcut::activated, this, &MaterialBrowserWidget::reloadQmlSource);
|
||||
|
@@ -63,8 +63,8 @@ NavigatorWidget::NavigatorWidget(NavigatorView *view)
|
||||
|
||||
setWindowTitle(tr("Navigator", "Title of navigator view"));
|
||||
|
||||
QByteArray sheet = Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css");
|
||||
setStyleSheet(Theme::replaceCssColors(QString::fromUtf8(sheet)));
|
||||
QString sheet = Utils::FileUtils::fetchQrc(":/qmldesigner/stylesheet.css");
|
||||
setStyleSheet(Theme::replaceCssColors(sheet));
|
||||
|
||||
QmlDesignerPlugin::trackWidgetFocusTime(this, Constants::EVENT_NAVIGATORVIEW_TIME);
|
||||
|
||||
|
@@ -88,7 +88,7 @@ PropertyEditorView::PropertyEditorView(AsynchronousImageCache &imageCache,
|
||||
connect(m_updateShortcut, &QShortcut::activated, this, &PropertyEditorView::reloadQml);
|
||||
|
||||
m_stackedWidget->setStyleSheet(Theme::replaceCssColors(
|
||||
QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css"))));
|
||||
Utils::FileUtils::fetchQrc(":/qmldesigner/stylesheet.css")));
|
||||
m_stackedWidget->setMinimumSize(340, 340);
|
||||
m_stackedWidget->move(0, 0);
|
||||
connect(m_stackedWidget, &PropertyEditorWidget::resized, this, &PropertyEditorView::updateSize);
|
||||
|
@@ -110,7 +110,7 @@ TimelineWidget::TimelineWidget(TimelineView *view)
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
||||
m_toolbar->setStyleSheet(Theme::replaceCssColors(
|
||||
QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css"))));
|
||||
Utils::FileUtils::fetchQrc(":/qmldesigner/stylesheet.css")));
|
||||
m_scrollbar->setOrientation(Qt::Horizontal);
|
||||
|
||||
QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
|
@@ -82,7 +82,7 @@ TransitionEditorWidget::TransitionEditorWidget(TransitionEditorView *view)
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
||||
m_toolbar->setStyleSheet(Theme::replaceCssColors(
|
||||
QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css"))));
|
||||
Utils::FileUtils::fetchQrc(":/qmldesigner/stylesheet.css")));
|
||||
m_scrollbar->setOrientation(Qt::Horizontal);
|
||||
|
||||
QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
|
@@ -152,9 +152,9 @@ QWidget *DesignModeWidget::createProjectExplorerWidget(QWidget *parent)
|
||||
}
|
||||
|
||||
if (navigationView.widget) {
|
||||
QByteArray sheet = Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css");
|
||||
QString sheet = Utils::FileUtils::fetchQrc(":/qmldesigner/stylesheet.css");
|
||||
sheet += "QLabel { background-color: #4f4f4f; }";
|
||||
navigationView.widget->setStyleSheet(Theme::replaceCssColors(QString::fromUtf8(sheet)));
|
||||
navigationView.widget->setStyleSheet(Theme::replaceCssColors(sheet));
|
||||
navigationView.widget->setParent(parent);
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ void DesignModeWidget::setup()
|
||||
m_dockManager->setWorkspacePresetsPath(
|
||||
Core::ICore::resourcePath("qmldesigner/workspacePresets/").toUrlishString());
|
||||
|
||||
QString sheet = QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/dockwidgets.css"));
|
||||
QString sheet = Utils::FileUtils::fetchQrc(":/qmldesigner/dockwidgets.css");
|
||||
m_dockManager->setStyleSheet(Theme::replaceCssColors(sheet));
|
||||
|
||||
connect(ProjectExplorer::ProjectManager::instance(),
|
||||
@@ -314,9 +314,9 @@ void DesignModeWidget::setup()
|
||||
const QString uniqueId = idString.remove(" "); // title without whitespaces
|
||||
|
||||
// Apply stylesheet to QWidget
|
||||
QByteArray sheet = Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css");
|
||||
QString sheet = Utils::FileUtils::fetchQrc(":/qmldesigner/stylesheet.css");
|
||||
sheet += "QLabel { background-color: creatorTheme.DSsectionHeadBackground; }";
|
||||
navigationView.widget->setStyleSheet(Theme::replaceCssColors(QString::fromUtf8(sheet)));
|
||||
navigationView.widget->setStyleSheet(Theme::replaceCssColors(sheet));
|
||||
|
||||
ensureMinimumSize(navigationView.widget);
|
||||
|
||||
|
@@ -326,14 +326,14 @@ static QString imagePlaceHolderPath(AbstractView *view)
|
||||
return QString::fromLatin1(imagePlaceHolder);
|
||||
}
|
||||
|
||||
static QByteArray getSourceForUrl(const QString &fileURl)
|
||||
static QString getSourceForUrl(const QString &fileURl)
|
||||
{
|
||||
Utils::FileReader fileReader;
|
||||
|
||||
if (fileReader.fetch(Utils::FilePath::fromString(fileURl)))
|
||||
return fileReader.data();
|
||||
else
|
||||
return Utils::FileReader::fetchQrc(fileURl);
|
||||
return QString::fromUtf8(fileReader.data());
|
||||
|
||||
return Utils::FileUtils::fetchQrc(fileURl);
|
||||
}
|
||||
|
||||
QmlObjectNode QmlVisualNode::createQmlObjectNode(AbstractView *view,
|
||||
@@ -396,7 +396,7 @@ QmlObjectNode QmlVisualNode::createQmlObjectNode(AbstractView *view,
|
||||
nodeSourceType));
|
||||
#endif
|
||||
} else {
|
||||
const auto templateContent = QString::fromUtf8(getSourceForUrl(templatePath));
|
||||
const QString templateContent = getSourceForUrl(templatePath);
|
||||
newQmlObjectNode = createQmlObjectNodeFromSource(view, templateContent, position);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user