コード例 #1
0
ファイル: qssparser.cpp プロジェクト: sandsmark/quassel-proxy
void QssParser::processStyleSheet(QString &ss)
{
    if (ss.isEmpty())
        return;

    // Remove C-style comments /* */ or //
    QRegExp commentRx("(//.*(\\n|$)|/\\*.*\\*/)");
    commentRx.setMinimal(true);
    ss.remove(commentRx);

    // Palette definitions first, so we can apply roles later on
    QRegExp paletterx("(Palette[^{]*)\\{([^}]+)\\}");
    int pos = 0;
    while ((pos = paletterx.indexIn(ss, pos)) >= 0) {
        parsePaletteBlock(paletterx.cap(1).trimmed(), paletterx.cap(2).trimmed());
        ss.remove(pos, paletterx.matchedLength());
    }

    // Now we can parse the rest of our custom blocks
    QRegExp blockrx("((?:ChatLine|ChatListItem|NickListItem)[^{]*)\\{([^}]+)\\}");
    pos = 0;
    while ((pos = blockrx.indexIn(ss, pos)) >= 0) {
        //qDebug() << blockrx.cap(1) << blockrx.cap(2);
        QString declaration = blockrx.cap(1).trimmed();
        QString contents = blockrx.cap(2).trimmed();

        if (declaration.startsWith("ChatLine"))
            parseChatLineBlock(declaration, contents);
        else if (declaration.startsWith("ChatListItem") || declaration.startsWith("NickListItem"))
            parseListItemBlock(declaration, contents);
        //else
        // TODO: add moar here

        ss.remove(pos, blockrx.matchedLength());
    }
}
コード例 #2
0
bool IqAmeSymbol::loadFromString(const QString &string)
{
    QRegExp textRx("^\\s*(SYMP|S)\\s*:\\s*(\\*([^\\*]*)\\*){0,1}");
    textRx.setCaseSensitivity(Qt::CaseInsensitive);
    if (textRx.indexIn(string) == -1)
        return false;

    setName(textRx.cap(3));

    //Получим оставшуюся строку
    QString clearString = string.mid(textRx.matchedLength());

    //Выделим комментарий
    QRegExp commentRx("\\*([^\\*]*)\\*\\W*$");
    if (commentRx.indexIn(clearString) != -1)
        setComment(commentRx.cap(1));

    //Удалим все комментарии из строки
    QRegExp extraCommentsRx("\\*[^\\*]*\\*");
    clearString.remove(extraCommentsRx);

    //Выделим тип символа
    QRegExp symbolType("^\"(\\d+)\"(.*)");
    if (symbolType.indexIn(clearString.trimmed()) == -1)
        return false;
    switch (symbolType.cap(1).toInt()) {
    case 1:
        setType(PointRequedReport);
        break;
    case 2:
        setType(PointRequestReport);
        break;
    case 3:
        setType(Ndb);
        break;
    case 4:
        setType(ArtificalObstaclesWithouLight);
        break;
    case 6:
        setType(VorDme);
        break;
    case 7:
        setType(CivilAirport);
        break;
    case 8:
        setType(MixedAirport);
        break;
    case 9:
        setType(MilitaryAirport);
        break;
    default:
        qWarning() << tr("Symbol type \"%0\" not know. Symbol element skipped...")
                      .arg(symbolType.cap(1));
        return false;
    }
    clearString = symbolType.cap(2).trimmed();

    QString symbolString = clearString.trimmed();

    //Выделим атрибуты
    QRegExp attributeRx("(<\\s*[^>]*\\s*>)(.*)");
    attributeRx.setCaseSensitivity(Qt::CaseInsensitive);

    if (attributeRx.indexIn(clearString) != -1) {
        //Нашли атрибуты, создадим их
        if (!attributes()) {
            setAttributes(new IqAmeShapesAttributes(this));
        }
        attributes()->loadFromString(attributeRx.cap(1));
        symbolString = attributeRx.cap(2).trimmed();
    }

    QString pName = symbolString;

    if (!pName.isEmpty()) {
        IqAmeGeoPoint *p = IqAmeApplication::aeroMapModel()->pointsModel()->point(pName.trimmed(), Qt::CaseInsensitive);
        if (!p) {
            //Если не нашли точку, то попробуем ее создать
            IqAmeGeoPoint newPoint;
            if (newPoint.fromCoordinate(pName)) {
                int newPointRow = IqAmeApplication::aeroMapModel()->pointsModel()->rowCount();
                IqAmeApplication::aeroMapModel()->pointsModel()->insertRow(newPointRow);
                p = IqAmeApplication::aeroMapModel()->pointsModel()->at(newPointRow);
                p->setName(newPoint.name());
                p->setLatitude(newPoint.latitude());
                p->setLongitude(newPoint.longitude());
            } else {
                qWarning() << tr("Point \"%0\" not found and can not create. Symbol element skipped...").arg(pName);
                return false;
            }
        }

        setPoint(p);
        return true;
    }

    return false;
}