/** * \en * clears all tags from pattern * \_en * \ru * Удаляет все теги из документа, а также строки, в которых содержится тег секции * \_ru */ void aMSOTemplate::cleanUpTags() { QDomNode n = docTpl.lastChild(); while( !n.isNull() ) { clearTags(n,false); //clearRow(n); n = n.previousSibling(); } n = docTpl.lastChild(); while( !n.isNull() ) { //clearTags(n,false); clearRow(n); n = n.previousSibling(); } n = docTpl.lastChild(); while (!n.isNull()) { clearAttributes(n, "Table", "ss:ExpandedRowCount"); n = n.previousSibling(); } }
/** * \en * Deletes row, having section tag * \_en * \ru * Рекурсивная функция. Удаляет строки, содержащие тег секции * \_ru * \param node - \en context \_en \ru узел из которого нужно удалить строки \_ru */ void aMSOTemplate::clearRow(QDomNode node) { QDomNode n = node.lastChild(); while( !n.isNull() ) { if(n.isText()) { QString str = n.nodeValue(); QRegExp re; re.setPattern(QString("%1.*%2").arg(open_token_section).arg(close_token_section)); re.setMinimal(true); int pos = re.search(str,0); if(pos!=-1) { QDomNode tmp = n; while(!tmp.parentNode().isNull()) { tmp = tmp.parentNode(); if( tmp.nodeName()=="Row" ) { tmp.parentNode().removeChild(tmp); break; } } } } else { clearRow(n); } n = n.previousSibling(); } }
/** * \en * Added value to end tag with name `sname'. Don't deletes tag. * \_en * \ru * Рекурсивная функция поиска и замены тегов на их значения в node. * Не заменяет теги, а дописывает значения в конец. * Для удаления тэгов используйте функцию cleanUpTags() * \_ru * \param node - \en context for searching \_en \ru узел, с которого осуществляется поиск. \_ru * \param sname - \en tag name \_en \ru имя тега для поиска \_ru * \see cleanUpTags() getNodeTags() insertRowValues() */ void aMSOTemplate::searchTags(QDomNode node, const QString &sname ) { QDomNode n = node.lastChild(); while( !n.isNull() ) { bool res = getNodeTags(n, sname, false); if( res ) { insertRowValues(n); } else { res = getNodeTags(n, sname, true); if(res) { insertTagsValues(n, sname); } else { searchTags(n, sname); } } n = n.previousSibling(); } }
QDomNode QDomNodeProto:: previousSibling() const { QDomNode *item = qscriptvalue_cast<QDomNode*>(thisObject()); if (item) return item->previousSibling(); return QDomNode(); }
// returns the DOM node of the previous behaviour in a pattern // QDomNode PolicyDocumentClass::getPrevBehaviourNode(const QString& patternName, const QString& behaviourName) const { QDomNode behaviourNode = getBehaviourNode(patternName, behaviourName); QDomNode previousNode = behaviourNode.previousSibling(); // get previous node until a behaviour is found // while(previousNode.toElement().tagName() != XML_TAG_BEHAVIOUR) { previousNode = previousNode.previousSibling(); if (previousNode.isNull()) return previousNode; } return previousNode; }
void ScrobblesListWidget::read() { qDebug() << m_path; clear(); // always have a now playing item in the list m_trackItem = new ScrobblesListWidgetItem( this ); TrackWidget* trackWidget = new TrackWidget( m_track, this ); trackWidget->setObjectName( "nowPlaying" ); setItemWidget( m_trackItem, trackWidget ); m_trackItem->setSizeHint( trackWidget->sizeHint() ); m_trackItem->setHidden( true ); m_trackItem->setNowPlaying( true ); connect( trackWidget, SIGNAL(clicked(TrackWidget&)), SLOT(onItemClicked(TrackWidget&)) ); // always have the refresh button in the list m_refreshItem = new ScrobblesListWidgetItem( this ); RefreshButton* refreshButton = new RefreshButton( this ); refreshButton->setObjectName( "refresh" ); setItemWidget( m_refreshItem, refreshButton ); m_refreshItem->setSizeHint( refreshButton->sizeHint() ); connect( refreshButton, SIGNAL(clicked()), SLOT(refresh()) ); onRefreshing( false ); // always have a view more item in the list m_moreItem = new ScrobblesListWidgetItem( this ); QPushButton* moreButton = new QPushButton( tr( "More Scrobbles at Last.fm" ), this ); moreButton->setObjectName( "more" ); setItemWidget( m_moreItem, moreButton ); m_moreItem->setSizeHint( moreButton->sizeHint() ); connect( moreButton, SIGNAL(clicked()), SLOT(onMoreClicked()) ); QFile file( m_path ); file.open( QFile::Text | QFile::ReadOnly ); QTextStream stream( &file ); stream.setCodec( "UTF-8" ); QDomDocument xml; xml.setContent( stream.readAll() ); QList<Track> tracks; for (QDomNode n = xml.documentElement().lastChild(); !n.isNull(); n = n.previousSibling()) tracks << Track( n.toElement() ); addTracks( tracks ); fetchTrackInfo( tracks ); limit( kScrobbleLimit ); }
/** * \en * Defines number of a line in a pattern * \_en * \ru * Определяет номер строки в шаблоне * \_ru * \param node - \en context \_en \ru узел Row для которого определяется индекс \_ru */ int aMSOTemplate::getRowIndex(QDomNode node) { QDomNode n = node; int i = 0; while( n.nodeName()=="Row") { ++i; n = n.previousSibling(); } return i; }
/** * \en * Execute replace tags to values. * \_en * \ru * Выполняет подстановку значения параметра в шаблоне. * Есть 2 типа тегов * \arg обычные теги * \arg секции - могут находиться ТОЛЬКО в строках таблицы. * Для подстановки значений обычных тегов необходимо выполнить setValue() где name = PARAM (сейчас #define PARAM "param") а value - значение для подстановки. Потом выполнить exec() с параметром = имени тега. * Для подстановки секций необходимо з адать нужные параметры, используя setValue() * а потом выполнить exec() с именем секции. * exec может вызываться нужное число раз как для обычных тегов, так и для секций * \_ru * \param sname - \en name of parametr.\_en \ru * имя параметра\_ru */ QString aMSOTemplate::exec( const QString &sname ) { setValue(sname, getValue(PARAM)); //search tags in content QDomNode n = docTpl.lastChild(); while( !n.isNull() ) { searchTags(n, sname); n = n.previousSibling(); } return docTpl.toString(); }
SyntaxHighlighter::SyntaxHighlighter( CodeEditor *parent, QDomNode& node) : QSyntaxHighlighter(parent->document()), m_pEditor(parent) { // string list that holds the key words QStringList keys; // get first child QDomNode temp = node.lastChild(); ////////////////////////////////////////////////////////////////////////// // get key words while(!temp.isNull()) { // get children QDomNodeList children = temp.childNodes(); // get attributes QDomNamedNodeMap attributes = temp.toElement().attributes(); // extract data for (int i = 0; i < children.length(); i++) { QString keyword = attributes.namedItem("StartTag").nodeValue() + children.at(i).toElement().text() + attributes.namedItem("EndTag").nodeValue(); keys.append(keyword); } // rule HighlightingRule rule; rule.format.setForeground(QColor(attributes.namedItem("Color").nodeValue())); rule.format.setFontItalic(attributes.namedItem("Italic").nodeValue().toInt()); rule.format.setFontWeight(attributes.namedItem("Bold").nodeValue().toInt()); // add to rule set foreach (const QString &pattern, keys) { rule.pattern = QRegExp(pattern); highlightingRules.append(rule); } // clear keys keys.clear(); // next temp = temp.previousSibling(); }
/** * \en * Deletes from node attribute * \_en * \ru * Рекурсивная функция. Удаляет из узла атрибут * \_ru * \param node - \en context \_en \ru узел из которого нужно удалить атрибут \_ru * \param nodename - \en node name \_en \ru имя узла \_ru * \param attr - \en attribut name \_en \ru имя атрибута,который нужно удалить \_ru */ void aMSOTemplate::clearAttributes(QDomNode node, const QString nodename, const QString attr) { QDomNode n = node.lastChild(); while( !n.isNull() ) { if( n.parentNode().nodeName()==nodename ) { n.parentNode().toElement().removeAttribute(attr); break; } else { clearAttributes(n, nodename, attr); } n = n.previousSibling(); } }
void ItemXML::moveUp() { QDomElement element = node_.toElement(); MIRO_ASSERT(!element.isNull()); QDomNode pre = node_.previousSibling(); while (!pre.isNull()) { QDomElement e = pre.toElement(); if (!e.isNull() && e.tagName() == element.tagName()) { break; } pre = pre.previousSibling(); } if (!pre.isNull()) { Super::moveUp(); node_.parentNode().insertBefore(node_, pre); setModified(); } }
QDomNode WbNewItem::serializeToSvg(QDomDocument *doc) { if(!graphicsItem()) { return QDomDocumentFragment(); } // Generate the SVG using QSvgGenerator QBuffer buffer; QSvgGenerator generator; generator.setOutputDevice(&buffer); QPainter painter; QStyleOptionGraphicsItem options; painter.begin(&generator); graphicsItem()->paint(&painter, &options); painter.end(); // qDebug("Serialized SVG doc:"); // qDebug(buffer.buffer()); // Parse the children of the new root <svg/> from the buffer to a document fragment // also add an 'id' attribute to each of the children doc->setContent(buffer.buffer()); QDomDocumentFragment fragment = doc->createDocumentFragment(); for(QDomNode n = doc->documentElement().lastChild(); !n.isNull(); n = n.previousSibling()) { // skip <title/>, <desc/>, and <defs/> if(n.isElement() && !(n.nodeName() == "title" || n.nodeName() == "desc" || n.nodeName() == "defs")) { n.toElement().setAttribute("id", "e" + SxeSession::generateUUID()); fragment.insertBefore(n, QDomNode()); } } return fragment; }
/** * \en * Deletes tags from \a node * \_en * \ru * Удаляет рекурсивно теги из \a node. * \_ru * \param node - \en context \_en \ru узел из которого нужно удалить теги \_ru * \param section - \ru true, если надо удалить тег секции \_ru */ void aMSOTemplate::clearTags(QDomNode node, bool section ) { if(node.isNull()) return; QDomNode n = node.lastChild(); while( !n.isNull() ) { if(n.isText()) { QString str = n.nodeValue(); QRegExp re; if(section) { re.setPattern(QString("%1.*%2").arg(open_token_section).arg(close_token_section)); } else { re.setPattern(QString("%1.*%2").arg(open_token).arg(close_token)); } re.setMinimal(true); int pos = re.search(str,0); while(pos != -1) { str = str.remove(re); pos = re.search(str,0); } n.setNodeValue(str); } else { clearTags(n,section); } n = n.previousSibling(); } }
void PhonemeEditorWidget::parseXmlFile() { // Clear old text boxes QList<TimeLineTextEdit *> oldText= m_text->findChildren<TimeLineTextEdit *>(); while(!oldText.isEmpty()) delete oldText.takeFirst(); // Clear old phoneme comboboxes QList<TimeLineComboBox *> oldPhoneme = m_phonemes->findChildren<TimeLineComboBox *>(); while(!oldPhoneme.isEmpty()) delete oldPhoneme.takeFirst(); // Get new items from phoneme xml QDomElement timings = m_phonemeXml.firstChildElement("PhonemeTimings"); // Get length of phoneme timings QDomElement last = timings.lastChildElement("word"); int sentenceLength = 0; if(!last.isNull()) sentenceLength = last.attribute("end", "0").toInt(); last = timings.lastChildElement("phn"); if( !last.isNull() ) sentenceLength = max(sentenceLength, last.attribute("end", "0").toInt() ); // Get minimal phoneme width QDomNodeList phnlist = timings.elementsByTagName("phn"); int minPhnWidth = 999999; for(unsigned int i=0; i<phnlist.length(); i++) { QDomElement phn = phnlist.item(i).toElement(); // Skip silence if( phn.attribute("value").compare("x") == 0 ) continue; int start = phn.attribute("start", "0").toInt(); int end = phn.attribute("end", "999999").toInt(); if( end-start < minPhnWidth ) minPhnWidth = end-start; } int minWidth = (int)( 39.5f / minPhnWidth * sentenceLength ); // Get length of panels and enlarge them if too small if( m_text->width()-2 < minWidth) { m_text->setFixedWidth(minWidth+2); m_phonemes->setFixedWidth(minWidth+2); m_phonemeScrollArea->setFixedWidth(m_text->x()+minWidth+2); } // Add wordBoxes in reverse direction, because first nodes have higher priority // and should be printed above of the others QDomNode wordNode = timings.lastChild(); while(!wordNode.isNull()) { // Get words if( wordNode.nodeName().compare("word") == 0) { QDomElement word = wordNode.toElement(); TimeLineTextEdit* wordBox = new TimeLineTextEdit(word, sentenceLength, m_text); connect(wordBox, SIGNAL(xmlNodeChanged()), this, SLOT(enableSaveButton()) ); wordBox->setVisible(true); // Get phonemes of a word QDomNodeList phonemeList = word.elementsByTagName("phn"); // also reverse direction for(int i = phonemeList.size()-1; i >=0; i--) { QDomElement phoneme = phonemeList.item(i).toElement(); // Skip silence if( phoneme.attribute("value").compare("x") == 0 ) continue; TimeLineComboBox* phonemeBox = new TimeLineComboBox(phoneme, sentenceLength, m_phonemeList, m_phonemes); connect(phonemeBox, SIGNAL(xmlNodeChanged()), this, SLOT(enableSaveButton()) ); connect(phonemeBox, SIGNAL(xmlNodeChanged()), wordBox, SLOT(updateFromXml())); phonemeBox->setVisible(true); } } // Get phonemes which don't belong to words else if( wordNode.nodeName().compare("phn") == 0 ) { QDomElement phoneme = wordNode.toElement(); // Skip silence if( phoneme.attribute("value").compare("x") != 0 ) { TimeLineComboBox* phonemeBox = new TimeLineComboBox(phoneme, sentenceLength, m_phonemeList, m_phonemes); connect(phonemeBox, SIGNAL(xmlNodeChanged()), this, SLOT(enableSaveButton()) ); phonemeBox->setVisible(true); } } wordNode = wordNode.previousSibling(); } }
void schedulexmldata::addschedulexmldata(QString tmpscheduledate, QString tmpid, QString tmptheme, QString tmpoccurtime, QString tmpoccuraddress, /*QString tmpremindtime, QString tmpremindway, QString tmpremindsequence,*/ QString tmpeventrepeat, QString tmpdetail) { QFile file("/home/user/.scheduledata.xml"); if(!file.open(QIODevice::ReadOnly)) return; QDomDocument doc; if(!doc.setContent(&file)){ file.close(); return; } file.close(); QDomText text; QDomElement root = doc.documentElement(); QDomElement scheduledate = doc.createElement(QString("scheduledate")); QDomAttr scheduledateattr = doc.createAttribute(QString("scheduledateattr")); scheduledate.setAttributeNode(scheduledateattr); QDomElement schedule = doc.createElement(QString("schedule")); QDomNode n = root.firstChild(); if(n.toElement().attribute(QString("scheduledateattr")) == "00000000"){ root.removeChild(n); root.appendChild(scheduledate); scheduledateattr.setValue(tmpscheduledate); scheduledate.appendChild(schedule); }else{ bool scheduledateisexistence = false; while(!n.isNull()){ if((n.previousSibling().toElement().attribute(QString("scheduledateattr")) < tmpscheduledate) &&( tmpscheduledate < n.toElement().attribute(QString("scheduledateattr")))){ root.insertBefore(scheduledate, n); scheduledateattr.setValue(tmpscheduledate); scheduledate.appendChild(schedule); scheduledateisexistence = true; }else if(tmpscheduledate == n.toElement().attribute(QString("scheduledateattr"))){ n.toElement().appendChild(schedule); scheduledateisexistence = true; } n = n.nextSibling(); } if(!scheduledateisexistence){ root.appendChild(scheduledate); scheduledateattr.setValue(tmpscheduledate); scheduledate.appendChild(schedule); } } if(tmpid == "-10"){ QDomNode nn = root.firstChild(); while(!nn.isNull()){ if(tmpscheduledate == nn.toElement().attribute(QString("scheduledateattr"))){ QDomNodeList schedulelist = nn.toElement().elementsByTagName(QString("schedule")); tmpid.setNum(schedulelist.count() - 1); qDebug() << tmpid; } nn = nn.nextSibling(); } } QDomAttr scheduleid = doc.createAttribute(QString("id")); scheduleid.setValue(QString(tmpid)); schedule.setAttributeNode(scheduleid); QDomElement theme = doc.createElement(QString("theme")); text = doc.createTextNode(QString(tmptheme)); theme.appendChild(text); schedule.appendChild(theme); QDomElement occurtime = doc.createElement(QString("occurtime")); text = doc.createTextNode(QString(tmpoccurtime)); occurtime.appendChild(text); schedule.appendChild(occurtime); QDomElement occuraddress = doc.createElement(QString("occuraddress")); text = doc.createTextNode(QString(tmpoccuraddress)); occuraddress.appendChild(text); schedule.appendChild(occuraddress); // QDomElement remindtime = doc.createElement(QString("remindtime")); // text = doc.createTextNode(QString(tmpremindtime)); // remindtime.appendChild(text); // schedule.appendChild(remindtime); // QDomElement remindway = doc.createElement(QString("remindway")); // text = doc.createTextNode(QString(tmpremindway)); // remindway.appendChild(text); // schedule.appendChild(remindway); // QDomElement remindsequence = doc.createElement(QString("remindsequence")); // text = doc.createTextNode(QString(tmpremindsequence)); // remindsequence.appendChild(text); // schedule.appendChild(remindsequence); QDomElement eventrepeat = doc.createElement(QString("eventrepeat")); text = doc.createTextNode(QString(tmpeventrepeat)); eventrepeat.appendChild(text); schedule.appendChild(eventrepeat); QDomElement detail = doc.createElement(QString("detail")); text = doc.createTextNode(QString(tmpdetail)); detail.appendChild(text); schedule.appendChild(detail); if( !file.open(QIODevice::WriteOnly | QIODevice::Truncate)) return; QTextStream out(&file); doc.save(out, 4); file.close(); }
bool ChartElemNavaids::loadFromDomElement(QDomElement& dom_element, QDomDocument& dom_doc, QString& err_msg) { MYASSERT(!dom_element.isNull()); TreeBaseXML::loadFromDomElement(dom_element, dom_doc, err_msg); if (m_dom_element.tagName() != CHART_NODE_NAME_NAVAIDS) { err_msg = QString("Wrong node name (%s), expected (%s)"). arg(m_dom_element.tagName()).arg(CHART_NODE_NAME_NAVAIDS); return false; } // loop through all navaids QDomNode node = m_dom_element.firstChild(); for(; !node.isNull(); node = node.nextSibling()) { QDomElement element = node.toElement(); if (element.isNull()) continue; // extract info from node QString id = element.attribute(CHART_ATTR_ID); QString ctry = element.attribute(CHART_ATTR_CTRY); QString name = element.attribute(CHART_ATTR_NAME); double lat = element.attribute(CHART_ATTR_LAT).toDouble(); double lon = element.attribute(CHART_ATTR_LON).toDouble(); int freq = element.attribute(CHART_ATTR_FREQ).toUInt(); bool has_dme = element.attribute(CHART_ATTR_DME).toInt(); int elevation = element.attribute(CHART_ATTR_ELEV).toInt(); // check info if (id.isEmpty()) { err_msg = QString("Navaids: Missing ID at tag named (%1)").arg(element.tagName()); return false; } // process element if (element.tagName() == CHART_NODE_NAME_NAVAIDS_VOR) { Vor* vor = 0; if (!name.isEmpty() && lat != 0.0 && lon != 0.0 && freq != 0) vor = new Vor(id, name, lat, lon, freq, has_dme, 0, 0, ctry); else vor = (Vor*)m_chart_model->getNavdata()->getElementsWithSignal( id, ctry, Waypoint::VOR); if (!vor) { err_msg = QString("Navaids:VOR: unknown VOR with ID (%1)").arg(id); return false; } if (!addVor(*vor, element, dom_doc, err_msg)) { node = node.previousSibling(); m_dom_element.removeChild(element); } delete vor; } else if (element.tagName() == CHART_NODE_NAME_NAVAIDS_NDB) { Ndb* ndb = 0; if (!name.isEmpty() && lat != 0.0 && lon != 0.0 && freq != 0) ndb = new Ndb(id, name, lat, lon, freq, 0, 0, ctry); else ndb = (Ndb*)m_chart_model->getNavdata()->getElementsWithSignal( id, ctry, Waypoint::NDB); if (!ndb) { err_msg = QString("Navaids:NDB: unknown NDB with ID (%1)").arg(id); return false; } if (!addNdb(*ndb, element, dom_doc, err_msg)) { node = node.previousSibling(); m_dom_element.removeChild(element); } delete ndb; } else if (element.tagName() == CHART_NODE_NAME_NAVAIDS_AIRPORT) { Airport* airport = 0; if (!name.isEmpty() && lat != 0.0 && lon != 0.0 && element.hasAttribute(CHART_ATTR_ELEV)) airport = new Airport(id, name, lat, lon, elevation); else airport = (Airport*)m_chart_model->getNavdata()->getElementsWithSignal( id, ctry, Waypoint::AIRPORT); if (!airport) { err_msg = QString("Navaids:AIRPORT: unknown AIRPORT with ID (%1)").arg(id); return false; } if (!addAirport(*airport, element, dom_doc, err_msg)) { node = node.previousSibling(); m_dom_element.removeChild(element); } delete airport; } else if (element.tagName() == CHART_NODE_NAME_NAVAIDS_INTERSECTION) { Intersection* intersection = 0; if (lat != 0.0 && lon != 0.0) intersection = new Intersection(id, lat, lon, ctry); else intersection = (Intersection*)m_chart_model->getNavdata()->getElementsWithSignal( id, ctry, Waypoint::INTERSECTION); if (!intersection) { err_msg = QString("Navaids:INTERSECTION: unknown INTERSECTION with ID (%1)").arg(id); return false; } if (!addIntersection(*intersection, element, dom_doc, err_msg)) { node = node.previousSibling(); m_dom_element.removeChild(element); } delete intersection; } } return true; }