Esempio n. 1
0
void PmrWindowWidget::filter(const QString &pFilter)
{
    // Filter our list of exposures and remove any duplicates (they will be
    // 'reintroduced' in the next step)

    QStringList filteredExposureNames = mExposureNames.filter(QRegularExpression(pFilter, QRegularExpression::CaseInsensitiveOption));

    mNumberOfFilteredExposures = filteredExposureNames.count();

    filteredExposureNames.removeDuplicates();

    // Update our message and show/hide the relevant exposures

    page()->mainFrame()->documentElement().findFirst("p[id=message]").setInnerXml(message());

    QWebElement trElement = page()->mainFrame()->documentElement().findFirst(QString("tbody[id=exposures]")).firstChild();
    QWebElement ulElement;

    for (int i = 0, iMax = mExposureNames.count(); i < iMax; ++i) {
        if (mExposureDisplayed[i] != filteredExposureNames.contains(mExposureNames[i])) {
            QString displayValue = mExposureDisplayed[i]?"none":"table-row";

            trElement.setStyleProperty("display", displayValue);

            ulElement = trElement.firstChild().firstChild().nextSibling();

            if (ulElement.hasClass("visible"))
                ulElement.setStyleProperty("display", displayValue);

            mExposureDisplayed[i] = !mExposureDisplayed[i];
        }

        trElement = trElement.nextSibling();
    }
}
Esempio n. 2
0
void MainWindow::finished_loading(bool ok)
{
	if(!ok)
std::cout << "LOAD FINISH NOT OK!\n\n";
	QString output;
	QWebElement body;
	progress = 100;
	adjust_title();
	QWebFrame *frame = uimw->webView->page()->mainFrame();
	QWebElement document = frame->documentElement();
	QWebElement element = document.firstChild();
	while(!element.isNull())
	{
		if(element.tagName() == "BODY")
		{
			output = element.toInnerXml();
			if(output == "ok\n")
			{
				QNetworkCookieJar *cj = uimw->webView->page()->networkAccessManager()->cookieJar();
				QList<QNetworkCookie> cookies = cj->cookiesForUrl(testauth);
				for(QList<QNetworkCookie>::const_iterator i = cookies.begin() ; i != cookies.end() ; i++ )
				{
					std::cout << "Set-Cookie: ";
					QByteArray ba = i->toRawForm();
					std::cout.write(ba.data(), ba.count());
					std::cout << "\r\n";
				}
				exit(0);
			}
		}
		element = element.nextSibling();
	}
	this->show();
}
Esempio n. 3
0
//#####################################################################
// Function setDOMNodes
//#####################################################################
void Page::setDOMNodes(const QWebElement& domNode) {
    QWebElement domChild = domNode.firstChild();
    while (!domChild.isNull()) {
        setDOMNodes(domChild);
        domChild = domChild.nextSibling();
    }
    mDOMNodes.append(domNode);
}
Esempio n. 4
0
//! [traverse document]
void Window::examineChildElements(const QWebElement &parentElement,
                                  QTreeWidgetItem *parentItem)
{
    QWebElement element = parentElement.firstChild();
    while (!element.isNull()) {

        QTreeWidgetItem *item = new QTreeWidgetItem();
        item->setText(0, element.tagName());
        parentItem->addChild(item);

        examineChildElements(element, item);

        element = element.nextSibling();
    }
}
Esempio n. 5
0
QTreeWidgetItem* XPathInspector::createTree(QWebElement root)
{
	QString js = "var arr = []; ";
    js +=        "for (var i=0; i<this.childNodes.length; i++) ";
    js +=        "   if (this.childNodes[i].nodeType == 3 && this.childNodes[i].nodeValue.replace(/^\\s+|\\s+$/g,'') != '') ";
    js +=        "      arr.push(this.childNodes[i].nodeValue); ";
	js +=        "   else if (this.childNodes[i].nodeType == 1)";
	js +=        "      arr.push(this.childNodes[i].tagName); ";
    js +=        "arr; ";
	QVariant v = root.evaluateJavaScript(js);
	QStringList nodes = v.toStringList();

	QWebElement child = root.firstChild();
	QList<QTreeWidgetItem*> list;
	int i = 0;
	while (!(i>=nodes.count() && child.isNull()))
	{
		while (i<nodes.count() && nodes.at(i) != child.tagName())
		{
			QTreeWidgetItem *item2 = new QTreeWidgetItem();
			item2->setText(0, nodes.at(i));
			list.append(item2);
			i++;
		}
		if (!child.isNull())
		{
			list.append(createTree(child));
			child = child.nextSibling();
			i++;
		}
	}

	QString text = "<"+root.tagName().toLower();
	QStringList attrs = root.attributeNames();
	for (int i=0; i<attrs.count(); i++)
		text += " "+attrs.at(i)+"=\""+root.attribute(attrs.at(i))+"\"";
	text += ">";
	
	QTreeWidgetItem *item = new QTreeWidgetItem();
	item->setText(0, text);
	QVariant v2(QVariant::UserType);
	v2.setValue<QWebElement>(root);
	item->setData(0, Qt::UserRole, v2);
	item->addChildren(list);
	return item;
}
void PhysiomeModelRepositoryWindowWidget::filter(const QString &pFilter)
{
    // Make sure that we have something to filter (i.e. no error message)

    if (!mErrorMessage.isEmpty())
        return;

    // Filter our list of exposures, remove any duplicates (they will be
    // reintroduced in the next step) and update our message (by retranslating
    // ourselves)

    QStringList filteredExposureNames = mExposureNames.filter(QRegularExpression(pFilter, QRegularExpression::CaseInsensitiveOption));

    mNumberOfFilteredExposures = filteredExposureNames.count();

    filteredExposureNames.removeDuplicates();

    retranslateUi();

    // Show/hide the relevant exposures
    // Note: to call QWebElement::setStyleProperty() many times is time
    //       consuming, hence we rely on mExposureDisplayed to determine when we
    //       should change the display property of our elements...

    QWebElement trElement = page()->mainFrame()->documentElement().findFirst(QString("tbody[id=exposures]")).firstChild();
    QWebElement ulElement;

    for (int i = 0, iMax = mExposureNames.count(); i < iMax; ++i) {
        if (mExposureDisplayed[i] != filteredExposureNames.contains(mExposureNames[i])) {
            QString displayValue = mExposureDisplayed[i]?"none":"table-row";

            trElement.setStyleProperty("display", displayValue);

            ulElement = trElement.firstChild().firstChild().nextSibling();

            if (ulElement.hasClass("visible"))
                ulElement.setStyleProperty("display", displayValue);

            mExposureDisplayed[i] = !mExposureDisplayed[i];
        }

        trElement = trElement.nextSibling();
    }
}
Esempio n. 7
0
QWebElement MyWebView::FindElementByName(QWebElement &elem, QString &name)
{
	if (elem.attribute("id").compare(name, Qt::CaseInsensitive) == 0)
	{
		return elem;
	}
	else
	{
		QWebElement childelem = elem.firstChild();
		QWebElement retelem;
		while (!childelem.isNull())
		{
			retelem = FindElementByName(childelem, name);
			if (!retelem.isNull())
			{
				return retelem;
			}
			childelem = childelem.nextSibling();
		}
	}
	return QWebElement();
}
void StationScheduleModel::parse(const QByteArray &htmlReply, const QUrl &baseUrl)
{
    Q_UNUSED(baseUrl);
    qDebug() << "--- start of query result --- cut here ------";
    qDebug() << QString::fromUtf8(htmlReply.constData());
    qDebug() << "--- end of query result ----- cut here ------";

    emit layoutAboutToBeChanged();
    beginResetModel();
    QWebPage page;
    page.mainFrame()->setContent(htmlReply, "text/html", baseUrl);
    QWebElement doc = page.mainFrame()->documentElement();

    // Check if the page is reporting an error before parsing it
    QWebElement errorElement = doc.findFirst("span.errore");
    if (!errorElement.isNull()) {
        m_departureSchedules.clear();
        m_arrivalSchedules.clear();
        QString errorText = errorElement.toPlainText().trimmed();
        if (errorText == "localita' non trovata") {
            setError(tr("Unknown station"));
        } else {
            setError(tr("Unknown error"));
        }
        qDebug() << "error:" << error();
        return;
    }
    // Find the first div
    QWebElement current = doc.findFirst("div");

    qDebug() << "skipping to the departures";
    // Skip to the first div of class corpocentrale, which contains the first
    // departure-related contents
    while (!current.classes().contains("corpocentrale")) {
        current = current.nextSibling();
        qDebug() << "skipping to the next element";
        if (current.isNull())
            break;
    }
    // Mark every div as a departure class element; the next corpocentrale
    // marks the start of the arrivals section
    qDebug() << "marking departures";
    do {
        if (current.classes().contains("bloccorisultato")) {
            StationScheduleItem schedule = parseResult(current);
            if (schedule.isValid()) {
                m_departureSchedules << schedule;
            }
        }
        current = current.nextSibling();
        qDebug() << "marking as departures";
        if (current.isNull())
            break;
    } while (!current.classes().contains("corpocentrale"));

    // Mark everything as an arrival, until reaching the footer
    while (!current.classes().contains("footer")) {
        if (current.classes().contains("bloccorisultato")) {
            StationScheduleItem schedule = parseResult(current);
            if (schedule.isValid()) {
                m_arrivalSchedules << schedule;
            }
        }
        current = current.nextSibling();
        qDebug() << "marking as arrival";
        if (current.isNull())
            break;
    }
    endResetModel();
    emit layoutChanged();
}
void CellmlAnnotationViewMetadataNormalViewDetailsWidget::linkClicked()
{
    // Retrieve some information about the link

    mOutputOntologicalTerms->retrieveLinkInformation(mLink, mTextContent);

    // Check whether we have clicked a resource/id link or a button link

    if (mTextContent.isEmpty()) {
        // Update some information

        CellMLSupport::CellmlFileRdfTriple *rdfTriple = mRdfTriplesMapping.value(mLink);

        QString qualifier = (rdfTriple->modelQualifier() != CellMLSupport::CellmlFileRdfTriple::ModelUnknown)?
                                rdfTriple->modelQualifierAsString():
                                rdfTriple->bioQualifierAsString();
        QString rdfTripleInformation = qualifier+"|"+rdfTriple->resource()+"|"+rdfTriple->id();

        mUrls.remove(rdfTripleInformation);

        mRdfTripleInformationSha1s.removeOne(mLink);

        mRdfTriplesMapping.remove(mLink);

        --mItemsCount;

        // Determine the 'new' RDF triple information to look up, based on
        // whether there are RDF triples left and whether the current RDF triple
        // is the one being highlighted

        QWebElement rdfTripleElement = mOutputOntologicalTerms->page()->mainFrame()->documentElement().findFirst(QString("tr[id=item_%1]").arg(mLink));

        if (!mItemsCount) {
            mRdfTripleInformation = QString();
            mInformationType = None;
        } else if (!mLink.compare(mRdfTripleInformationSha1)) {
            QWebElement newRdfTripleEment = rdfTripleElement.nextSibling();

            if (newRdfTripleEment.isNull())
                newRdfTripleEment = rdfTripleElement.previousSibling();

            static const QRegularExpression ItemRegEx = QRegularExpression("^item_");

            CellMLSupport::CellmlFileRdfTriple *newRdfTriple = mRdfTriplesMapping.value(newRdfTripleEment.attribute("id").remove(ItemRegEx));
            QString newQualifier = (newRdfTriple->modelQualifier() != CellMLSupport::CellmlFileRdfTriple::ModelUnknown)?
                                       newRdfTriple->modelQualifierAsString():
                                       newRdfTriple->bioQualifierAsString();

            mRdfTripleInformation = newQualifier+"|"+newRdfTriple->resource()+"|"+newRdfTriple->id();

            if (!rdfTripleInformation.compare(mFirstRdfTripleInformation))
                mFirstRdfTripleInformation = mRdfTripleInformation;

            if (!rdfTripleInformation.compare(mLastRdfTripleInformation))
                mLastRdfTripleInformation = mRdfTripleInformation;
        }

        // Remove the RDF triple from our GUI

        rdfTripleElement.removeFromDocument();

        // Do some additional GUI updates

        mLookUpRdfTripleInformation = Any;

        if (!mLink.compare(mRdfTripleInformationSha1))
            additionalGuiUpdates(mRdfTripleInformation, mInformationType, mLookUpRdfTripleInformation);
        else
            // The looked up information is the same, so no need to look it up
            // again
            // Note: indeed, to look it up again would result in the web view
            //       flashing (since a 'new' web page would be loaded)...

            additionalGuiUpdates(mRdfTripleInformation, mInformationType, No);

        // Remove the RDF triple from the CellML file

        mCellmlFile->rdfTriples().remove(rdfTriple);

        // Let people know that an RDF triple has been removed

        emit rdfTripleRemoved(rdfTriple);
    } else {
        // We have clicked on a qualifier/resource/id link, so start by enabling
        // the looking up of any RDF triple information

        mLookUpRdfTripleInformation = Any;

        // Call our generic look up function

        QStringList rdfTripleInformation = mLink.split("|");

        genericLookUp(mLink,
                      (!rdfTripleInformation[0].compare(mTextContent))?
                          Qualifier:
                          !rdfTripleInformation[1].compare(mTextContent)?
                              Resource:
                              Id);
    }
}
void WBWebTrapWebView::highliteElementAtPos ( const QPoint& pos)
{
    mCurrentContentType = Unknown;

    if(page() && page()->currentFrame())
    {
        QWebHitTestResult htr = page()->currentFrame()->hitTestContent (pos);
        QRect pageHtr = htr.boundingRect().translated(htr.frame()->pos());

        QRect updateRect = mWebViewElementRect.united(pageHtr);
        updateRect = updateRect.adjusted(-8, -8, 8, 8);

        mDomElementRect = htr.boundingRect();

        if (!htr.pixmap().isNull())
        {
            mCurrentContentType = Image;
            qDebug() << "found pixmap at " << htr.boundingRect();
        }
        else
        {
            QWebElement element = htr.element();
            QString tagName = element.tagName().toLower();

            if (tagName == "object"
                || tagName == "embed")
            {
                mCurrentContentType = ObjectOrEmbed;
            }
            else if ((tagName == "input") || (tagName == "textarea"))
            {
                QString ec = potentialEmbedCodeAtPos(pos);

                if (ec.length() > 0)
                {
                    qDebug() << "found input data \n\n" << ec;
                    mCurrentContentType = Input;
                }
            }
            else
            {
                QString tagName = htr.element().tagName();
                QString id =  htr.element().attribute("id", "");
                QWebElement el = htr.element();

                QString idSelector = tagName + "#" + id;
                bool idSuccess = (el == el.document().findFirst(idSelector));

                if (idSuccess)
                {
                    mElementQuery = idSelector;
                    mCurrentContentType = ElementByQuery;
                }
                else
                {
                    //bool isValid = true;

                    QWebElement elParent = el.parent();
                    QWebElement currentEl = el;
                    QString path = tagName;
                    QStringList pathElements;

                    do
                    {
                        QWebElement someSibling = elParent.firstChild();

                        int index = 0;
                        bool foundIndex = false;

                        do
                        {
                            if (someSibling.tagName() == currentEl.tagName())
                            {
                                if (someSibling == currentEl)
                                {
                                    foundIndex = true;
                                }
                                else
                                    index++;
                            }

                            someSibling = someSibling.nextSibling();
                        }
                        while(!someSibling.isNull() && !foundIndex);

                        QString part;

                        if (index > 0)
                            part = QString("%1:nth-child(%2)").arg(currentEl.tagName()).arg(index);
                        else
                            part = currentEl.tagName();

                        pathElements.insert(0, part);

                        currentEl = elParent;
                        elParent = elParent.parent();

                    } while(!elParent.isNull());

                    //QString idSelector = tagName + "#" + id;
                    QString treeSelector =  pathElements.join(" > ");

                    mElementQuery = treeSelector;
                    mCurrentContentType = ElementByQuery;

                    //bool treeSuccess = (el == el.document().findFirst(treeSelector));

                    //qDebug() << "----------------------------";
                    //qDebug() << idSuccess << idSelector;
                    //qDebug() << treeSuccess << treeSelector;
                }
            }
        }

        update(updateRect);
    }
}