Esempio n. 1
0
bool BazaarPlugin::submitEditorAboutToClose(VCSBase::VCSBaseSubmitEditor *submitEditor)
{
    if (!m_changeLog)
        return true;
    Core::IFile *editorFile = submitEditor->file();
    const CommitEditor *commitEditor = qobject_cast<const CommitEditor *>(submitEditor);
    if (!editorFile || !commitEditor)
        return true;

    bool dummyPrompt = m_bazaarSettings.boolValue(BazaarSettings::promptOnSubmitKey);
    const VCSBase::VCSBaseSubmitEditor::PromptSubmitResult response =
            commitEditor->promptSubmit(tr("Close Commit Editor"), tr("Do you want to commit the changes?"),
                                       tr("Message check failed. Do you want to proceed?"),
                                       &dummyPrompt, dummyPrompt);

    switch (response) {
    case VCSBase::VCSBaseSubmitEditor::SubmitCanceled:
        return false;
    case VCSBase::VCSBaseSubmitEditor::SubmitDiscarded:
        deleteCommitLog();
        return true;
    default:
        break;
    }

    QStringList files = commitEditor->checkedFiles();
    if (!files.empty()) {
        //save the commit message
        if (!m_core->fileManager()->saveFile(editorFile))
            return false;

        //rewrite entries of the form 'file => newfile' to 'newfile' because
        //this would mess the commit command
        for (QStringList::iterator iFile = files.begin(); iFile != files.end(); ++iFile) {
            const QStringList parts = iFile->split(" => ", QString::SkipEmptyParts);
            if (!parts.isEmpty())
                *iFile = parts.last();
        }

        const BazaarCommitWidget *commitWidget = commitEditor->commitWidget();
        QStringList extraOptions;
        // Author
        if (!commitWidget->committer().isEmpty())
            extraOptions.append(QLatin1String("--author=") + commitWidget->committer());
        // Fixed bugs
        foreach (const QString &fix, commitWidget->fixedBugs()) {
            if (!fix.isEmpty())
                extraOptions << QLatin1String("--fixes") << fix;
        }
        // Whether local commit or not
        if (commitWidget->isLocalOptionEnabled())
            extraOptions += QLatin1String("--local");
        m_client->commit(m_submitRepository, files, editorFile->fileName(), extraOptions);
    }
    return true;
}
Esempio n. 2
0
bool BazaarPlugin::submitEditorAboutToClose()
{
    CommitEditor *commitEditor = qobject_cast<CommitEditor *>(submitEditor());
    QTC_ASSERT(commitEditor, return true);
    Core::IDocument *editorDocument = commitEditor->document();
    QTC_ASSERT(editorDocument, return true);

    bool dummyPrompt = false;
    const VcsBase::VcsBaseSubmitEditor::PromptSubmitResult response =
            commitEditor->promptSubmit(tr("Close Commit Editor"), tr("Do you want to commit the changes?"),
                                       tr("Message check failed. Do you want to proceed?"),
                                       &dummyPrompt, !m_submitActionTriggered);
    m_submitActionTriggered = false;

    switch (response) {
    case VcsBase::VcsBaseSubmitEditor::SubmitCanceled:
        return false;
    case VcsBase::VcsBaseSubmitEditor::SubmitDiscarded:
        return true;
    default:
        break;
    }

    QStringList files = commitEditor->checkedFiles();
    if (!files.empty()) {
        //save the commit message
        if (!Core::DocumentManager::saveDocument(editorDocument))
            return false;

        //rewrite entries of the form 'file => newfile' to 'newfile' because
        //this would mess the commit command
        for (QStringList::iterator iFile = files.begin(); iFile != files.end(); ++iFile) {
            const QStringList parts = iFile->split(QLatin1String(" => "), QString::SkipEmptyParts);
            if (!parts.isEmpty())
                *iFile = parts.last();
        }

        BazaarCommitWidget *commitWidget = commitEditor->commitWidget();
        QStringList extraOptions;
        // Author
        if (!commitWidget->committer().isEmpty())
            extraOptions.append(QLatin1String("--author=") + commitWidget->committer());
        // Fixed bugs
        foreach (const QString &fix, commitWidget->fixedBugs()) {
            if (!fix.isEmpty())
                extraOptions << QLatin1String("--fixes") << fix;
        }
        // Whether local commit or not
        if (commitWidget->isLocalOptionEnabled())
            extraOptions += QLatin1String("--local");
        m_client->commit(m_submitRepository, files, editorDocument->filePath(), extraOptions);
    }
    return true;
}
Esempio n. 3
0
// Parse a <g> tag while opening a file
void svgParseGroup(const QDomElement &element, NoteEditor *editor, QPen pen)
{
    if (element.tagName() != "g") return;

    // Convert the <g> tag into a QPen
    if (element.hasAttribute("stroke-width"))
        pen.setWidthF(element.attribute("stroke-width").toDouble());
    if (element.hasAttribute("stroke")) {
        // Colors by hex value with '#' prefix
        if (element.attribute("stroke").at(0) == '#') {
            pen.setColor(QColor(element.attribute("stroke")
                                .right(6).toInt(0, 16)));
        }
        // TODO: handle colors by name
    }

    if (element.hasAttribute("stroke-linecap")) {
        QString linecap = element.attribute("stroke-linecap");
        if (linecap == "square") {
            pen.setCapStyle(Qt::SquareCap);
        } else if (linecap == "round") {
            pen.setCapStyle(Qt::RoundCap);
        } else if (linecap == "butt") {
            pen.setCapStyle(Qt::FlatCap);
        }
    }

    QDomElement child = element.firstChildElement();
    while (!child.isNull()) {
        if (child.tagName() == "g") {
            svgParseGroup(child, editor, pen);
        } else if (child.tagName() == "polyline") {
            // Get curve from points, add to editor
            Curve *curve = new Curve(pen);
            QStringList pointStrs = child.attribute("points")
                    .split(' ', QString::SkipEmptyParts);
            QStringList::iterator itr;
            for (itr = pointStrs.begin(); itr != pointStrs.end(); ++itr) {
                QStringList curPointStr =
                        itr->split(',', QString::SkipEmptyParts);
                QPointF point(curPointStr[0].toDouble(),
                              curPointStr[1].toDouble());
                editor->addPointToCurve(point, curve);
            }
            editor->addCurve(curve);
        }
        child = child.nextSiblingElement();
    }
}
Esempio n. 4
0
void ParsetTreeViewer::view(QString parset, const OTDBtree &otdb_tree) {
	if (!parset.isEmpty()) {
		ui.treeWidget->clear();
        parset.remove("LOFAR.");
        parset.remove("ObsSW.");
		QStringList lines(parset.split("\n", QString::SkipEmptyParts));
		lines.sort();

        if (otdb_tree.treeID()) {
            // add meta data from the OTDB tree
            lines += QString("current status in SAS=") + sasStateString(otdb_tree.state()).c_str();
            lines += QString("actual start time=") + otdb_tree.startTime().toString().c_str();
            lines += QString("actual stop time=") + otdb_tree.stopTime().toString().c_str();
            lines += QString("creation date=") + otdb_tree.creationDate().toString().c_str();
            lines += QString("modified date=") + otdb_tree.modificationDate().toString().c_str();
            lines += QString("SAS ID=") + QString::number(otdb_tree.treeID());
            lines += QString("group ID=") + QString::number(otdb_tree.groupID());
            lines += QString("MoM ID=") + QString::number(otdb_tree.momID());
            lines += QString("parent template=") + QString::number(otdb_tree.originalTree());
            lines += QString("campaign=") + otdb_tree.campaign().c_str();
            lines += QString("processType=") + otdb_tree.processType();
            lines += QString("processSubType=") + PROCESS_SUBTYPES[otdb_tree.processSubType()];
            lines += QString("strategy=") + otdb_tree.strategy();
        }

		QStringList key_value_pair, prev_line, current_line, item_pair;
		QTreeWidgetItem *newItem;
        QList<QTreeWidgetItem *> parents, prevParents;
        QString value, tooltip;
		int idx, nrElements;
		for (QStringList::iterator it = lines.begin()+1; it != lines.end(); ++it) {
			key_value_pair = it->split('='); // key_value_pair.first() = full node/key parset name, key_value_pair.last() = value
			if (key_value_pair.size() > 1) {
				value = key_value_pair.last();
			}
			else value = "";
			current_line = key_value_pair.first().split('.');
			prevParents = parents;
			parents.clear();
			idx = 0;
			nrElements = current_line.size();
			while (idx < nrElements) { // while not arrived at last element and not beyond the length of the previous line
				if (idx < prev_line.size()) { // if not beyond the number of elements in the previous line
					if (current_line.at(idx) != prev_line.at(idx)) { // if the item on this position is different from the item on that position of the previous line
						// insert element
						if (idx+1 == nrElements) {
							item_pair << current_line.at(idx) << value;
							tooltip = commaWordWrap(item_pair.first() + " = " + value,100);
						}
						else {
							item_pair << current_line.at(idx);
							tooltip = item_pair.first();
						}

						if (parents.empty()) newItem = new QTreeWidgetItem(ui.treeWidget, item_pair);
						else newItem = new QTreeWidgetItem(parents.last(), item_pair);
						newItem->setToolTip(0,tooltip);
						newItem->setToolTip(1,tooltip);
						parents.push_back(newItem);
						item_pair.clear();
					}
					else parents.push_back(prevParents.at(idx));
				}
				else {
					// insert element
					if (idx+1 == nrElements) {
						item_pair << current_line.at(idx) << value;
						tooltip = commaWordWrap(item_pair.first() + " = " + value,100);
					}
					else {
						item_pair << current_line.at(idx);
						tooltip = item_pair.first();
					}

					if (parents.empty()) newItem = new QTreeWidgetItem(ui.treeWidget, item_pair);
					else newItem = new QTreeWidgetItem(parents.last(), item_pair);
					newItem->setToolTip(0,tooltip);
					newItem->setToolTip(1,tooltip);
					parents.push_back(newItem);
					item_pair.clear();
				}
				++idx;
			}
			prev_line = current_line;
		}
		this->show();
	}
}
Esempio n. 5
0
GeoDataDocument *CycleStreetsRunner::parse( const QByteArray &content ) const
{
    QDomDocument xml;
    if ( !xml.setContent( content ) ) {
        mDebug() << "Cannot parse xml file with routing instructions.";
        return 0;
    }
    GeoDataDocument *result = new GeoDataDocument();
    result->setName( "CycleStreets" );
    GeoDataPlacemark *routePlacemark = new GeoDataPlacemark;
    routePlacemark->setName( "Route" );

    GeoDataLineString *routeWaypoints = new GeoDataLineString;
    QDomNodeList features = xml.elementsByTagName( "gml:featureMember" );

    if ( features.isEmpty() ) {
        return 0;
    }
    QDomElement route = features.at( 0 ).toElement().firstChild().toElement();
    QDomElement lineString = route.elementsByTagName( "gml:LineString" ).at( 0 ).toElement();
    QDomElement coordinates = lineString.toElement().elementsByTagName( "gml:coordinates" ).at( 0 ).toElement();
    QStringList coordinatesList = coordinates.text().split( ' ' );

    QStringList::iterator iter = coordinatesList.begin();
    QStringList::iterator end = coordinatesList.end();

    for( ; iter != end; ++iter) {
        QStringList coordinate =  iter->split(',');
        if ( coordinate.size() == 2 ) {
            double const lon = coordinate.at( 0 ).toDouble();
            double const lat = coordinate.at( 1 ).toDouble();
            GeoDataCoordinates const position( lon, lat, 0.0, GeoDataCoordinates::Degree );
            routeWaypoints->append( position );
        }
    }
    routePlacemark->setGeometry( routeWaypoints );

    QDomElement durationElement = route.elementsByTagName( "cs:time" ).at(0).toElement();
    QTime duration;
    duration = duration.addSecs( durationElement.text().toInt() );
    qreal length = routeWaypoints->length( EARTH_RADIUS );

    const QString name = nameString( "CS", length, duration );
    const GeoDataExtendedData data = routeData( length, duration );
    routePlacemark->setExtendedData( data );
    result->setName( name );
    result->append( routePlacemark );

    int i;
    for ( i = 1; i < features.count() && features.at( i ).firstChildElement().tagName() != "cs:segment"; ++i );
    for ( ; i < features.count(); ++i) {
        QDomElement segment = features.at( i ).toElement();

        QString name = segment.elementsByTagName( "cs:name" ).at( 0 ).toElement().text();
        QString maneuver = segment.elementsByTagName( "cs:turn" ).at( 0 ).toElement().text();
        QStringList points = segment.elementsByTagName( "cs:points" ).at( 0 ).toElement().text().split( ' ' );
        QStringList const elevation = segment.elementsByTagName( "cs:elevations" ).at( 0 ).toElement().text().split( ',' );

        GeoDataPlacemark *instructions = new GeoDataPlacemark;
        QString instructionName;
        if ( !maneuver.isEmpty() ) {
            instructionName = maneuver.left( 1 ).toUpper() + maneuver.mid( 1 );
        } else {
            instructionName = "Straight";
        }
        if ( name != "Short un-named link" && name != "Un-named link" ){
            instructionName.append( " into " + name );
        }
        instructions->setName( instructionName );

        GeoDataExtendedData extendedData;
        GeoDataData turnType;
        turnType.setName( "turnType" );
        turnType.setValue( maneuverType( maneuver ) );
        extendedData.addValue( turnType );

        instructions->setExtendedData( extendedData );
        GeoDataLineString *lineString = new GeoDataLineString;
        QStringList::iterator iter = points.begin();
        QStringList::iterator end = points.end();
        for  ( int j=0; iter != end; ++iter, ++j ) {
            QStringList coordinate = iter->split( ',' );
            if ( coordinate.size() == 2 ) {
                double const lon = coordinate.at( 0 ).toDouble();
                double const lat = coordinate.at( 1 ).toDouble();
                double const alt = j < elevation.size() ? elevation[j].toDouble() : 0.0;
                lineString->append( GeoDataCoordinates( lon, lat, alt, GeoDataCoordinates::Degree ) );
            }
        }
        instructions->setGeometry( lineString );
        result->append( instructions );
    }
    return result;
}
Esempio n. 6
0
bool OutputOptions::validateValue(const QString& optionName, const QString& value)
{
	QStringList allowValues;
	QStringList allowColors;

	if (!m_list.contains(optionName)) {
		// Option does not exist
		return false;
	}

	allowValues = m_allow[optionName].split('|');
	switch (m_type[optionName]) {
	case Integer:
		/* If the allow string is empty, then any number is allowed */
		if (m_allow[optionName].isEmpty()) {
			return true;
		}
		/* See if value is in on of the ranges */
		for (QStringList::iterator it = allowValues.begin(); it != allowValues.end(); ++it) {
			if ((*it).indexOf(':') >= 0) {
				QStringList limits = it->split(':');
				int val = value.toInt();
				int ulimit = limits[1].toInt();
				int llimit = limits[0].toInt();
				if ((val >= llimit) && (val <= ulimit)) {
					return true;
				}
			}
		}
		if (allowValues.contains(value)) {
			return true;
		}
		return false;
	case String:
		if (m_allow[optionName].isEmpty()) {
			return true;
		}
		if (allowValues.contains(value)) {
			return true;
		}
		return false;
	case Boolean:
		if ((value == "1") || (value == "0") || (value == "true") || (value == "false")) {
			return true;
		} else {
			return false;
		}
	case Color:
		allowColors.append("red");
		allowColors.append("blue");
		allowColors.append("black");
		allowColors.append("white");
		allowColors.append("green");
		allowColors.append("purple");
		if ((allowColors.contains(value)) || (value.contains(QRegExp("^#[0-9a-fA-F]{6}")))) {
			return true;
		} else {
			return false;
		}
		break;
	default :
		/* Unknown type */
		return false;
	}

	/* Error because method should have returned by now. */
	return false;
}