ResourceNode: Add some tests for actual node types

Change-Id: I20297df727adf2058583b64975e7a6848bc80263
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2017-02-28 10:55:29 +01:00
parent a2b47b7da2
commit 28b6c4f671
2 changed files with 19 additions and 11 deletions

View File

@@ -229,7 +229,8 @@ void ResourceEditorPlugin::onRefresh()
void ResourceEditorPlugin::addPrefixContextMenu()
{
auto topLevel = static_cast<ResourceTopLevelNode *>(ProjectTree::currentNode());
auto topLevel = dynamic_cast<ResourceTopLevelNode *>(ProjectTree::currentNode());
QTC_ASSERT(topLevel, return);
PrefixLangDialog dialog(tr("Add Prefix"), QString(), QString(), Core::ICore::mainWindow());
if (dialog.exec() != QDialog::Accepted)
return;
@@ -241,7 +242,8 @@ void ResourceEditorPlugin::addPrefixContextMenu()
void ResourceEditorPlugin::removePrefixContextMenu()
{
ResourceFolderNode *rfn = static_cast<ResourceFolderNode *>(ProjectTree::currentNode());
auto rfn = dynamic_cast<ResourceFolderNode *>(ProjectTree::currentNode());
QTC_ASSERT(rfn, return);
if (QMessageBox::question(Core::ICore::mainWindow(),
tr("Remove Prefix"),
tr("Remove prefix %1 and all its files?").arg(rfn->displayName()))
@@ -253,7 +255,8 @@ void ResourceEditorPlugin::removePrefixContextMenu()
void ResourceEditorPlugin::removeNonExisting()
{
ResourceTopLevelNode *topLevel = static_cast<ResourceTopLevelNode *>(ProjectTree::currentNode());
auto topLevel = dynamic_cast<ResourceTopLevelNode *>(ProjectTree::currentNode());
QTC_ASSERT(topLevel, return);
topLevel->removeNonExistingFiles();
}
@@ -264,7 +267,8 @@ void ResourceEditorPlugin::renameFileContextMenu()
void ResourceEditorPlugin::removeFileContextMenu()
{
ResourceFolderNode *rfn = static_cast<ResourceFolderNode *>(ProjectTree::currentNode());
auto rfn = dynamic_cast<ResourceFolderNode *>(ProjectTree::currentNode());
QTC_ASSERT(rfn, return);
QString path = rfn->filePath().toString();
FolderNode *parent = rfn->parentFolderNode();
if (!parent->removeFiles(QStringList() << path))
@@ -280,19 +284,22 @@ void ResourceEditorPlugin::openEditorContextMenu()
void ResourceEditorPlugin::copyPathContextMenu()
{
ResourceFileNode *node = static_cast<ResourceFileNode *>(ProjectTree::currentNode());
auto node = dynamic_cast<ResourceFileNode *>(ProjectTree::currentNode());
QTC_ASSERT(node, return);
QApplication::clipboard()->setText(QLatin1String(resourcePrefix) + node->qrcPath());
}
void ResourceEditorPlugin::copyUrlContextMenu()
{
ResourceFileNode *node = static_cast<ResourceFileNode *>(ProjectTree::currentNode());
auto node = dynamic_cast<ResourceFileNode *>(ProjectTree::currentNode());
QTC_ASSERT(node, return);
QApplication::clipboard()->setText(QLatin1String(urlPrefix) + node->qrcPath());
}
void ResourceEditorPlugin::renamePrefixContextMenu()
{
ResourceFolderNode *node = static_cast<ResourceFolderNode *>(ProjectTree::currentNode());
auto node = dynamic_cast<ResourceFolderNode *>(ProjectTree::currentNode());
QTC_ASSERT(node, return);
PrefixLangDialog dialog(tr("Rename Prefix"), node->prefix(), node->lang(), Core::ICore::mainWindow());
if (dialog.exec() != QDialog::Accepted)
@@ -350,7 +357,8 @@ void ResourceEditorPlugin::updateContextActions()
m_copyUrl->setEnabled(isResourceFile);
m_copyUrl->setVisible(isResourceFile);
if (isResourceFile) {
ResourceFileNode *fileNode = static_cast<ResourceFileNode *>(node);
auto fileNode = dynamic_cast<ResourceFileNode *>(node);
QTC_ASSERT(fileNode, return);
QString qrcPath = fileNode->qrcPath();
m_copyPath->setParameter(QLatin1String(resourcePrefix) + qrcPath);
m_copyUrl->setParameter(QLatin1String(urlPrefix) + qrcPath);

View File

@@ -304,10 +304,10 @@ ProjectExplorer::FolderNode::AddNewInformation ResourceTopLevelNode::addNewInfor
// The ResourceFolderNode '/' defers to us, as otherwise
// two nodes would be responsible for '/'
// Thus also return a high priority for it
if (ResourceFolderNode *rfn = dynamic_cast<ResourceFolderNode *>(context))
if (auto rfn = dynamic_cast<ResourceFolderNode *>(context))
if (rfn->prefix() == QLatin1String("/") && rfn->parentFolderNode() == this)
p = 120;
if (SimpleResourceFolderNode *rfn = dynamic_cast<SimpleResourceFolderNode *>(context))
if (auto rfn = dynamic_cast<SimpleResourceFolderNode *>(context))
if (rfn->prefix() == QLatin1String("/") && rfn->resourceNode() == this)
p = 120;
}
@@ -456,7 +456,7 @@ ProjectExplorer::FolderNode::AddNewInformation ResourceFolderNode::addNewInforma
if (context == this)
p = 120;
if (SimpleResourceFolderNode *sfn = dynamic_cast<SimpleResourceFolderNode *>(context)) {
if (auto sfn = dynamic_cast<SimpleResourceFolderNode *>(context)) {
if (sfn->prefixNode() == this)
p = 120;
}