aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/resourceeditor
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2024-01-16 18:16:01 +0100
committerhjk <hjk@qt.io>2024-01-16 17:28:35 +0000
commita7bf47bf4970f5246378e8cfbc3a226e2501dcfe (patch)
treeb63db48fca021c286195515a442c694ac21b0c0e /src/plugins/resourceeditor
parentfc36218d390e6706c4b14cd80f63bf65ec9d5f0f (diff)
ResourceEditor: Move ResourceEditorW definition to .cpp
And simplify constructor. Change-Id: Ib0526f468aed0604a6b71ac180c02e408318f4ce Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Diffstat (limited to 'src/plugins/resourceeditor')
-rw-r--r--src/plugins/resourceeditor/resourceeditorw.cpp107
-rw-r--r--src/plugins/resourceeditor/resourceeditorw.h50
2 files changed, 75 insertions, 82 deletions
diff --git a/src/plugins/resourceeditor/resourceeditorw.cpp b/src/plugins/resourceeditor/resourceeditorw.cpp
index 1c52e956d2..bde597e3fb 100644
--- a/src/plugins/resourceeditor/resourceeditorw.cpp
+++ b/src/plugins/resourceeditor/resourceeditorw.cpp
@@ -5,7 +5,6 @@
#include "projectexplorer/projectexplorerconstants.h"
#include "resourceeditorconstants.h"
-#include "resourceeditorplugin.h"
#include "resourceeditortr.h"
#include "qrceditor/qrceditor.h"
#include "qrceditor/resourcefile_p.h"
@@ -28,19 +27,13 @@
#include <QMenu>
#include <QToolBar>
+using namespace Core;
using namespace Utils;
namespace ResourceEditor::Internal {
enum { debugResourceEditorW = 0 };
-static ResourceEditorW *currentEditor()
-{
- auto const focusEditor = qobject_cast<ResourceEditorW *>(Core::EditorManager::currentEditor());
- QTC_ASSERT(focusEditor, return nullptr);
- return focusEditor;
-}
-
QAction *m_redoAction = nullptr;
QAction *m_undoAction = nullptr;
QAction *m_refreshAction = nullptr;
@@ -60,17 +53,67 @@ ResourceEditorDocument::ResourceEditorDocument(QObject *parent) :
qDebug() << "ResourceEditorFile::ResourceEditorFile()";
}
-ResourceEditorW::ResourceEditorW(const Core::Context &context, QWidget *parent)
- : m_resourceDocument(new ResourceEditorDocument(this)),
- m_contextMenu(new QMenu),
- m_toolBar(new QToolBar)
+class ResourceEditorW final : public IEditor
+{
+ Q_OBJECT
+
+public:
+ ResourceEditorW();
+ ~ResourceEditorW() final;
+
+ static ResourceEditorW *currentEditor()
+ {
+ auto const focusEditor = qobject_cast<ResourceEditorW *>(EditorManager::currentEditor());
+ QTC_ASSERT(focusEditor, return nullptr);
+ return focusEditor;
+ }
+
+ IDocument *document() const final { return m_resourceDocument; }
+ QByteArray saveState() const final;
+ void restoreState(const QByteArray &state) final;
+ QWidget *toolBar() final;
+
+private:
+ void onUndoStackChanged(bool canUndo, bool canRedo);
+ void showContextMenu(const QPoint &globalPoint, const QString &fileName);
+ void openCurrentFile();
+ void openFile(const QString &fileName);
+ void renameCurrentFile();
+ void copyCurrentResourcePath();
+ void orderList();
+
+ const QString m_extension;
+ const QString m_fileFilter;
+ QString m_displayName;
+ QrcEditor *m_resourceEditor;
+ ResourceEditorDocument *m_resourceDocument;
+ QMenu *m_contextMenu;
+ QMenu *m_openWithMenu;
+ QString m_currentFileName;
+ QToolBar *m_toolBar;
+ QAction *m_renameAction;
+ QAction *m_copyFileNameAction;
+ QAction *m_orderList;
+
+public:
+ void onRefresh();
+ void onUndo();
+ void onRedo();
+
+ friend class ResourceEditorDocument;
+};
+
+ResourceEditorW::ResourceEditorW()
+ : m_resourceDocument(new ResourceEditorDocument(this)),
+ m_contextMenu(new QMenu),
+ m_toolBar(new QToolBar)
{
- m_resourceEditor = new QrcEditor(m_resourceDocument->model(), parent);
+ m_resourceEditor = new QrcEditor(m_resourceDocument->model(), nullptr);
- setContext(context);
+ setContext(Context(Constants::C_RESOURCEEDITOR));
setWidget(m_resourceEditor);
- Core::CommandButton *refreshButton = new Core::CommandButton(Constants::REFRESH, m_toolBar);
+ CommandButton *refreshButton = new CommandButton(Constants::REFRESH, m_toolBar);
refreshButton->setIcon(QIcon(QLatin1String(":/texteditor/images/finddocuments.png")));
connect(refreshButton, &QAbstractButton::clicked, this, &ResourceEditorW::onRefresh);
m_toolBar->addWidget(refreshButton);
@@ -106,9 +149,9 @@ ResourceEditorW::~ResourceEditorW()
delete m_toolBar;
}
-Core::IDocument::OpenResult ResourceEditorDocument::open(QString *errorString,
- const FilePath &filePath,
- const FilePath &realFilePath)
+IDocument::OpenResult ResourceEditorDocument::open(QString *errorString,
+ const FilePath &filePath,
+ const FilePath &realFilePath)
{
if (debugResourceEditorW)
qDebug() << "ResourceEditorW::open: " << filePath;
@@ -180,7 +223,7 @@ bool ResourceEditorDocument::setContents(const QByteArray &contents)
{
TempFileSaver saver;
saver.write(contents);
- if (!saver.finalize(Core::ICore::dialogParent()))
+ if (!saver.finalize(ICore::dialogParent()))
return false;
const FilePath originalFileName = m_model->filePath();
@@ -282,7 +325,7 @@ void ResourceEditorW::onUndoStackChanged(bool canUndo, bool canRedo)
void ResourceEditorW::showContextMenu(const QPoint &globalPoint, const QString &fileName)
{
- Core::EditorManager::populateOpenWithMenu(m_openWithMenu, FilePath::fromString(fileName));
+ EditorManager::populateOpenWithMenu(m_openWithMenu, FilePath::fromString(fileName));
m_currentFileName = fileName;
m_renameAction->setEnabled(!document()->isFileReadOnly());
m_contextMenu->popup(globalPoint);
@@ -295,7 +338,7 @@ void ResourceEditorW::openCurrentFile()
void ResourceEditorW::openFile(const QString &fileName)
{
- Core::EditorManager::openEditor(FilePath::fromString(fileName));
+ EditorManager::openEditor(FilePath::fromString(fileName));
}
void ResourceEditorW::onRefresh()
@@ -328,7 +371,7 @@ void ResourceEditorW::onRedo()
m_resourceEditor->onRedo();
}
-class ResourceEditorFactory final : public Core::IEditorFactory
+class ResourceEditorFactory final : public IEditorFactory
{
public:
ResourceEditorFactory()
@@ -340,9 +383,7 @@ public:
FileIconProvider::registerIconOverlayForSuffix(
ProjectExplorer::Constants::FILEOVERLAY_QRC, "qrc");
- setEditorCreator([] {
- return new ResourceEditorW(Core::Context(Constants::C_RESOURCEEDITOR));
- });
+ setEditorCreator([] { return new ResourceEditorW; });
}
};
@@ -351,29 +392,31 @@ void setupResourceEditor(QObject *guard)
static ResourceEditorFactory theResourceEditorFactory;
// Register undo and redo
- const Core::Context context(Constants::C_RESOURCEEDITOR);
+ const Context context(Constants::C_RESOURCEEDITOR);
m_undoAction = new QAction(Tr::tr("&Undo"), guard);
m_redoAction = new QAction(Tr::tr("&Redo"), guard);
m_refreshAction = new QAction(Tr::tr("Recheck Existence of Referenced Files"), guard);
- Core::ActionManager::registerAction(m_undoAction, Core::Constants::UNDO, context);
- Core::ActionManager::registerAction(m_redoAction, Core::Constants::REDO, context);
- Core::ActionManager::registerAction(m_refreshAction, Constants::REFRESH, context);
+ ActionManager::registerAction(m_undoAction, Core::Constants::UNDO, context);
+ ActionManager::registerAction(m_redoAction, Core::Constants::REDO, context);
+ ActionManager::registerAction(m_refreshAction, Constants::REFRESH, context);
QObject::connect(m_undoAction, &QAction::triggered, guard, [] {
- if (ResourceEditorW *editor = currentEditor())
+ if (ResourceEditorW *editor = ResourceEditorW::currentEditor())
editor->onUndo();
});
QObject::connect(m_redoAction, &QAction::triggered, guard, [] {
- if (ResourceEditorW *editor = currentEditor())
+ if (ResourceEditorW *editor = ResourceEditorW::currentEditor())
editor->onRedo();
});
QObject::connect(m_refreshAction, &QAction::triggered, guard, [] {
- if (ResourceEditorW *editor = currentEditor())
+ if (ResourceEditorW *editor = ResourceEditorW::currentEditor())
editor->onRefresh();
});
}
} // ResourceEditor::Internal
+
+#include "resourceeditorw.moc"
diff --git a/src/plugins/resourceeditor/resourceeditorw.h b/src/plugins/resourceeditor/resourceeditorw.h
index 24702885a5..7f434016a9 100644
--- a/src/plugins/resourceeditor/resourceeditorw.h
+++ b/src/plugins/resourceeditor/resourceeditorw.h
@@ -4,12 +4,6 @@
#pragma once
#include <coreplugin/idocument.h>
-#include <coreplugin/editormanager/ieditor.h>
-
-QT_BEGIN_NAMESPACE
-class QMenu;
-class QToolBar;
-QT_END_NAMESPACE
namespace ResourceEditor::Internal {
@@ -56,50 +50,6 @@ private:
bool m_shouldAutoSave = false;
};
-class ResourceEditorW : public Core::IEditor
-{
- Q_OBJECT
-
-public:
- ResourceEditorW(const Core::Context &context, QWidget *parent = nullptr);
- ~ResourceEditorW() override;
-
- // IEditor
- Core::IDocument *document() const override { return m_resourceDocument; }
- QByteArray saveState() const override;
- void restoreState(const QByteArray &state) override;
- QWidget *toolBar() override;
-
-private:
- void onUndoStackChanged(bool canUndo, bool canRedo);
- void showContextMenu(const QPoint &globalPoint, const QString &fileName);
- void openCurrentFile();
- void openFile(const QString &fileName);
- void renameCurrentFile();
- void copyCurrentResourcePath();
- void orderList();
-
- const QString m_extension;
- const QString m_fileFilter;
- QString m_displayName;
- QrcEditor *m_resourceEditor;
- ResourceEditorDocument *m_resourceDocument;
- QMenu *m_contextMenu;
- QMenu *m_openWithMenu;
- QString m_currentFileName;
- QToolBar *m_toolBar;
- QAction *m_renameAction;
- QAction *m_copyFileNameAction;
- QAction *m_orderList;
-
-public:
- void onRefresh();
- void onUndo();
- void onRedo();
-
- friend class ResourceEditorDocument;
-};
-
void setupResourceEditor(QObject *guard);
} // ResourceEditor::Internal