Esempio n. 1
0
QString XmlDomElement::getText<QString>(bool throwIfEmpty, const QString& defaultValue) const throw (Exception)
{
    Q_UNUSED(defaultValue);
    Q_ASSERT(defaultValue == QString()); // defaultValue makes no sense in this method

    if (hasChilds())
    {
        throw FileParseError(__FILE__, __LINE__, getDocFilePath(), -1, -1, mName,
                             tr("A node with child elements cannot have a text."));
    }
    if (mText.isEmpty() && throwIfEmpty)
    {
        throw FileParseError(__FILE__, __LINE__, getDocFilePath(), -1, -1, mName,
                             tr("The node text must not be empty."));
    }
    return mText;
}
Esempio n. 2
0
QString XmlDomElement::getAttribute<QString>(const QString& name, bool throwIfEmpty, const QString& defaultValue) const throw (Exception)
{
    Q_UNUSED(defaultValue);
    Q_ASSERT(defaultValue == QString()); // defaultValue makes no sense in this method

    if (!mAttributes.contains(name))
    {
        throw FileParseError(__FILE__, __LINE__, getDocFilePath(), -1, -1, QString(),
            QString(tr("Attribute \"%1\" not found in node \"%2\".")).arg(name, mName));
    }
    if (mAttributes.value(name).isEmpty() && throwIfEmpty)
    {
        throw FileParseError(__FILE__, __LINE__, getDocFilePath(), -1, -1, QString(),
            QString(tr("Attribute \"%1\" in node \"%2\" must not be empty.")).arg(name, mName));
    }
    return mAttributes.value(name);
}
Esempio n. 3
0
XmlDomElement* XmlDomElement::getFirstChild(bool throwIfNotFound) const throw (Exception)
{
    if (!mChilds.isEmpty())
        return mChilds.first();
    else if (!throwIfNotFound)
        return nullptr;
    else
    {
        throw FileParseError(__FILE__, __LINE__, getDocFilePath(), -1, -1, QString(),
            QString(tr("No child in node \"%1\" found.")).arg(mName));
    }
}
Esempio n. 4
0
Uuid XmlDomElement::getAttribute<Uuid>(const QString& name, bool throwIfEmpty, const Uuid& defaultValue) const throw (Exception)
{
    QString attr = getAttribute<QString>(name, throwIfEmpty);
    Uuid obj(attr);
    if (!obj.isNull())
        return obj;
    else if ((attr.isEmpty()) && (!throwIfEmpty))
        return defaultValue;
    else
    {
        throw FileParseError(__FILE__, __LINE__, getDocFilePath(), -1, -1, attr,
            QString(tr("Invalid UUID attribute \"%1\" in node \"%2\".")).arg(name, mName));
    }
}
Esempio n. 5
0
Version XmlDomElement::getText<Version>(bool throwIfEmpty, const Version& defaultValue) const throw (Exception)
{
    QString text = getText<QString>(throwIfEmpty);
    Version obj(text);
    if (obj.isValid())
        return obj;
    else if ((text.isEmpty()) && (!throwIfEmpty))
        return defaultValue;
    else
    {
        throw FileParseError(__FILE__, __LINE__, getDocFilePath(), -1, -1, text,
                             QString(tr("Invalid version number in node \"%1\".")).arg(mName));
    }
}
Esempio n. 6
0
Uuid XmlDomElement::getText<Uuid>(bool throwIfEmpty, const Uuid& defaultValue) const throw (Exception)
{
    QString text = getText<QString>(throwIfEmpty);
    Uuid obj(text);
    if (!obj.isNull())
        return obj;
    else if ((text.isEmpty()) && (!throwIfEmpty))
        return defaultValue;
    else
    {
        throw FileParseError(__FILE__, __LINE__, getDocFilePath(), -1, -1, text,
                             QString(tr("Invalid UUID in node \"%1\".")).arg(mName));
    }
}
Esempio n. 7
0
QDateTime XmlDomElement::getText<QDateTime>(bool throwIfEmpty, const QDateTime& defaultValue) const throw (Exception)
{
    QString text = getText<QString>(throwIfEmpty);
    QDateTime obj = QDateTime::fromString(text, Qt::ISODate).toLocalTime();
    if (obj.isValid())
        return obj;
    else if ((text.isEmpty()) && (!throwIfEmpty))
        return defaultValue;
    else
    {
        throw FileParseError(__FILE__, __LINE__, getDocFilePath(), -1, -1, text,
                             QString(tr("Invalid date/time in node \"%1\".")).arg(mName));
    }
}
Esempio n. 8
0
int DocInterface::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: FileParseError((*reinterpret_cast< QString(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 1;
    }
    return _id;
}
Esempio n. 9
0
int XmlDomElement::getAttribute<int>(const QString& name, bool throwIfEmpty, const int& defaultValue) const throw (Exception)
{
    QString attr = getAttribute<QString>(name, throwIfEmpty);
    bool ok = false;
    int value = attr.toInt(&ok);
    if (ok)
        return value;
    else if ((attr.isEmpty()) && (!throwIfEmpty))
        return defaultValue;
    else
    {
        throw FileParseError(__FILE__, __LINE__, getDocFilePath(), -1, -1, attr,
            QString(tr("Invalid integer attribute \"%1\" in node \"%2\".")).arg(name, mName));
    }
}
Esempio n. 10
0
bool XmlDomElement::getAttribute<bool>(const QString& name, bool throwIfEmpty, const bool& defaultValue) const throw (Exception)
{
    QString attr = getAttribute<QString>(name, throwIfEmpty);
    if (attr == "true")
        return true;
    else if (attr == "false")
        return false;
    else if ((attr.isEmpty()) && (!throwIfEmpty))
        return defaultValue;
    else
    {
        throw FileParseError(__FILE__, __LINE__, getDocFilePath(), -1, -1, attr,
            QString(tr("Invalid boolean attribute \"%1\" in node \"%2\".")).arg(name, mName));
    }
}
Esempio n. 11
0
bool XmlDomElement::getText<bool>(bool throwIfEmpty, const bool& defaultValue) const throw (Exception)
{
    QString text = getText<QString>(throwIfEmpty);
    if (text == "true")
        return true;
    else if (text == "false")
        return false;
    else if ((text.isEmpty()) && (!throwIfEmpty))
        return defaultValue;
    else
    {
        throw FileParseError(__FILE__, __LINE__, getDocFilePath(), -1, -1, text,
                             QString(tr("Invalid boolean value in node \"%1\".")).arg(mName));
    }
}
Esempio n. 12
0
qreal XmlDomElement::getText<qreal>(bool throwIfEmpty, const qreal& defaultValue) const throw (Exception)
{
    QString text = getText<QString>(throwIfEmpty);
    bool ok = false;
    static_assert(sizeof(qreal) == sizeof(double), "Unsupported size of qreal type!");
    qreal value = text.toDouble(&ok);
    if (ok)
        return value;
    else if ((text.isEmpty()) && (!throwIfEmpty))
        return defaultValue;
    else
    {
        throw FileParseError(__FILE__, __LINE__, getDocFilePath(), -1, -1, text,
                             QString(tr("Invalid number in node \"%1\".")).arg(mName));
    }
}
Esempio n. 13
0
VAlign XmlDomElement::getAttribute<VAlign>(const QString& name, bool throwIfEmpty, const VAlign& defaultValue) const throw (Exception)
{
    QString attr = getAttribute<QString>(name, throwIfEmpty);
    try
    {
        VAlign obj = VAlign::fromString(attr);
        return obj;
    }
    catch (Exception& exc)
    {
        if ((attr.isEmpty()) && (!throwIfEmpty))
            return defaultValue;
        else
        {
            throw FileParseError(__FILE__, __LINE__, getDocFilePath(), -1, -1, attr,
                QString(tr("Invalid vertical align attribute \"%1\" in node \"%2\".")).arg(name, mName));
        }
    }
}
Esempio n. 14
0
Length XmlDomElement::getText<Length>(bool throwIfEmpty, const Length& defaultValue) const throw (Exception)
{
    QString text = getText<QString>(throwIfEmpty);
    try
    {
        Length obj = Length::fromMm(text);
        return obj;
    }
    catch (Exception& exc)
    {
        if ((text.isEmpty()) && (!throwIfEmpty))
            return defaultValue;
        else
        {
            throw FileParseError(__FILE__, __LINE__, getDocFilePath(), -1, -1, text,
                                 QString(tr("Invalid length in node \"%1\".")).arg(mName));
        }
    }
}