Add lacking qrc files into the project

Task-number: QTCREATORBUG-9610

Change-Id: I3f98ce154e05f419ea8a3c45a18eb9df51b5cfa2
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
jkobus
2013-08-30 15:55:51 +02:00
committed by Jarek Kobus
parent 5fcdb73e4d
commit 17e2847f7e
3 changed files with 35 additions and 5 deletions

View File

@@ -111,7 +111,7 @@ bool FormWindowEditor::open(QString *errorString, const QString &fileName, const
d->m_widget->formWindowFile()->setShouldAutoSave(false);
if (Internal::ResourceHandler *rh = form->findChild<Designer::Internal::ResourceHandler*>())
rh->updateResources();
rh->updateResources(true);
return true;
}

View File

@@ -89,7 +89,8 @@ ResourceHandler::ResourceHandler(qdesigner_internal::FormWindowBase *fw) :
QObject(fw),
m_form(fw),
m_sessionNode(0),
m_sessionWatcher(0)
m_sessionWatcher(0),
m_handlingResources(false)
{
}
@@ -124,8 +125,11 @@ ResourceHandler::~ResourceHandler()
}
}
void ResourceHandler::updateResources()
void ResourceHandler::updateResources(bool updateProjectResources)
{
if (m_handlingResources)
return;
ensureInitialized();
const QString fileName = m_form->fileName();
@@ -136,6 +140,9 @@ void ResourceHandler::updateResources()
// Filename could change in the meantime.
Project *project = SessionManager::projectForFile(fileName);
const bool dirty = m_form->property("_q_resourcepathchanged").toBool();
if (dirty)
m_form->setDirty(true);
// Does the file belong to a project?
if (project) {
@@ -143,7 +150,29 @@ void ResourceHandler::updateResources()
ProjectNode *root = project->rootProjectNode();
QrcFilesVisitor qrcVisitor;
root->accept(&qrcVisitor);
const QStringList projectQrcFiles = qrcVisitor.qrcFiles();
QStringList projectQrcFiles = qrcVisitor.qrcFiles();
// Check if the user has chosen to update the lacking resource inside designer
if (dirty && updateProjectResources) {
QStringList qrcPathsToBeAdded;
foreach (const QString &originalQrcPath, m_originalUiQrcPaths) {
if (!projectQrcFiles.contains(originalQrcPath) && !qrcPathsToBeAdded.contains(originalQrcPath))
qrcPathsToBeAdded.append(originalQrcPath);
}
if (!qrcPathsToBeAdded.isEmpty()) {
m_handlingResources = true;
root->addFiles(qrcPathsToBeAdded);
m_handlingResources = false;
projectQrcFiles += qrcPathsToBeAdded;
}
}
QStringList originalSorted = m_originalUiQrcPaths;
originalSorted.sort();
QStringList projectSorted = projectQrcFiles;
projectSorted.sort();
if (originalSorted != projectSorted)
m_form->setDirty(true);
#if QT_VERSION >= 0x050000
m_form->activateResourceFilePaths(projectQrcFiles);
m_form->setResourceFileSaveMode(QDesignerFormWindowInterface::SaveOnlyUsedResourceFiles);

View File

@@ -73,7 +73,7 @@ public:
virtual ~ResourceHandler();
public slots:
void updateResources();
void updateResources(bool updateProjectResources = false);
private:
void ensureInitialized();
@@ -85,6 +85,7 @@ private:
QStringList m_originalUiQrcPaths;
ProjectExplorer::SessionNode *m_sessionNode;
ProjectExplorer::NodesWatcher *m_sessionWatcher;
bool m_handlingResources;
};
} // namespace Internal