forked from qt-creator/qt-creator
QmlDesigner: Change signature of our exceptions to use QByteArray instead of QString
This allows to use macros like __FUNCTION__ for the exceptions if QT_NO_CAST_FROM_ASCII is defined. Change-Id: Ib629482bb60502cb311cb2657f1a73c730daf6aa Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
committed by
Thomas Hartmann
parent
2dc48cb4ae
commit
b3b6d3fc71
@@ -100,11 +100,11 @@ bool Exception::warnAboutException()
|
||||
the __FILE__ macro.
|
||||
*/
|
||||
Exception::Exception(int line,
|
||||
const QString &function,
|
||||
const QString &file)
|
||||
const QByteArray &_function,
|
||||
const QByteArray &_file)
|
||||
: m_line(line),
|
||||
m_function(function),
|
||||
m_file(file)
|
||||
m_function(QString::fromLatin1(_function)),
|
||||
m_file(QString::fromLatin1(_file))
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
void * array[50];
|
||||
@@ -120,7 +120,7 @@ Exception::Exception(int line,
|
||||
#endif
|
||||
|
||||
if (s_shouldAssert)
|
||||
Q_ASSERT_X(false, function.toUtf8(), QString("%1:%2 - %3").arg(file).arg(line).arg(function).toUtf8());
|
||||
Q_ASSERT_X(false, _function, QString(QStringLiteral("%1:%2 - %3")).arg(m_file).arg(m_line).arg(m_function).toLatin1());
|
||||
}
|
||||
|
||||
Exception::~Exception()
|
||||
|
@@ -46,10 +46,10 @@ namespace QmlDesigner {
|
||||
the __FILE__ macro.
|
||||
*/
|
||||
InvalidArgumentException::InvalidArgumentException(int line,
|
||||
const QString &function,
|
||||
const QString &file,
|
||||
const QString &argument)
|
||||
: Exception(line, function, file), m_argument(argument)
|
||||
const QByteArray &function,
|
||||
const QByteArray &file,
|
||||
const QByteArray &argument)
|
||||
: Exception(line, function, file), m_argument(QString::fromLatin1(argument))
|
||||
{
|
||||
createWarning();
|
||||
}
|
||||
|
@@ -35,12 +35,12 @@
|
||||
namespace QmlDesigner {
|
||||
|
||||
InvalidIdException::InvalidIdException(int line,
|
||||
const QString &function,
|
||||
const QString &file,
|
||||
const QString &id,
|
||||
const QByteArray &function,
|
||||
const QByteArray &file,
|
||||
const QByteArray &id,
|
||||
Reason reason) :
|
||||
InvalidArgumentException(line, function, file, "id"),
|
||||
m_id(id)
|
||||
m_id(QString::fromLatin1(id))
|
||||
{
|
||||
if (reason == InvalidCharacters)
|
||||
m_description = QCoreApplication::translate("InvalidIdException", "Only alphanumeric characters and underscore allowed.\nIds must begin with a lowercase letter.");
|
||||
@@ -49,13 +49,13 @@ InvalidIdException::InvalidIdException(int line,
|
||||
}
|
||||
|
||||
InvalidIdException::InvalidIdException(int line,
|
||||
const QString &function,
|
||||
const QString &file,
|
||||
const QString &id,
|
||||
const QString &description) :
|
||||
const QByteArray &function,
|
||||
const QByteArray &file,
|
||||
const QByteArray &id,
|
||||
const QByteArray &description) :
|
||||
InvalidArgumentException(line, function, file, "id"),
|
||||
m_id(id),
|
||||
m_description(description)
|
||||
m_id(QString::fromLatin1(id)),
|
||||
m_description(QString::fromLatin1(description))
|
||||
{
|
||||
createWarning();
|
||||
}
|
||||
|
@@ -45,8 +45,8 @@ namespace QmlDesigner {
|
||||
the __FILE__ macro.
|
||||
*/
|
||||
InvalidMetaInfoException::InvalidMetaInfoException(int line,
|
||||
const QString &function,
|
||||
const QString &file)
|
||||
const QByteArray &function,
|
||||
const QByteArray &file)
|
||||
: Exception(line, function, file)
|
||||
{
|
||||
createWarning();
|
||||
|
@@ -45,8 +45,8 @@ namespace QmlDesigner {
|
||||
the __FILE__ macro.
|
||||
*/
|
||||
InvalidModelNodeException::InvalidModelNodeException(int line,
|
||||
const QString &function,
|
||||
const QString &file)
|
||||
const QByteArray &function,
|
||||
const QByteArray &file)
|
||||
: Exception(line, function, file)
|
||||
{
|
||||
createWarning();
|
||||
|
@@ -46,8 +46,8 @@ namespace QmlDesigner {
|
||||
the __FILE__ macro.
|
||||
*/
|
||||
InvalidModelStateException::InvalidModelStateException(int line,
|
||||
const QString &function,
|
||||
const QString &file)
|
||||
const QByteArray &function,
|
||||
const QByteArray &file)
|
||||
: Exception(line, function, file)
|
||||
{
|
||||
createWarning();
|
||||
|
@@ -44,10 +44,10 @@ namespace QmlDesigner {
|
||||
the __FILE__ macro.
|
||||
*/
|
||||
InvalidPropertyException::InvalidPropertyException(int line,
|
||||
const QString &function,
|
||||
const QString &file,
|
||||
const QString &argument)
|
||||
: Exception(line, function, file), m_argument(argument)
|
||||
const QByteArray &function,
|
||||
const QByteArray &file,
|
||||
const QByteArray &argument)
|
||||
: Exception(line, function, file), m_argument(QString::fromLatin1(argument))
|
||||
{
|
||||
createWarning();
|
||||
}
|
||||
|
@@ -44,11 +44,11 @@ namespace QmlDesigner {
|
||||
the __FILE__ macro.
|
||||
*/
|
||||
InvalidQmlSourceException::InvalidQmlSourceException(int line,
|
||||
const QString &function,
|
||||
const QString &file,
|
||||
const QString &qmlSource)
|
||||
const QByteArray &function,
|
||||
const QByteArray &file,
|
||||
const QByteArray &qmlSource)
|
||||
: Exception(line, function, file),
|
||||
m_qmlSource(qmlSource)
|
||||
m_qmlSource(QString::fromUtf8(qmlSource))
|
||||
{
|
||||
createWarning();
|
||||
}
|
||||
|
@@ -44,8 +44,8 @@ namespace QmlDesigner {
|
||||
the __FILE__ macro.
|
||||
*/
|
||||
InvalidReparentingException::InvalidReparentingException(int line,
|
||||
const QString &function,
|
||||
const QString &file)
|
||||
const QByteArray &function,
|
||||
const QByteArray &file)
|
||||
: Exception(line, function, file)
|
||||
{
|
||||
createWarning();
|
||||
|
@@ -45,8 +45,8 @@ namespace QmlDesigner {
|
||||
the __FILE__ macro.
|
||||
*/
|
||||
InvalidSlideIndexException::InvalidSlideIndexException(int line,
|
||||
const QString &function,
|
||||
const QString &file)
|
||||
const QByteArray &function,
|
||||
const QByteArray &file)
|
||||
: Exception(line, function, file)
|
||||
{
|
||||
createWarning();
|
||||
|
@@ -33,8 +33,8 @@
|
||||
namespace QmlDesigner {
|
||||
|
||||
NotImplementedException::NotImplementedException(int line,
|
||||
const QString &function,
|
||||
const QString &file):
|
||||
const QByteArray &function,
|
||||
const QByteArray &file):
|
||||
Exception(line, function, file)
|
||||
{
|
||||
}
|
||||
|
@@ -45,8 +45,8 @@ namespace QmlDesigner {
|
||||
the __FILE__ macro.
|
||||
*/
|
||||
RemoveBaseStateException::RemoveBaseStateException(int line,
|
||||
const QString &function,
|
||||
const QString &file)
|
||||
const QByteArray &function,
|
||||
const QByteArray &file)
|
||||
: Exception(line, function, file)
|
||||
{
|
||||
createWarning();
|
||||
|
@@ -33,11 +33,11 @@
|
||||
using namespace QmlDesigner;
|
||||
|
||||
RewritingException::RewritingException(int line,
|
||||
const QString &function,
|
||||
const QString &file,
|
||||
const QString &description,
|
||||
const QByteArray &function,
|
||||
const QByteArray &file,
|
||||
const QByteArray &description,
|
||||
const QString &documentTextContent):
|
||||
Exception(line, function, file), m_description(description), m_documentTextContent(documentTextContent)
|
||||
Exception(line, function, file), m_description(QString::fromLatin1(description)), m_documentTextContent(documentTextContent)
|
||||
{
|
||||
createWarning();
|
||||
}
|
||||
|
@@ -42,8 +42,8 @@ class QMLDESIGNERCORE_EXPORT Exception
|
||||
{
|
||||
public:
|
||||
Exception(int line,
|
||||
const QString &function,
|
||||
const QString &file);
|
||||
const QByteArray &function,
|
||||
const QByteArray &file);
|
||||
virtual ~Exception();
|
||||
|
||||
virtual QString type() const = 0;
|
||||
|
@@ -40,9 +40,9 @@ class QMLDESIGNERCORE_EXPORT InvalidArgumentException : public Exception
|
||||
{
|
||||
public:
|
||||
InvalidArgumentException(int line,
|
||||
const QString &function,
|
||||
const QString &file,
|
||||
const QString &argument);
|
||||
const QByteArray &function,
|
||||
const QByteArray &file,
|
||||
const QByteArray &argument);
|
||||
|
||||
QString type() const;
|
||||
QString argument() const;
|
||||
|
@@ -41,16 +41,16 @@ public:
|
||||
enum Reason { InvalidCharacters, DuplicateId };
|
||||
|
||||
InvalidIdException(int line,
|
||||
const QString &function,
|
||||
const QString &file,
|
||||
const QString &id,
|
||||
const QByteArray &function,
|
||||
const QByteArray &file,
|
||||
const QByteArray &id,
|
||||
Reason reason);
|
||||
|
||||
InvalidIdException(int line,
|
||||
const QString &function,
|
||||
const QString &file,
|
||||
const QString &id,
|
||||
const QString &description);
|
||||
const QByteArray &function,
|
||||
const QByteArray &file,
|
||||
const QByteArray &id,
|
||||
const QByteArray &description);
|
||||
|
||||
QString type() const;
|
||||
QString description() const;
|
||||
|
@@ -39,8 +39,8 @@ class QMLDESIGNERCORE_EXPORT InvalidMetaInfoException : public Exception
|
||||
{
|
||||
public:
|
||||
InvalidMetaInfoException(int line,
|
||||
const QString &function,
|
||||
const QString &file);
|
||||
const QByteArray &function,
|
||||
const QByteArray &file);
|
||||
|
||||
QString type() const;
|
||||
|
||||
|
@@ -39,8 +39,8 @@ class QMLDESIGNERCORE_EXPORT InvalidModelNodeException : public Exception
|
||||
{
|
||||
public:
|
||||
InvalidModelNodeException(int line,
|
||||
const QString &function,
|
||||
const QString &file);
|
||||
const QByteArray &function,
|
||||
const QByteArray &file);
|
||||
|
||||
QString type() const;
|
||||
|
||||
|
@@ -39,8 +39,8 @@ class QMLDESIGNERCORE_EXPORT InvalidModelStateException : public Exception
|
||||
{
|
||||
public:
|
||||
InvalidModelStateException(int line,
|
||||
const QString &function,
|
||||
const QString &file);
|
||||
const QByteArray &function,
|
||||
const QByteArray &file);
|
||||
|
||||
|
||||
QString type() const;
|
||||
|
@@ -39,9 +39,9 @@ class QMLDESIGNERCORE_EXPORT InvalidPropertyException : public Exception
|
||||
{
|
||||
public:
|
||||
InvalidPropertyException(int line,
|
||||
const QString &function,
|
||||
const QString &file,
|
||||
const QString &argument);
|
||||
const QByteArray &function,
|
||||
const QByteArray &file,
|
||||
const QByteArray &argument);
|
||||
|
||||
QString type() const;
|
||||
QString argument() const;
|
||||
|
@@ -39,9 +39,9 @@ class QMLDESIGNERCORE_EXPORT InvalidQmlSourceException : public QmlDesigner::Exc
|
||||
{
|
||||
public:
|
||||
InvalidQmlSourceException(int line,
|
||||
const QString &function,
|
||||
const QString &file,
|
||||
const QString &qmlSource = QString());
|
||||
const QByteArray &function,
|
||||
const QByteArray &file,
|
||||
const QByteArray &qmlSource = QByteArray());
|
||||
|
||||
QString type() const;
|
||||
QString description() const;
|
||||
|
@@ -39,8 +39,8 @@ class QMLDESIGNERCORE_EXPORT InvalidReparentingException : public Exception
|
||||
{
|
||||
public:
|
||||
InvalidReparentingException(int line,
|
||||
const QString &function,
|
||||
const QString &file);
|
||||
const QByteArray &function,
|
||||
const QByteArray &file);
|
||||
|
||||
QString type() const;
|
||||
};
|
||||
|
@@ -39,8 +39,8 @@ class QMLDESIGNERCORE_EXPORT InvalidSlideIndexException : public Exception
|
||||
{
|
||||
public:
|
||||
InvalidSlideIndexException(int line,
|
||||
const QString &function,
|
||||
const QString &file);
|
||||
const QByteArray &function,
|
||||
const QByteArray &file);
|
||||
QString type() const;
|
||||
};
|
||||
|
||||
|
@@ -39,8 +39,8 @@ class QMLDESIGNERCORE_EXPORT NotImplementedException : public Exception
|
||||
{
|
||||
public:
|
||||
NotImplementedException(int line,
|
||||
const QString &function,
|
||||
const QString &file);
|
||||
const QByteArray &function,
|
||||
const QByteArray &file);
|
||||
|
||||
QString type() const;
|
||||
|
||||
|
@@ -39,8 +39,8 @@ class QMLDESIGNERCORE_EXPORT RemoveBaseStateException : public Exception
|
||||
{
|
||||
public:
|
||||
RemoveBaseStateException(int line,
|
||||
const QString &function,
|
||||
const QString &file);
|
||||
const QByteArray &function,
|
||||
const QByteArray &file);
|
||||
|
||||
QString type() const;
|
||||
|
||||
|
@@ -39,9 +39,9 @@ class QMLDESIGNERCORE_EXPORT RewritingException: public Exception
|
||||
{
|
||||
public:
|
||||
RewritingException(int line,
|
||||
const QString &function,
|
||||
const QString &file,
|
||||
const QString &description,
|
||||
const QByteArray &function,
|
||||
const QByteArray &file,
|
||||
const QByteArray &description,
|
||||
const QString &documentTextContent);
|
||||
|
||||
virtual QString type() const;
|
||||
|
@@ -201,7 +201,7 @@ InternalNode::Pointer ModelPrivate::createNode(const TypeName &typeName,
|
||||
bool isRootNode)
|
||||
{
|
||||
if (typeName.isEmpty())
|
||||
throw InvalidArgumentException(__LINE__, __FUNCTION__, __FILE__, tr("invalid type"));
|
||||
throw InvalidArgumentException(__LINE__, __FUNCTION__, __FILE__, tr("invalid type").toLatin1());
|
||||
|
||||
qint32 internalId = 0;
|
||||
|
||||
@@ -309,8 +309,10 @@ void ModelPrivate::changeNodeId(const InternalNode::Pointer& internalNodePointer
|
||||
|
||||
try {
|
||||
notifyNodeIdChanged(internalNodePointer, id, oldId);
|
||||
|
||||
} catch (const RewritingException &e) {
|
||||
throw InvalidIdException(__LINE__, __FUNCTION__, __FILE__, id, e.description());
|
||||
throw InvalidIdException(__LINE__, __FUNCTION__, __FILE__, id.toLatin1(), e.description().toLatin1());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,9 +323,9 @@ void ModelPrivate::checkPropertyName(const QString &propertyName)
|
||||
throw InvalidPropertyException(__LINE__, __FUNCTION__, __FILE__, "<empty property name>");
|
||||
}
|
||||
|
||||
if (propertyName == "id") {
|
||||
Q_ASSERT_X(propertyName != "id", Q_FUNC_INFO, "cannot add property id");
|
||||
throw InvalidPropertyException(__LINE__, __FUNCTION__, __FILE__, propertyName);
|
||||
if (propertyName == QLatin1String("id")) {
|
||||
Q_ASSERT_X(propertyName != QLatin1String("id"), Q_FUNC_INFO, "cannot add property id");
|
||||
throw InvalidPropertyException(__LINE__, __FUNCTION__, __FILE__, propertyName.toLatin1());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -821,7 +823,7 @@ void ModelPrivate::resetModelByRewriter(const QString &description)
|
||||
if (rewriterView())
|
||||
rewriterView()->resetToLastCorrectQml();
|
||||
|
||||
throw RewritingException(__LINE__, __FUNCTION__, __FILE__, description, rewriterView()->textModifierContent());
|
||||
throw RewritingException(__LINE__, __FUNCTION__, __FILE__, description.toLatin1(), rewriterView()->textModifierContent());
|
||||
}
|
||||
|
||||
|
||||
|
@@ -193,13 +193,13 @@ void ModelNode::setIdWithoutRefactoring(const QString &id)
|
||||
}
|
||||
|
||||
if (!isValidId(id))
|
||||
throw InvalidIdException(__LINE__, __FUNCTION__, __FILE__, id, InvalidIdException::InvalidCharacters);
|
||||
throw InvalidIdException(__LINE__, __FUNCTION__, __FILE__, id.toLatin1(), InvalidIdException::InvalidCharacters);
|
||||
|
||||
if (id == m_internalNode->id())
|
||||
return;
|
||||
|
||||
if (view()->hasId(id))
|
||||
throw InvalidIdException(__LINE__, __FUNCTION__, __FILE__, id, InvalidIdException::DuplicateId);
|
||||
throw InvalidIdException(__LINE__, __FUNCTION__, __FILE__, id.toLatin1(), InvalidIdException::DuplicateId);
|
||||
|
||||
m_model.data()->d->changeNodeId(internalNode(), id);
|
||||
}
|
||||
|
@@ -537,7 +537,7 @@ void RewriterView::applyChanges()
|
||||
qDebug() << "Content:" << content;
|
||||
if (!errors().isEmpty())
|
||||
qDebug() << "Error:" << errors().first().description();
|
||||
throw RewritingException(__LINE__, __FUNCTION__, __FILE__, m_rewritingErrorMessage, content);
|
||||
throw RewritingException(__LINE__, __FUNCTION__, __FILE__, m_rewritingErrorMessage.toLatin1(), content.toLatin1());
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user