Beispiel #1
0
void Parser::parseCourses(QNetworkReply *reply, QStandardItemModel *itemModel)
{
    // Empfangene Nachricht auslesen und als JSON interpretieren
    QByteArray response(reply->readAll());
    QJsonDocument document = QJsonDocument::fromJson(response);
    QJsonObject object = document.object();

    if(object.isEmpty())
    {
        QLOG_WARN() << tr("Kursinformationen leer bzw. nicht lesbar.");
        return;
    }

    if(!object["Status"].toBool())
    {
        QLOG_ERROR() << tr("Status der Kursinformationen nicht ok: ") <<
                        QString(document.toJson());
        return;
    }

    // Array mit allen einzelnen Vorlesungen/Veranstaltungen
    QJsonArray courses = object["dataSet"].toArray();

    // Für jede Veranstaltung ein neues Strukturelement anlegen
    foreach(QJsonValue element, courses)
    {
        QJsonObject course = element.toObject();

        QString title = course["courseTitle"].toString();
        QString cid = course["uniqueid"].toString();
        QString semester = course["semester"].toString();
        QString url = course["url"].toString();

        // Erstellen eines RegExps  für unzulässige Buchstaben im Veranstaltungsnamen
        QString escapePattern = "(:|<|>|/|\\\\|\\||\\*|\\^|\\?|\\\")";
        QRegExp escapeRegExp(escapePattern, Qt::CaseSensitive);
        title = title.replace(escapeRegExp, "").trimmed();
        // Titellänge limitieren um Probleme bei Dateisystemen zu verhindern
        title.truncate(100);

        Structureelement *newCourse = new Structureelement(title, QUrl(url), 0, 0, cid, courseItem);

        Utils::getSemesterItem(itemModel, semester)->appendRow(newCourse);

        QLOG_DEBUG() << tr("Veranstaltung") << title << "(" << cid << tr(") hinzugefügt.");
    }
Beispiel #2
0
static OfxStatus interactPenUp(OfxImageEffectHandle  effect, OfxInteractHandle interactInstance, OfxPropertySetHandle inArgs)
{
	// get my data handle
	MyInteractData *data = getInteractData(interactInstance);
	Instance *instance = (Instance*)ofxuGetEffectInstanceData(effect);

	double penPos[2];
	gPropHost->propGetDoubleN(inArgs, kOfxInteractPropPenPosition, 2, penPos);

	if (data->Down)
	{
		// Get the image size
		const std::pair<int, int> &size = instance->Mask.getSize ();
		const int upX = (int)penPos[0];
		const int upY = size.second-(int)penPos[1]-1;

		std::set<std::string> names;
		openexrid::Sample sample;

		const int alpha = instance->Mask.findSlice ("A");

		const int maxX = std::min (std::max (upX, data->DownX)+1, size.first);
		const int maxY = std::min (std::max (upY, data->DownY)+1, size.second);
		for (int y = std::max (std::min (upY, data->DownY), 0); y < maxY; ++y)
		for (int x = std::max (std::min (upX, data->DownX), 0); x < maxX; ++x)
 		{
 			// Get the max coverage sample in the pixel
			float maxCoverage = 0;
			uint32_t maxId = ~0U;
			const int sampleN = instance->Mask.getSampleN (x, y);
			for (int s = 0; s < sampleN; ++s)
			{
				openexrid::Sample sample;
				instance->Mask.getSample (x, y, s, sample);
				if (alpha == -1 || sample.Values[alpha] > maxCoverage)
				{
					maxId = sample.Id;
					if (alpha != -1)
						maxCoverage = sample.Values[alpha];
				}
			}

			// Found something ?
			if (maxId != ~0U)
			{
				const char *name = instance->Mask.getName (maxId);
				names.insert (escapeRegExp (name));
			}
		}
 
		// Get the old pattern
		const char *_oldPattern;
		gParamHost->paramGetValue (data->patternParam, &_oldPattern);
		std::string oldPattern = _oldPattern;
		
		/* Nuke escapes the \ of the text parameter */
		std::set<std::string> oldNames (split (oldPattern.c_str (), "\n\r"));

		// Shift ?
		if (data->Shift)
		{
			// Reverse the selection for the previously selected names
			for (const auto &name : oldNames)
			{
				// Try insert
				auto r = names.insert (name);

				// Already there, remove it
				if (!r.second)
					names.erase (r.first);
			}
		}

		// get the point param's value
		std::string pattern = join (names, "\n");
		gParamHost->paramSetValue(data->patternParam, pattern.c_str ());
		data->Down = false;
	}
	return kOfxStatOK;
}