forked from qt-creator/qt-creator
Design mode/Qt Designer clean-up, part III: Resources.
Move resource code to new ResourceHandler class and instantiate it on the form window.
This commit is contained in:
@@ -40,7 +40,8 @@ HEADERS += formeditorplugin.h \
|
||||
designercontext.h \
|
||||
faketoolbar.h \
|
||||
formeditorstack.h \
|
||||
editordata.h
|
||||
editordata.h \
|
||||
resourcehandler.h
|
||||
|
||||
SOURCES += formeditorplugin.cpp \
|
||||
formeditorfactory.cpp \
|
||||
@@ -58,7 +59,8 @@ SOURCES += formeditorplugin.cpp \
|
||||
designerxmleditor.cpp \
|
||||
designercontext.cpp \
|
||||
faketoolbar.cpp \
|
||||
formeditorstack.cpp
|
||||
formeditorstack.cpp \
|
||||
resourcehandler.cpp
|
||||
|
||||
RESOURCES += designer.qrc
|
||||
|
||||
|
||||
@@ -29,8 +29,10 @@
|
||||
|
||||
#include "designerxmleditor.h"
|
||||
#include "designerconstants.h"
|
||||
#include "resourcehandler.h"
|
||||
#include "qt_private/formwindowbase_p.h"
|
||||
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/modemanager.h>
|
||||
@@ -124,6 +126,9 @@ bool DesignerXmlEditorEditable::open(const QString &fileName)
|
||||
setDisplayName(fi.fileName());
|
||||
m_file.setFileName(absfileName);
|
||||
|
||||
if (Internal::ResourceHandler *rh = qFindChild<Designer::Internal::ResourceHandler*>(form))
|
||||
rh->updateResources();
|
||||
|
||||
emit changed();
|
||||
|
||||
return true;
|
||||
|
||||
@@ -39,6 +39,8 @@ namespace Internal {
|
||||
// Associates XML and its form editor
|
||||
struct EditorData {
|
||||
EditorData() : xmlEditor(0), formEditor(0) {}
|
||||
operator bool() const { return xmlEditor != 0; }
|
||||
|
||||
DesignerXmlEditorEditable *xmlEditor;
|
||||
Designer::FormWindowEditor *formEditor;
|
||||
};
|
||||
|
||||
@@ -112,9 +112,9 @@ Designer::FormWindowEditor *EditorWidget::formWindowEditorForXmlEditor(const Cor
|
||||
return m_stack->formWindowEditorForXmlEditor(xmlEditor);
|
||||
}
|
||||
|
||||
FormWindowEditor *EditorWidget::activeFormWindow() const
|
||||
EditorData EditorWidget::activeEditor() const
|
||||
{
|
||||
return m_stack->activeFormWindow();
|
||||
return m_stack->activeEditor();
|
||||
}
|
||||
|
||||
Designer::FormWindowEditor *EditorWidget::formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const
|
||||
|
||||
@@ -66,7 +66,8 @@ public:
|
||||
bool setVisibleEditor(Core::IEditor *xmlEditor);
|
||||
Designer::FormWindowEditor *formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const;
|
||||
Designer::FormWindowEditor *formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const;
|
||||
FormWindowEditor *activeFormWindow() const;
|
||||
|
||||
EditorData activeEditor() const;
|
||||
|
||||
public slots:
|
||||
void resetToDefaultLayout();
|
||||
|
||||
@@ -93,12 +93,15 @@ int FormEditorStack::indexOf(const Core::IEditor *xmlEditor) const
|
||||
return -1;
|
||||
}
|
||||
|
||||
FormWindowEditor *FormEditorStack::activeFormWindow() const
|
||||
EditorData FormEditorStack::activeEditor() const
|
||||
{
|
||||
if (QDesignerFormWindowInterface *afw = m_designerCore->formWindowManager()->activeFormWindow())
|
||||
if (FormWindowEditor *fwe = formWindowEditorForFormWindow(afw))
|
||||
return fwe;
|
||||
return 0;
|
||||
// Should actually be in sync with current index.
|
||||
if (QDesignerFormWindowInterface *afw = m_designerCore->formWindowManager()->activeFormWindow()) {
|
||||
const int index = indexOf(afw);
|
||||
if (index >= 0)
|
||||
return m_formEditors.at(index);
|
||||
}
|
||||
return EditorData();
|
||||
}
|
||||
|
||||
Designer::FormWindowEditor *FormEditorStack::formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const
|
||||
|
||||
@@ -70,7 +70,8 @@ public:
|
||||
bool setVisibleEditor(Core::IEditor *xmlEditor);
|
||||
Designer::FormWindowEditor *formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const;
|
||||
Designer::FormWindowEditor *formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const;
|
||||
FormWindowEditor *activeFormWindow() const;
|
||||
|
||||
EditorData activeEditor() const;
|
||||
|
||||
private slots:
|
||||
void updateFormWindowSelectionHandles();
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "designerxmleditor.h"
|
||||
#include "designercontext.h"
|
||||
#include "editorwidget.h"
|
||||
#include "resourcehandler.h"
|
||||
|
||||
#include <coreplugin/modemanager.h>
|
||||
#include <coreplugin/designmode.h>
|
||||
@@ -662,15 +663,17 @@ EditorData FormEditorW::createEditor(QWidget *parent)
|
||||
qdesigner_internal::FormWindowBase *form = qobject_cast<qdesigner_internal::FormWindowBase *>(m_fwm->createFormWindow(0));
|
||||
QTC_ASSERT(form, return data);
|
||||
connect(form, SIGNAL(toolChanged(int)), this, SLOT(toolChanged(int)));
|
||||
ResourceHandler *resourceHandler = new ResourceHandler(form);
|
||||
form->setDesignerGrid(qdesigner_internal::FormWindowBase::defaultDesignerGrid());
|
||||
qdesigner_internal::FormWindowBase::setupDefaultAction(form);
|
||||
data.formEditor = new FormWindowEditor(form);
|
||||
DesignerXmlEditor *xmlEditor = new DesignerXmlEditor(form, parent);
|
||||
TextEditor::TextEditorSettings::instance()->initializeEditor(xmlEditor);
|
||||
data.xmlEditor = xmlEditor->designerEditable();
|
||||
data.formEditor->setFile(data.xmlEditor->file());
|
||||
connect(data.formEditor, SIGNAL(formWindowSizeChanged(int,int)),
|
||||
xmlEditor, SIGNAL(changed()));
|
||||
connect(data.xmlEditor->file(), SIGNAL(changed()),
|
||||
resourceHandler, SLOT(updateResources()));
|
||||
m_editorWidget->add(data);
|
||||
return data;
|
||||
}
|
||||
@@ -720,11 +723,11 @@ void FormEditorW::activeFormWindowChanged(QDesignerFormWindowInterface *afw)
|
||||
m_actionGroupPreviewInStyle->setEnabled(afw != 0);
|
||||
}
|
||||
|
||||
FormWindowEditor *FormEditorW::activeFormWindow() const
|
||||
EditorData FormEditorW::activeEditor() const
|
||||
{
|
||||
if (m_editorWidget)
|
||||
return m_editorWidget->activeFormWindow();
|
||||
return 0;
|
||||
return m_editorWidget->activeEditor();
|
||||
return EditorData();
|
||||
}
|
||||
|
||||
void FormEditorW::activateEditMode(int id)
|
||||
|
||||
@@ -114,7 +114,7 @@ public:
|
||||
inline QDesignerFormEditorInterface *designerEditor() const { return m_formeditor; }
|
||||
inline QWidget * const*designerSubWindows() const { return m_designerSubWindows; }
|
||||
|
||||
FormWindowEditor *activeFormWindow() const;
|
||||
EditorData activeEditor() const;
|
||||
|
||||
private slots:
|
||||
void activateEditMode(int id);
|
||||
|
||||
@@ -32,13 +32,6 @@
|
||||
#include "formeditorw.h"
|
||||
|
||||
#include <coreplugin/ifile.h>
|
||||
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/projectnodes.h>
|
||||
#include <projectexplorer/nodesvisitor.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/session.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QtDesigner/QDesignerFormWindowInterface>
|
||||
@@ -46,123 +39,20 @@
|
||||
#include <QtDesigner/QDesignerFormWindowManagerInterface>
|
||||
#include <QtDesigner/QDesignerPropertyEditorInterface>
|
||||
#include "qt_private/formwindowbase_p.h"
|
||||
#include "qt_private/qtresourcemodel_p.h"
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
using namespace Designer;
|
||||
using namespace Designer::Internal;
|
||||
using namespace Designer::Constants;
|
||||
using namespace SharedTools;
|
||||
using ProjectExplorer::NodesVisitor;
|
||||
using ProjectExplorer::ProjectNode;
|
||||
using ProjectExplorer::FolderNode;
|
||||
using ProjectExplorer::FileNode;
|
||||
|
||||
class QrcFilesVisitor : public NodesVisitor
|
||||
{
|
||||
public:
|
||||
QStringList qrcFiles() const;
|
||||
|
||||
void visitProjectNode(ProjectNode *node);
|
||||
void visitFolderNode(FolderNode *node);
|
||||
private:
|
||||
QStringList m_qrcFiles;
|
||||
};
|
||||
|
||||
QStringList QrcFilesVisitor::qrcFiles() const
|
||||
{
|
||||
return m_qrcFiles;
|
||||
}
|
||||
|
||||
void QrcFilesVisitor::visitProjectNode(ProjectNode *projectNode)
|
||||
{
|
||||
visitFolderNode(projectNode);
|
||||
}
|
||||
|
||||
void QrcFilesVisitor::visitFolderNode(FolderNode *folderNode)
|
||||
{
|
||||
foreach (const FileNode *fileNode, folderNode->fileNodes()) {
|
||||
if (fileNode->fileType() == ProjectExplorer::ResourceType)
|
||||
m_qrcFiles.append(fileNode->path());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FormWindowEditor::FormWindowEditor(QDesignerFormWindowInterface *form,
|
||||
QWidget *parent) :
|
||||
SharedTools::WidgetHost(parent, form),
|
||||
m_file(0),
|
||||
m_sessionNode(0),
|
||||
m_sessionWatcher(0)
|
||||
SharedTools::WidgetHost(parent, form)
|
||||
{
|
||||
connect(this, SIGNAL(formWindowSizeChanged(int,int)), this, SLOT(slotFormSizeChanged(int,int)));
|
||||
}
|
||||
|
||||
void FormWindowEditor::setFile(Core::IFile *file)
|
||||
{
|
||||
m_file = file;
|
||||
}
|
||||
|
||||
FormWindowEditor::~FormWindowEditor()
|
||||
{
|
||||
// Close: Delete the Designer form window via embedding widget
|
||||
if (m_sessionNode && m_sessionWatcher) {
|
||||
m_sessionNode->unregisterWatcher(m_sessionWatcher);
|
||||
delete m_sessionWatcher;
|
||||
}
|
||||
}
|
||||
|
||||
void FormWindowEditor::initializeResources(const QString & /* fileName */)
|
||||
{
|
||||
ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance();
|
||||
ProjectExplorer::SessionManager *session = pe->session();
|
||||
|
||||
m_sessionNode = session->sessionNode();
|
||||
m_sessionWatcher = new ProjectExplorer::NodesWatcher();
|
||||
|
||||
connect(m_sessionWatcher, SIGNAL(filesAdded()), this, SLOT(updateResources()));
|
||||
connect(m_sessionWatcher, SIGNAL(filesRemoved()), this, SLOT(updateResources()));
|
||||
connect(m_sessionWatcher, SIGNAL(foldersAdded()), this, SLOT(updateResources()));
|
||||
connect(m_sessionWatcher, SIGNAL(foldersRemoved()), this, SLOT(updateResources()));
|
||||
m_sessionNode->registerWatcher(m_sessionWatcher);
|
||||
|
||||
if (qdesigner_internal::FormWindowBase *fw = qobject_cast<qdesigner_internal::FormWindowBase *>(formWindow())) {
|
||||
QtResourceSet *rs = fw->resourceSet();
|
||||
m_originalUiQrcPaths = rs->activeQrcPaths();
|
||||
}
|
||||
|
||||
updateResources();
|
||||
}
|
||||
|
||||
void FormWindowEditor::updateResources()
|
||||
{
|
||||
if (qdesigner_internal::FormWindowBase *fw = qobject_cast<qdesigner_internal::FormWindowBase *>(formWindow())) {
|
||||
ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance();
|
||||
// filename could change in the meantime.
|
||||
ProjectExplorer::Project *project = pe->session()->projectForFile(m_file->fileName());
|
||||
|
||||
qdesigner_internal::FormWindowBase::SaveResourcesBehaviour behaviour = qdesigner_internal::FormWindowBase::SaveAll;
|
||||
QtResourceSet *rs = fw->resourceSet();
|
||||
if (project) {
|
||||
ProjectNode *root = project->rootProjectNode();
|
||||
QrcFilesVisitor qrcVisitor;
|
||||
root->accept(&qrcVisitor);
|
||||
|
||||
rs->activateQrcPaths(qrcVisitor.qrcFiles());
|
||||
behaviour = qdesigner_internal::FormWindowBase::SaveOnlyUsedQrcFiles;
|
||||
} else {
|
||||
rs->activateQrcPaths(m_originalUiQrcPaths);
|
||||
}
|
||||
fw->setSaveResourcesBehaviour(behaviour);
|
||||
}
|
||||
}
|
||||
|
||||
Core::IFile *FormWindowEditor::file() const
|
||||
{
|
||||
return m_file;
|
||||
}
|
||||
|
||||
void FormWindowEditor::slotFormSizeChanged(int w, int h)
|
||||
{
|
||||
if (Designer::Constants::Internal::debug)
|
||||
|
||||
@@ -35,11 +35,6 @@
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QPointer>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
class SessionNode;
|
||||
class NodesWatcher;
|
||||
}
|
||||
|
||||
namespace Core {
|
||||
class IFile;
|
||||
}
|
||||
@@ -55,23 +50,9 @@ class FormWindowEditor : public SharedTools::WidgetHost
|
||||
public:
|
||||
explicit FormWindowEditor(QDesignerFormWindowInterface *form,
|
||||
QWidget *parent = 0);
|
||||
~FormWindowEditor();
|
||||
|
||||
void setFile(Core::IFile *file);
|
||||
QString contents() const;
|
||||
Core::IFile *file() const;
|
||||
|
||||
private slots:
|
||||
void updateResources();
|
||||
void slotFormSizeChanged(int w, int h);
|
||||
|
||||
private:
|
||||
void initializeResources(const QString &fileName = QString());
|
||||
|
||||
QPointer<Core::IFile> m_file;
|
||||
QStringList m_originalUiQrcPaths;
|
||||
ProjectExplorer::SessionNode *m_sessionNode;
|
||||
ProjectExplorer::NodesWatcher *m_sessionWatcher;
|
||||
};
|
||||
|
||||
} // namespace Designer
|
||||
|
||||
@@ -28,9 +28,11 @@
|
||||
**************************************************************************/
|
||||
|
||||
#include "formeditorplugin.h"
|
||||
#include "designerxmleditor.h"
|
||||
#include "qtcreatorintegration.h"
|
||||
#include "formeditorw.h"
|
||||
#include "formwindoweditor.h"
|
||||
#include "editordata.h"
|
||||
#include "codemodelhelpers.h"
|
||||
|
||||
#include <cpptools/cppmodelmanagerinterface.h>
|
||||
@@ -50,6 +52,7 @@
|
||||
#include <texteditor/itexteditable.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/session.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QtDesigner/QDesignerFormWindowInterface>
|
||||
#include <QtDesigner/QDesignerFormEditorInterface>
|
||||
@@ -95,17 +98,16 @@ QtCreatorIntegration::QtCreatorIntegration(QDesignerFormEditorInterface *core, F
|
||||
|
||||
void QtCreatorIntegration::updateSelection()
|
||||
{
|
||||
if (FormWindowEditor *afww = m_few->activeFormWindow())
|
||||
afww->updateFormWindowSelectionHandles(true);
|
||||
if (const EditorData ed = m_few->activeEditor())
|
||||
ed.formEditor->updateFormWindowSelectionHandles(true);
|
||||
qdesigner_internal::QDesignerIntegration::updateSelection();
|
||||
}
|
||||
|
||||
QWidget *QtCreatorIntegration::containerWindow(QWidget * /*widget*/) const
|
||||
{
|
||||
FormWindowEditor *fw = m_few->activeFormWindow();
|
||||
if (!fw)
|
||||
return 0;
|
||||
return fw->integrationContainer();
|
||||
if (const EditorData ed = m_few->activeEditor())
|
||||
return ed.formEditor->integrationContainer();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static QList<Document::Ptr> findDocumentsIncluding(const CPlusPlus::Snapshot &docTable,
|
||||
@@ -570,7 +572,9 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
|
||||
const QStringList ¶meterNames,
|
||||
QString *errorMessage)
|
||||
{
|
||||
const QString currentUiFile = m_few->activeFormWindow()->file()->fileName();
|
||||
const EditorData ed = m_few->activeEditor();
|
||||
QTC_ASSERT(ed, return false)
|
||||
const QString currentUiFile = ed.xmlEditor->file()->fileName();
|
||||
#if 0
|
||||
return Designer::Internal::navigateToSlot(currentUiFile, objectName, signalSignature, parameterNames, errorMessage);
|
||||
#endif
|
||||
@@ -609,7 +613,7 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
|
||||
return false;
|
||||
}
|
||||
|
||||
QDesignerFormWindowInterface *fwi = m_few->activeFormWindow()->formWindow();
|
||||
QDesignerFormWindowInterface *fwi = ed.formEditor->formWindow();
|
||||
|
||||
const QString uiClass = uiClassName(fwi->mainContainer()->objectName());
|
||||
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "resourcehandler.h"
|
||||
#include "designerconstants.h"
|
||||
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/projectnodes.h>
|
||||
#include <projectexplorer/nodesvisitor.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/session.h>
|
||||
|
||||
#include "qt_private/formwindowbase_p.h"
|
||||
#include "qt_private/qtresourcemodel_p.h"
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
using ProjectExplorer::NodesVisitor;
|
||||
using ProjectExplorer::ProjectNode;
|
||||
using ProjectExplorer::FolderNode;
|
||||
using ProjectExplorer::FileNode;
|
||||
|
||||
namespace Designer {
|
||||
namespace Internal {
|
||||
|
||||
// Visit project nodes and collect qrc-files.
|
||||
class QrcFilesVisitor : public NodesVisitor
|
||||
{
|
||||
public:
|
||||
QStringList qrcFiles() const;
|
||||
|
||||
void visitProjectNode(ProjectNode *node);
|
||||
void visitFolderNode(FolderNode *node);
|
||||
private:
|
||||
QStringList m_qrcFiles;
|
||||
};
|
||||
|
||||
QStringList QrcFilesVisitor::qrcFiles() const
|
||||
{
|
||||
return m_qrcFiles;
|
||||
}
|
||||
|
||||
void QrcFilesVisitor::visitProjectNode(ProjectNode *projectNode)
|
||||
{
|
||||
visitFolderNode(projectNode);
|
||||
}
|
||||
|
||||
void QrcFilesVisitor::visitFolderNode(FolderNode *folderNode)
|
||||
{
|
||||
foreach (const FileNode *fileNode, folderNode->fileNodes()) {
|
||||
if (fileNode->fileType() == ProjectExplorer::ResourceType)
|
||||
m_qrcFiles.append(fileNode->path());
|
||||
}
|
||||
}
|
||||
|
||||
// ------------ ResourceHandler
|
||||
ResourceHandler::ResourceHandler(qdesigner_internal::FormWindowBase *fw) :
|
||||
QObject(fw),
|
||||
m_form(fw),
|
||||
m_sessionNode(0),
|
||||
m_sessionWatcher(0)
|
||||
{
|
||||
}
|
||||
|
||||
void ResourceHandler::ensureInitialized()
|
||||
{
|
||||
if (m_sessionNode)
|
||||
return;
|
||||
ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance();
|
||||
ProjectExplorer::SessionManager *session = pe->session();
|
||||
|
||||
m_sessionNode = session->sessionNode();
|
||||
m_sessionWatcher = new ProjectExplorer::NodesWatcher();
|
||||
|
||||
connect(m_sessionWatcher, SIGNAL(filesAdded()), this, SLOT(updateResources()));
|
||||
connect(m_sessionWatcher, SIGNAL(filesRemoved()), this, SLOT(updateResources()));
|
||||
connect(m_sessionWatcher, SIGNAL(foldersAdded()), this, SLOT(updateResources()));
|
||||
connect(m_sessionWatcher, SIGNAL(foldersRemoved()), this, SLOT(updateResources()));
|
||||
m_sessionNode->registerWatcher(m_sessionWatcher);
|
||||
|
||||
m_originalUiQrcPaths = m_form->resourceSet()->activeQrcPaths();
|
||||
if (Designer::Constants::Internal::debug)
|
||||
qDebug() << "ResourceHandler::ensureInitialized() origPaths=" << m_originalUiQrcPaths;
|
||||
}
|
||||
|
||||
ResourceHandler::~ResourceHandler()
|
||||
{
|
||||
// Close: Delete the Designer form window via embedding widget
|
||||
if (m_sessionNode && m_sessionWatcher) {
|
||||
m_sessionNode->unregisterWatcher(m_sessionWatcher);
|
||||
delete m_sessionWatcher;
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceHandler::updateResources()
|
||||
{
|
||||
ensureInitialized();
|
||||
|
||||
const QString fileName = m_form->fileName();
|
||||
QTC_ASSERT(!fileName.isEmpty(), return)
|
||||
|
||||
if (Designer::Constants::Internal::debug)
|
||||
qDebug() << "ResourceHandler::updateResources()" << fileName;
|
||||
|
||||
ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance();
|
||||
// filename could change in the meantime.
|
||||
ProjectExplorer::Project *project = pe->session()->projectForFile(fileName);
|
||||
|
||||
// Does the file belong to a project?
|
||||
if (project) {
|
||||
// Collect project resource files.
|
||||
ProjectNode *root = project->rootProjectNode();
|
||||
QrcFilesVisitor qrcVisitor;
|
||||
root->accept(&qrcVisitor);
|
||||
const QStringList projectQrcFiles = qrcVisitor.qrcFiles();
|
||||
m_form->resourceSet()->activateQrcPaths(projectQrcFiles);
|
||||
m_form->setSaveResourcesBehaviour(qdesigner_internal::FormWindowBase::SaveOnlyUsedQrcFiles);
|
||||
if (Designer::Constants::Internal::debug)
|
||||
qDebug() << "ResourceHandler::updateResources()" << fileName
|
||||
<< " associated with project" << project->rootProjectNode()->path()
|
||||
<< " using project qrc files" << projectQrcFiles.size();
|
||||
} else {
|
||||
// Use resource file originally used in form
|
||||
m_form->resourceSet()->activateQrcPaths(m_originalUiQrcPaths);
|
||||
m_form->setSaveResourcesBehaviour(qdesigner_internal::FormWindowBase::SaveAll);
|
||||
if (Designer::Constants::Internal::debug)
|
||||
qDebug() << "ResourceHandler::updateResources()" << fileName << " not associated with project, using loaded qrc files.";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Designer
|
||||
@@ -0,0 +1,83 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef RESOURCEHANDLER_H
|
||||
#define RESOURCEHANDLER_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace qdesigner_internal {
|
||||
class FormWindowBase;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace ProjectExplorer {
|
||||
class SessionNode;
|
||||
class NodesWatcher;
|
||||
}
|
||||
|
||||
namespace Designer {
|
||||
namespace Internal {
|
||||
|
||||
/* ResourceHandler: Constructed on a form window and activated on open/save as
|
||||
* (see README.txt). The form can have 2 states:
|
||||
* 1) standalone: Uses the form editor's list of resource files.
|
||||
* 2) Within a project: Use the list of resources files of the projects.
|
||||
*
|
||||
* When initializing, store the original list of qrc files of the form and
|
||||
* connect to various signals of the project explorer to re-check.
|
||||
* In updateResources, check whether the form is part of a project and use
|
||||
* the project's resource files or the stored ones. */
|
||||
|
||||
class ResourceHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ResourceHandler(qdesigner_internal::FormWindowBase *fw);
|
||||
virtual ~ResourceHandler();
|
||||
|
||||
public slots:
|
||||
void updateResources();
|
||||
|
||||
private:
|
||||
void ensureInitialized();
|
||||
|
||||
qdesigner_internal::FormWindowBase * const m_form;
|
||||
|
||||
QStringList m_originalUiQrcPaths;
|
||||
ProjectExplorer::SessionNode *m_sessionNode;
|
||||
ProjectExplorer::NodesWatcher *m_sessionWatcher;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Designer
|
||||
|
||||
#endif // RESOURCEHANDLER_H
|
||||
Reference in New Issue
Block a user