diff options
author | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2010-03-09 17:01:34 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2010-03-09 17:01:51 +0100 |
commit | c7e3e6adf38dd94bbeb4c8de584fcefe24ae3ea7 (patch) | |
tree | 2dff1bae758d9871c158af6644868c536f3d5ff5 /src/plugins | |
parent | 8aae812558ab98960b808552446f10a752fb9611 (diff) | |
download | qt-creator-c7e3e6adf38dd94bbeb4c8de584fcefe24ae3ea7.tar.gz |
Design mode/Qt Designer clean-up, part III: Resources.
Move resource code to new ResourceHandler class and
instantiate it on the form window.
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/designer/designer.pro | 6 | ||||
-rw-r--r-- | src/plugins/designer/designerxmleditor.cpp | 5 | ||||
-rw-r--r-- | src/plugins/designer/editordata.h | 2 | ||||
-rw-r--r-- | src/plugins/designer/editorwidget.cpp | 4 | ||||
-rw-r--r-- | src/plugins/designer/editorwidget.h | 3 | ||||
-rw-r--r-- | src/plugins/designer/formeditorstack.cpp | 13 | ||||
-rw-r--r-- | src/plugins/designer/formeditorstack.h | 3 | ||||
-rw-r--r-- | src/plugins/designer/formeditorw.cpp | 11 | ||||
-rw-r--r-- | src/plugins/designer/formeditorw.h | 2 | ||||
-rw-r--r-- | src/plugins/designer/formwindoweditor.cpp | 112 | ||||
-rw-r--r-- | src/plugins/designer/formwindoweditor.h | 19 | ||||
-rw-r--r-- | src/plugins/designer/qtcreatorintegration.cpp | 20 | ||||
-rw-r--r-- | src/plugins/designer/resourcehandler.cpp | 158 | ||||
-rw-r--r-- | src/plugins/designer/resourcehandler.h | 83 |
14 files changed, 287 insertions, 154 deletions
diff --git a/src/plugins/designer/designer.pro b/src/plugins/designer/designer.pro index 9a28eb14b0..5bbc140976 100644 --- a/src/plugins/designer/designer.pro +++ b/src/plugins/designer/designer.pro @@ -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 diff --git a/src/plugins/designer/designerxmleditor.cpp b/src/plugins/designer/designerxmleditor.cpp index e6982bc917..0b063d0689 100644 --- a/src/plugins/designer/designerxmleditor.cpp +++ b/src/plugins/designer/designerxmleditor.cpp @@ -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; diff --git a/src/plugins/designer/editordata.h b/src/plugins/designer/editordata.h index 661c8e2024..26c37d9d2f 100644 --- a/src/plugins/designer/editordata.h +++ b/src/plugins/designer/editordata.h @@ -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; }; diff --git a/src/plugins/designer/editorwidget.cpp b/src/plugins/designer/editorwidget.cpp index 7e7ea571b5..3e6453f45a 100644 --- a/src/plugins/designer/editorwidget.cpp +++ b/src/plugins/designer/editorwidget.cpp @@ -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 diff --git a/src/plugins/designer/editorwidget.h b/src/plugins/designer/editorwidget.h index cf8041d235..4294f51d2d 100644 --- a/src/plugins/designer/editorwidget.h +++ b/src/plugins/designer/editorwidget.h @@ -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(); diff --git a/src/plugins/designer/formeditorstack.cpp b/src/plugins/designer/formeditorstack.cpp index 202c5fadaa..06d15b4ba3 100644 --- a/src/plugins/designer/formeditorstack.cpp +++ b/src/plugins/designer/formeditorstack.cpp @@ -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 diff --git a/src/plugins/designer/formeditorstack.h b/src/plugins/designer/formeditorstack.h index 94513924e5..c3fce4e8d8 100644 --- a/src/plugins/designer/formeditorstack.h +++ b/src/plugins/designer/formeditorstack.h @@ -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(); diff --git a/src/plugins/designer/formeditorw.cpp b/src/plugins/designer/formeditorw.cpp index 320be347a6..d8708305e0 100644 --- a/src/plugins/designer/formeditorw.cpp +++ b/src/plugins/designer/formeditorw.cpp @@ -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) diff --git a/src/plugins/designer/formeditorw.h b/src/plugins/designer/formeditorw.h index 48617ab62f..76f4b0ebd4 100644 --- a/src/plugins/designer/formeditorw.h +++ b/src/plugins/designer/formeditorw.h @@ -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); diff --git a/src/plugins/designer/formwindoweditor.cpp b/src/plugins/designer/formwindoweditor.cpp index df6f9a2b21..75a95329b5 100644 --- a/src/plugins/designer/formwindoweditor.cpp +++ b/src/plugins/designer/formwindoweditor.cpp @@ -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) diff --git a/src/plugins/designer/formwindoweditor.h b/src/plugins/designer/formwindoweditor.h index 20cccbe09c..5694902136 100644 --- a/src/plugins/designer/formwindoweditor.h +++ b/src/plugins/designer/formwindoweditor.h @@ -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 diff --git a/src/plugins/designer/qtcreatorintegration.cpp b/src/plugins/designer/qtcreatorintegration.cpp index 54ace337da..4cf1be7222 100644 --- a/src/plugins/designer/qtcreatorintegration.cpp +++ b/src/plugins/designer/qtcreatorintegration.cpp @@ -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()); diff --git a/src/plugins/designer/resourcehandler.cpp b/src/plugins/designer/resourcehandler.cpp new file mode 100644 index 0000000000..3187f11906 --- /dev/null +++ b/src/plugins/designer/resourcehandler.cpp @@ -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 diff --git a/src/plugins/designer/resourcehandler.h b/src/plugins/designer/resourcehandler.h new file mode 100644 index 0000000000..f793be5922 --- /dev/null +++ b/src/plugins/designer/resourcehandler.h @@ -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 |