Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

virtual QVariant PatternistApplicationParser::convertToValue ( const QApplicationArgument argument,
const QString input 
) const [inline, protected, virtual]

This function is only of interest when subclassing.

parse() calls this function each time a value, that is input, on the command line needs to be validated and subsequently converted to the type of argument. A descriptive error message will be outputted if input cannot be converted to the required type.

The default implementation uses QVariant::canConvert() and QVariant::convert() for doing conversions.

QApplicationArgumentParser can be subclassed and this function subsequently overridden, to handle custom types.

If input isn't valid input for argument, this function returns a default constructed QVariant.

See also:
typeToName(), parse()

Reimplemented from QApplicationArgumentParser.

Definition at line 125 of file main.cpp.

References QIODevice::errorString(), QFile::fileName(), QXmlName::fromClarkName(), QXmlName::isNCName(), QXmlName::isNull(), QVariant::isNull(), QString::left(), QApplicationArgumentParser::message(), QString::mid(), QApplicationArgument::name(), QFile::open(), and QApplicationArgumentParser::value().

    {
        if(arg.name() == QLatin1String("param"))
        {
            const int assign = input.indexOf(QLatin1Char('='));

            if(assign == -1)
            {
                message(QXmlPatternistCLI::tr("Each binding must contain an equal sign."));
                return QVariant();
            }

            const QString name(input.left(assign));
            const QString value(input.mid(assign + 1));

            if(!QXmlName::isNCName(name))
            {
                message(QXmlPatternistCLI::tr("The variable name must be a valid NCName, which %1 isn't.").arg(name));
                return QVariant();
            }

            /* The value.isNull() check ensures we can bind variables whose value is an empty string. */
            return qVariantFromValue(Parameter(name, value.isNull() ? QString(QLatin1String("")) : value ));
        }
        else if(arg.name() == QLatin1String("output"))
        {
            QFile *const f = new QFile(input);

            if(f->open(QIODevice::WriteOnly))
                return qVariantFromValue(static_cast<QIODevice *>(f));
            else
            {
                message(QXmlPatternistCLI::tr("Failed to open file %1 for writing: %2").arg(f->fileName(), f->errorString()));
                return QVariant();
            }
        }
        else if(arg.name() == QLatin1String("initial-template"))
        {
            const QXmlName name(QXmlName::fromClarkName(input, m_namePool));
            if(name.isNull())
            {
                message(QXmlPatternistCLI::tr("%1 is an invalid Clark Name").arg(input));
                return QVariant();
            }
            else
                return qVariantFromValue(name);
        }
        else
            return QApplicationArgumentParser::convertToValue(arg, input);
    }

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index