Commit be161190 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Code scanning (QString) issues in QmlDesigner.


Reviewed-by: default avatarThomas Hartmann <thartman@trolltech.com>
parent 0ae3f86c
......@@ -165,7 +165,7 @@ void ItemCreatorTool::createAtItem(const QRectF &rect)
pos = parentItem->mapFromScene(pos);
}
QStringList list = m_itemString.split("^");
QStringList list = m_itemString.split(QLatin1Char('^'));
if (list.count() != 2)
return;
if (list.first() == "item") {
......
......@@ -430,7 +430,7 @@ public:
_styleSheetFile.setScheme("file"); //### todo
QString fileName;
if (!QFileInfo(_styleSheetFile.toLocalFile()).exists())
fileName = (":" + _styleSheetFile.toLocalFile().split(":").last()); //try if it is a resource
fileName = (QLatin1Char(':') + _styleSheetFile.toLocalFile().split(QLatin1Char(':')).last()); //try if it is a resource
else
fileName = (_styleSheetFile.toLocalFile());
QFile file(fileName);
......@@ -550,7 +550,7 @@ private:
QString path;
if (_url.scheme() == QLatin1String("qrc")) {
path = ":" + _url.path();
path = QLatin1Char(':') + _url.path();
} else {
path = _url.toLocalFile();
}
......@@ -623,7 +623,7 @@ private:
QString path;
if (_url.scheme() == QLatin1String("qrc")) {
path = ":" + _url.path();
path = QLatin1Char(':') + _url.path();
} else {
path = _url.toLocalFile();
}
......
......@@ -77,7 +77,7 @@ PropertyEditor::NodeType::~NodeType()
void createPropertyEditorValue(const QmlObjectNode &fxObjectNode, const QString &name, const QVariant &value, QmlPropertyMap *propertyMap, PropertyEditor *propertyEditor)
{
QString propertyName(name);
propertyName.replace(".", "_");
propertyName.replace(QLatin1Char('.'), QLatin1Char('_'));
PropertyEditorValue *valueObject = qobject_cast<PropertyEditorValue*>(QmlMetaType::toQObject(propertyMap->value(propertyName)));
if (!valueObject) {
valueObject = new PropertyEditorValue(propertyMap);
......@@ -206,7 +206,7 @@ void PropertyEditor::changeValue(const QString &name)
}
QString propertyName(name);
propertyName.replace("_", ".");
propertyName.replace(QLatin1Char('_'), QLatin1Char('.'));
PropertyEditorValue *value = qobject_cast<PropertyEditorValue*>(QmlMetaType::toQObject(m_currentType->m_backendValuesPropertyMap.value(name)));
......@@ -528,7 +528,7 @@ QUrl PropertyEditor::fileToUrl(const QString &filePath) const {
if (filePath.isEmpty())
return fileUrl;
if (filePath.startsWith(":")) {
if (filePath.startsWith(QLatin1Char(':'))) {
fileUrl.setScheme("qrc");
QString path = filePath;
path.remove(0, 1); // remove trailing ':'
......
......@@ -239,7 +239,7 @@ void PropertyEditorNodeWrapper::add(const QString &type)
QString propertyType = type;
if ((m_editorValue && m_editorValue->modelNode().isValid())) {
if (propertyType == "")
if (propertyType.isEmpty())
propertyType = m_editorValue->modelNode().metaInfo().property(m_editorValue->name()).type();
while (propertyType.contains('*')) //strip star
propertyType.chop(1);
......
......@@ -57,7 +57,7 @@ public:
QString propertyName() const;
public slots:
void add(const QString &type = "");
void add(const QString &type = QString());
void remove();
void changeValue(const QString &name);
void update();
......
......@@ -71,7 +71,7 @@ QVariant StatesEditorModel::data(const QModelIndex &index, int role) const
QVariant result;
switch (role) {
case StateNameRole: {
if ((index.row()==0) && (m_stateNames.at(index.row())==""))
if ((index.row()==0) && m_stateNames.at(index.row()).isEmpty())
result = QString("base state");
else
result = m_stateNames.at(index.row());
......
......@@ -105,7 +105,7 @@ void AddArrayMemberVisitor::insertInto(QmlJS::AST::UiArrayBinding *arrayBinding)
void AddArrayMemberVisitor::convertAndAdd(QmlJS::AST::UiObjectBinding *objectBinding)
{
const int indentDepth = calculateIndentDepth(objectBinding->firstSourceLocation());
const QString arrayPrefix = QLatin1String("[\n") + addIndentation(QLatin1String(""), indentDepth);
const QString arrayPrefix = QLatin1String("[\n") + addIndentation(QString(), indentDepth);
replace(objectBinding->qualifiedTypeNameId->identifierToken.offset, 0, arrayPrefix);
const int insertionPoint = objectBinding->lastSourceLocation().end();
replace(insertionPoint, 0,
......
......@@ -489,7 +489,7 @@ QVariant ObjectNodeInstance::property(const QString &name) const
return QVariant();
if (url.scheme() == "file") {
int basePathLength = nodeInstanceView()->model()->fileUrl().toLocalFile().lastIndexOf("/");
int basePathLength = nodeInstanceView()->model()->fileUrl().toLocalFile().lastIndexOf('/');
return QUrl(url.toLocalFile().mid(basePathLength + 1));
}
}
......@@ -612,11 +612,11 @@ QStringList propertyNameForWritableProperties(QObject *object, const QString &ba
if (metaProperty.isReadable() && !metaProperty.isWritable()) {
QObject *childObject = QmlMetaType::toQObject(metaProperty.read(object));
if (childObject)
propertyNameList.append(propertyNameForWritableProperties(childObject, baseName + QString::fromUtf8(metaProperty.name()) + "."));
propertyNameList.append(propertyNameForWritableProperties(childObject, baseName + QString::fromUtf8(metaProperty.name()) + '.'));
} else if (QmlValueTypeFactory::valueType(metaProperty.userType())) {
QmlValueType *valueType = QmlValueTypeFactory::valueType(metaProperty.userType());
valueType->setValue(metaProperty.read(object));
propertyNameList.append(propertyNameForWritableProperties(valueType, baseName + QString::fromUtf8(metaProperty.name()) + "."));
propertyNameList.append(propertyNameForWritableProperties(valueType, baseName + QString::fromUtf8(metaProperty.name()) + '.'));
} else if (metaProperty.isReadable() && metaProperty.isWritable()) {
propertyNameList.append(baseName + QString::fromUtf8(metaProperty.name()));
}
......
......@@ -278,7 +278,7 @@ QHash<QString,PropertyMetaInfo> NodeMetaInfo::dotProperties() const
while (iter.hasNext()) {
iter.next();
if (!propertiesInfo.contains(iter.key()) && iter.key() != "objectName")
propertiesInfo.insert(propertyName + "." + iter.key(), iter.value());
propertiesInfo.insert(propertyName + '.' + iter.key(), iter.value());
}
}
}
......
......@@ -223,7 +223,7 @@ void SubComponentManagerPrivate::parseDirectory(const QString &dirPath)
while (newIter != newList.constEnd()) {
parseFile(newIter->filePath());
if (debug)
qDebug() << "m_watcher.addPath(" << newIter->filePath() << ")";
qDebug() << "m_watcher.addPath(" << newIter->filePath() << ')';
m_watcher.addPath(newIter->filePath());
++newIter;
}
......
......@@ -415,12 +415,12 @@ uint qHash(const AbstractProperty &property)
QDebug operator<<(QDebug debug, const AbstractProperty &property)
{
return debug.nospace() << "AbstractProperty(" << (property.isValid() ? property.name() : QLatin1String("invalid")) << ")";
return debug.nospace() << "AbstractProperty(" << (property.isValid() ? property.name() : QLatin1String("invalid")) << ')';
}
QTextStream& operator<<(QTextStream &stream, const AbstractProperty &property)
{
stream << "AbstractProperty(" << property.name() << ")";
stream << "AbstractProperty(" << property.name() << ')';
return stream;
}
......
......@@ -102,7 +102,7 @@ BindingProperty& BindingProperty::operator= (const QString &expression)
static ModelNode resolveBinding(const QString &binding, ModelNode currentNode, AbstractView* view)
{
int i = 0;
QString element = binding.split(".").at(0);
QString element = binding.split(QLatin1Char('.')).at(0);
while (!element.isEmpty())
{
if (element == "parent") {
......@@ -119,10 +119,10 @@ static ModelNode resolveBinding(const QString &binding, ModelNode currentNode, A
currentNode = view->modelNodeForId(element); //id
}
i++;
if (i < binding.split(".").count())
element = binding.split(".").at(i);
if (i < binding.split(QLatin1Char('.')).count())
element = binding.split(QLatin1Char('.')).at(i);
else
element = "";
element.clear();
}
return currentNode;
......@@ -144,8 +144,8 @@ AbstractProperty BindingProperty::resolveToProperty() const
QString binding = expression();
ModelNode node = parentModelNode();
QString element;
if (binding.contains(".")) {
element = binding.split(".").last();
if (binding.contains(QLatin1Char('.'))) {
element = binding.split(QLatin1Char('.')).last();
QString nodeBinding = binding;
nodeBinding.chop(element.length());
node = resolveBinding(nodeBinding, parentModelNode(), view());
......
......@@ -72,7 +72,7 @@ static void syncBindingProperties(ModelNode &outputNode, const ModelNode &inputN
static void syncId(ModelNode &outputNode, const ModelNode &inputNode, const QHash<QString, QString> &idRenamingHash)
{
if (!inputNode.id().isNull() && inputNode.id() != "") {
if (!inputNode.id().isNull() && !inputNode.id().isEmpty()) {
outputNode.setId(idRenamingHash.value(inputNode.id()));
}
}
......@@ -82,7 +82,7 @@ static void setupIdRenamingHash(const ModelNode &modelNode, QHash<QString, QStri
QList<ModelNode> allNodes(modelNode.allSubModelNodes());
allNodes.append(modelNode);
foreach (const ModelNode &node, allNodes) {
if (!node.id().isNull() && node.id() != "") {
if (!node.id().isNull() && !node.id().isEmpty()) {
QString newId = node.id();
int i = 1;
while (view->hasId(newId) || idRenamingHash.contains(newId)) {
......@@ -96,7 +96,7 @@ static void setupIdRenamingHash(const ModelNode &modelNode, QHash<QString, QStri
static void syncNodeProperties(ModelNode &outputNode, const ModelNode &inputNode, const QHash<QString, QString> &idRenamingHash, AbstractView *view)
{
foreach (NodeProperty nodeProperty, inputNode.nodeProperties()) {
foreach (const NodeProperty &nodeProperty, inputNode.nodeProperties()) {
ModelNode newNode = createNodeFromNode(nodeProperty.modelNode(), idRenamingHash, view);
outputNode.nodeProperty(nodeProperty.name()).reparentHere(newNode);
}
......@@ -104,7 +104,7 @@ static void syncNodeProperties(ModelNode &outputNode, const ModelNode &inputNode
static void syncNodeListProperties(ModelNode &outputNode, const ModelNode &inputNode, const QHash<QString, QString> &idRenamingHash, AbstractView *view)
{
foreach (NodeListProperty nodeListProperty, inputNode.nodeListProperties()) {
foreach (const NodeListProperty &nodeListProperty, inputNode.nodeListProperties()) {
foreach (const ModelNode &node, nodeListProperty.toModelNodeList()) {
ModelNode newNode = createNodeFromNode(node, idRenamingHash, view);
outputNode.nodeListProperty(nodeListProperty.name()).reparentHere(newNode);
......
......@@ -249,7 +249,7 @@ QString ModelNode::simplifiedTypeName() const
throw InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__);
}
return type().split("/").last();
return type().split(QLatin1Char('/')).last();
}
/*! \brief Returns whether the node is valid
......@@ -842,7 +842,7 @@ QDebug operator<<(QDebug debug, const ModelNode &modelNode)
debug.nospace() << "ModelNode("
<< modelNode.internalNode().data() << ", "
<< modelNode.type() << ", "
<< modelNode.id() <<")";
<< modelNode.id() << ')';
} else {
debug.nospace() << "ModelNode(invalid)";
}
......@@ -855,7 +855,7 @@ QTextStream& operator<<(QTextStream &stream, const ModelNode &modelNode)
if (modelNode.isValid()) {
stream << "ModelNode("
<< "type: " << modelNode.type() << ", "
<< "id: " << modelNode.id() <<")";
<< "id: " << modelNode.id() << ')';
} else {
stream << "ModelNode(invalid)";
}
......
......@@ -145,7 +145,7 @@ void QmlAnchors::setAnchor(AnchorLine::Type sourceAnchorLine,
QString targetExpression = targetQmlItemNode.modelNode().validId();
if (targetQmlItemNode.modelNode() == qmlItemNode().modelNode().parentProperty().parentModelNode())
targetExpression = "parent";
targetExpression = targetExpression + "." + lineTypeToString(targetAnchorLine);
targetExpression = targetExpression + QLatin1Char('.') + lineTypeToString(targetAnchorLine);
qmlItemNode().modelNode().bindingProperty(propertyName).setExpression(targetExpression);
}
}
......
......@@ -115,7 +115,7 @@ QmlItemNode QmlModelView::createQmlItemNodeFromImage(const QString &imageName, c
QString id;
int i = 1;
QString name("image");
name.replace(" ", "");
name.remove(QLatin1Char(' '));
do {
id = name + QString::number(i);
i++;
......@@ -159,7 +159,7 @@ QmlItemNode QmlModelView::createQmlItemNode(const ItemLibraryInfo &itemLibraryRe
QString id;
int i = 1;
QString name(itemLibraryRepresentation.name());
name.replace(" ", "");
name.remove(QLatin1Char(' '));
do {
id = name + QString::number(i);
i++;
......
......@@ -72,7 +72,7 @@ QString QmlTextGenerator::toQml(const AbstractProperty &property, int indentDept
result += arrayContentIndentation;
result += toQml(nodes.at(i), arrayContentDepth);
}
return result + QLatin1String("]");
return result + QLatin1Char(']');
}
} else if (property.isVariantProperty()) {
const VariantProperty variantProperty = property.toVariantProperty();
......
......@@ -89,7 +89,7 @@ bool AddPropertyRewriteAction::execute(QmlRefactoring &refactoring, ModelNodePos
if (!result) {
qDebug() << "*** AddPropertyRewriteAction::execute failed in addToObjectMemberList("
<< nodeLocation << ","
<< nodeLocation << ','
<< m_valueText << ") **"
<< info();
}
......@@ -98,8 +98,8 @@ bool AddPropertyRewriteAction::execute(QmlRefactoring &refactoring, ModelNodePos
if (!result) {
qDebug() << "*** AddPropertyRewriteAction::execute failed in addProperty("
<< nodeLocation << ","
<< m_property.name() << ","
<< nodeLocation << ','
<< m_property.name() << ','
<< m_valueText << ", ScriptBinding) **"
<< info();
}
......@@ -124,8 +124,8 @@ bool ChangeIdRewriteAction::execute(QmlDesigner::QmlRefactoring &refactoring, Mo
if (!result) {
qDebug() << "*** ChangeIdRewriteAction::execute failed in addProperty("
<< nodeLocation << ","
<< idPropertyName << ","
<< nodeLocation << ','
<< idPropertyName << ','
<< m_newId << ", ScriptBinding) **"
<< info();
}
......@@ -134,7 +134,7 @@ bool ChangeIdRewriteAction::execute(QmlDesigner::QmlRefactoring &refactoring, Mo
if (!result) {
qDebug() << "*** ChangeIdRewriteAction::execute failed in removeProperty("
<< nodeLocation << ","
<< nodeLocation << ','
<< idPropertyName << ") **"
<< info();
}
......@@ -143,8 +143,8 @@ bool ChangeIdRewriteAction::execute(QmlDesigner::QmlRefactoring &refactoring, Mo
if (!result) {
qDebug() << "*** ChangeIdRewriteAction::execute failed in changeProperty("
<< nodeLocation << ","
<< idPropertyName << ","
<< nodeLocation << ','
<< idPropertyName << ','
<< m_newId << ", ScriptBinding) **"
<< info();
}
......@@ -168,7 +168,7 @@ bool ChangePropertyRewriteAction::execute(QmlDesigner::QmlRefactoring &refactori
if (!result) {
qDebug() << "*** ChangePropertyRewriteAction::execute failed in addToObjectMemberList("
<< nodeLocation << ","
<< nodeLocation << ','
<< m_valueText << ") **"
<< info();
}
......@@ -177,8 +177,8 @@ bool ChangePropertyRewriteAction::execute(QmlDesigner::QmlRefactoring &refactori
if (!result) {
qDebug() << "*** ChangePropertyRewriteAction::execute failed in addToArrayMemberList("
<< nodeLocation << ","
<< m_property.name() << ","
<< nodeLocation << ','
<< m_property.name() << ','
<< m_valueText << ") **"
<< info();
}
......@@ -187,9 +187,9 @@ bool ChangePropertyRewriteAction::execute(QmlDesigner::QmlRefactoring &refactori
if (!result) {
qDebug() << "*** ChangePropertyRewriteAction::execute failed in changeProperty("
<< nodeLocation << ","
<< m_property.name() << ","
<< m_valueText << ","
<< nodeLocation << ','
<< m_property.name() << ','
<< m_valueText << ','
<< qPrintable(toString(m_propertyType)) << ") **"
<< info();
}
......@@ -221,7 +221,7 @@ bool ChangeTypeRewriteAction::execute(QmlDesigner::QmlRefactoring &refactoring,
result = refactoring.changeObjectType(nodeLocation, newNodeType);
if (!result) {
qDebug() << "*** ChangeTypeRewriteAction::execute failed in changeObjectType("
<< nodeLocation << ","
<< nodeLocation << ','
<< newNodeType << ") **"
<< info();
}
......@@ -258,7 +258,7 @@ bool RemovePropertyRewriteAction::execute(QmlDesigner::QmlRefactoring &refactori
bool result = refactoring.removeProperty(nodeLocation, m_property.name());
if (!result) {
qDebug() << "*** RemovePropertyRewriteAction::execute failed in removeProperty("
<< nodeLocation << ","
<< nodeLocation << ','
<< m_property.name() << ") **"
<< info();
}
......@@ -285,9 +285,9 @@ bool ReparentNodeRewriteAction::execute(QmlDesigner::QmlRefactoring &refactoring
result = refactoring.moveObject(nodeLocation, targetPropertyName, isArrayBinding, targetParentObjectLocation);
if (!result) {
qDebug() << "*** ReparentNodeRewriteAction::execute failed in moveObject("
<< nodeLocation << ","
<< targetPropertyName << ","
<< isArrayBinding << ","
<< nodeLocation << ','
<< targetPropertyName << ','
<< isArrayBinding << ','
<< targetParentObjectLocation << ") **"
<< info();
}
......@@ -316,7 +316,7 @@ bool MoveNodeRewriteAction::execute(QmlRefactoring &refactoring,
result = refactoring.moveObjectBeforeObject(movingNodeLocation, newTrailingNodeLocation);
if (!result) {
qDebug() << "*** MoveNodeRewriteAction::execute failed in moveObjectBeforeObject("
<< movingNodeLocation << ","
<< movingNodeLocation << ','
<< newTrailingNodeLocation << ") **"
<< info();
}
......
......@@ -590,7 +590,7 @@ void TextToModelMerger::setupComponent(const ModelNode &node)
if (componentText.isEmpty())
return;
QString result = "";
QString result;
if (componentText.contains("Component")) { //explicit component
FirstDefinitionFinder firstDefinitionFinder(componentText);
int offset = firstDefinitionFinder(0);
......
......@@ -133,11 +133,11 @@ VariantProperty& VariantProperty::operator= (const QPair<QString, QVariant> &typ
QDebug operator<<(QDebug debug, const VariantProperty &VariantProperty)
{
return debug.nospace() << "VariantProperty(" << VariantProperty.name() << ")";
return debug.nospace() << "VariantProperty(" << VariantProperty.name() << ')';
}
QTextStream& operator<<(QTextStream &stream, const VariantProperty &property)
{
stream << "VariantProperty(" << property.name() << ")";
stream << "VariantProperty(" << property.name() << ')';
return stream;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment