forked from qt-creator/qt-creator
QmlDesigner: Show warning icons for each file
Task-number: QDS-3797 Change-Id: Ibcbed1a221e762e0e6a3b4f9f538b8e4b1f144d3 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
committed by
Thomas Hartmann
parent
0588161edd
commit
4c50ec85b7
@@ -228,7 +228,7 @@ QVariant FlatModel::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
case Qt::DecorationRole: {
|
||||
if (!folderNode)
|
||||
return Core::FileIconProvider::icon(node->filePath());
|
||||
return node->asFileNode()->icon();
|
||||
if (!project)
|
||||
return folderNode->icon();
|
||||
static QIcon warnIcon = Utils::Icons::WARNING.icon();
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include <utils/pointeralgorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/stringutils.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
@@ -252,6 +253,35 @@ bool Node::isEnabled() const
|
||||
return parent ? parent->isEnabled() : true;
|
||||
}
|
||||
|
||||
QIcon FileNode::icon() const
|
||||
{
|
||||
if (hasError())
|
||||
return Utils::Icons::WARNING.icon();
|
||||
if (m_icon.isNull())
|
||||
m_icon = Core::FileIconProvider::icon(filePath());
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
void FileNode::setIcon(const QIcon icon)
|
||||
{
|
||||
m_icon = icon;
|
||||
}
|
||||
|
||||
bool FileNode::hasError() const
|
||||
{
|
||||
return m_hasError;
|
||||
}
|
||||
|
||||
void FileNode::setHasError(bool error)
|
||||
{
|
||||
m_hasError = error;
|
||||
}
|
||||
|
||||
void FileNode::setHasError(bool error) const
|
||||
{
|
||||
m_hasError = error;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns \c true if the file is automatically generated by a compile step.
|
||||
*/
|
||||
|
||||
@@ -218,8 +218,17 @@ public:
|
||||
bool supportsAction(ProjectAction action, const Node *node) const override;
|
||||
QString displayName() const override;
|
||||
|
||||
bool hasError() const;
|
||||
void setHasError(const bool error);
|
||||
void setHasError(const bool error) const;
|
||||
|
||||
QIcon icon() const;
|
||||
void setIcon(const QIcon icon);
|
||||
|
||||
private:
|
||||
FileType m_fileType;
|
||||
mutable QIcon m_icon;
|
||||
mutable bool m_hasError = false;
|
||||
};
|
||||
|
||||
// Documentation inside.
|
||||
|
||||
@@ -46,6 +46,10 @@
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/session.h>
|
||||
#include <projectexplorer/projectnodes.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/icon.h>
|
||||
#include <utils/utilsicons.h>
|
||||
@@ -169,6 +173,28 @@ void NavigatorView::modelAttached(Model *model)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
clearExplorerWarnings();
|
||||
}
|
||||
|
||||
void NavigatorView::clearExplorerWarnings()
|
||||
{
|
||||
QList<ModelNode> allNodes;
|
||||
addNodeAndSubModelNodesToList(rootModelNode(), allNodes);
|
||||
for (ModelNode node : allNodes) {
|
||||
if (node.metaInfo().isFileComponent()) {
|
||||
const ProjectExplorer::FileNode *fnode = fileNodeForModelNode(node);
|
||||
fnode->setHasError(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NavigatorView::addNodeAndSubModelNodesToList(const ModelNode &node, QList<ModelNode> &nodes)
|
||||
{
|
||||
nodes.append(node);
|
||||
for (ModelNode subNode : node.allSubModelNodes()) {
|
||||
addNodeAndSubModelNodesToList(subNode, nodes);
|
||||
}
|
||||
}
|
||||
|
||||
void NavigatorView::modelAboutToBeDetached(Model *model)
|
||||
@@ -342,8 +368,10 @@ void NavigatorView::auxiliaryDataChanged(const ModelNode &modelNode,
|
||||
|
||||
void NavigatorView::instanceErrorChanged(const QVector<ModelNode> &errorNodeList)
|
||||
{
|
||||
for (const ModelNode &modelNode : errorNodeList)
|
||||
for (const ModelNode &modelNode : errorNodeList) {
|
||||
m_currentModelInterface->notifyDataChanged(modelNode);
|
||||
propagateInstanceErrorToExplorer(modelNode);
|
||||
}
|
||||
}
|
||||
|
||||
void NavigatorView::nodeOrderChanged(const NodeListProperty &listProperty)
|
||||
@@ -374,6 +402,41 @@ QAbstractItemModel *NavigatorView::currentModel() const
|
||||
return treeWidget()->model();
|
||||
}
|
||||
|
||||
const ProjectExplorer::FileNode *NavigatorView::fileNodeForModelNode(const ModelNode &node) const
|
||||
{
|
||||
QString filename = node.metaInfo().componentFileName();
|
||||
Utils::FilePath filePath = Utils::FilePath::fromString(filename);
|
||||
ProjectExplorer::Project *currentProject = ProjectExplorer::SessionManager::projectForFile(filePath);
|
||||
return currentProject->nodeForFilePath(filePath)->asFileNode();
|
||||
}
|
||||
|
||||
const ProjectExplorer::FileNode *NavigatorView::fileNodeForIndex(const QModelIndex &index) const
|
||||
{
|
||||
if (index.isValid() && currentModel()->data(index, Qt::UserRole).isValid()) {
|
||||
ModelNode node = modelNodeForIndex(index);
|
||||
if (node.metaInfo().isFileComponent()) {
|
||||
return fileNodeForModelNode(node);
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void NavigatorView::propagateInstanceErrorToExplorer(const ModelNode &modelNode) {
|
||||
QModelIndex index = indexForModelNode(modelNode);;
|
||||
|
||||
do {
|
||||
const ProjectExplorer::FileNode *fnode = fileNodeForIndex(index);
|
||||
if (fnode) {
|
||||
fnode->setHasError(true);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
index = index.parent();
|
||||
}
|
||||
} while (index.isValid());
|
||||
}
|
||||
|
||||
void NavigatorView::leftButtonClicked()
|
||||
{
|
||||
if (selectedModelNodes().count() > 1)
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "navigatormodelinterface.h"
|
||||
|
||||
#include <abstractview.h>
|
||||
#include <projectexplorer/projectnodes.h>
|
||||
|
||||
#include <QPointer>
|
||||
#include <QHash>
|
||||
@@ -108,6 +109,7 @@ private:
|
||||
void changeToComponent(const QModelIndex &index);
|
||||
QModelIndex indexForModelNode(const ModelNode &modelNode) const;
|
||||
QAbstractItemModel *currentModel() const;
|
||||
void propagateInstanceErrorToExplorer(const ModelNode &modelNode);
|
||||
|
||||
void leftButtonClicked();
|
||||
void rightButtonClicked();
|
||||
@@ -123,6 +125,10 @@ protected: //functions
|
||||
void expandAncestors(const QModelIndex &index);
|
||||
void reparentAndCatch(NodeAbstractProperty property, const ModelNode &modelNode);
|
||||
void setupWidget();
|
||||
void addNodeAndSubModelNodesToList(const ModelNode &node, QList<ModelNode> &nodes);
|
||||
void clearExplorerWarnings();
|
||||
const ProjectExplorer::FileNode *fileNodeForModelNode(const ModelNode &node) const;
|
||||
const ProjectExplorer::FileNode *fileNodeForIndex(const QModelIndex &index) const;
|
||||
|
||||
private:
|
||||
bool m_blockSelectionChangedSignal;
|
||||
|
||||
Reference in New Issue
Block a user