bool WDomElem::insertChild(int pos, int count, QDomElement &element) { // check validity if ( (element.tagName().compare(g_strValidNodeTag, Qt::CaseInsensitive) != 0 ) || pos < 0 || count < 1 || pos > domElem.childNodes().size()) { return false; } // decide if append or insert if (pos >= countChild()) { // append new nodes for (int i = 0; i < count; i++) { appendChild(element); } } else { // insert new nodes for (int i = 0; i < count; i++) { domElem.insertBefore(element, getValidElemAt(pos)); WDomElem * childNode = new WDomElem(element, pos, this); childWDomElems.insert(pos, 1, childNode); } // update row numbers updateRowNumbers(); } return true; }
bool WDomElem::appendChild(QDomElement &element) { if (element.toElement().tagName().compare(g_strValidNodeTag, Qt::CaseInsensitive) != 0 ) { return false; } // appenda at DOM tree level, WDomElem child is appended automagically in WDomElem::getChild (OR NOT ???) domElem.appendChild(element); // append at TREE level childWDomElems.resize(childWDomElems.size()+1); childWDomElems[childWDomElems.size()-1] = new WDomElem(element, childWDomElems.size()-1, this); // update row numbers updateRowNumbers(); return true; }
bool WDomElem::replaceChild(int pos, QDomElement &element) { // check validity if (pos >= domElem.childNodes().size()) { return false; } // Qt Doc: If newChild is the child of another node, it is reparented to this node. // Qt Doc: If newChild is a child of this node, then its position in the list of children is changed. //domElem.replaceChild(element, domElem.childNodes().at(pos)); domElem.replaceChild(element, getValidElemAt(pos)); delete childWDomElems[pos]; childWDomElems[pos] = new WDomElem(element, pos, this); updateRowNumbers(); // not sure if necessary return true; }
bool WDomElem::removeChild(int pos, int count) { // check validity if (pos+count > domElem.childNodes().size()) { return false; } // remove children for (int i = 0; i < count; i++) { // remove from DOM //domElem.removeChild(domElem.childNodes().at(pos)); QDomElement delem = getValidElemAt(pos); getElem().removeChild(delem); // remove from tree delete childWDomElems[pos]; childWDomElems.remove(pos); } // update row numbers updateRowNumbers(); return true; }
void WWidgetNode::setupNodeChildren() { QFileInfo info(m_strPath); if (!info.isDir()) { qDebug() << "[ERROR] Not a directory in WWidgetNode::setupNodeChildren"; } QDir dir(info.absoluteFilePath()); QFileInfo newinfo; QFileInfoList list; WWidgetNode * child; int count = 0; // loop all entries in dir for (int i = 0; i < dir.entryInfoList().count(); i++) { // get entry of this dir newinfo = dir.entryInfoList().at(i); // continue if entry is not a dir if (!newinfo.fileName().compare(".") || !newinfo.fileName().compare("..")) { continue; } // depending on this dir type choose what to do with the cuirrent entry switch (m_intNodeType) { case ROOT: if (newinfo.isDir()) { // create category child child = new WWidgetNode(CATEGORY, newinfo.absoluteFilePath(), count, this); childWWidgetNodes.append(child); count++; } break; case CATEGORY: if (newinfo.isDir()) { list = QDir(newinfo.absoluteFilePath()).entryInfoList(); for (int j = 0; j < list.count(); j++) { // check if selected child dir contains a project file if (list.at(j).filePath().contains(".wtw")) { // create widget child child = new WWidgetNode(WIDGET, newinfo.absoluteFilePath(), count, this); // discirminate some widgets (do not add to WWidgetNode tree but yes to QObject tree) QString strName = child->getName(); if (strName.compare("WTabItem" ) != 0 && strName.compare("WMenuItem" ) != 0 && strName.compare("WPopupItem") != 0) { // append to list of widgets childWWidgetNodes.append(child); count++; } } } } break; case WIDGET: if (newinfo.isFile() && newinfo.fileName().contains(".wtw")) { m_strName = newinfo.baseName(); // must be class name QFile file(newinfo.absoluteFilePath()); if (!file.open(QFile::ReadOnly)) { qDebug() << "[ERROR] Opening file in WWidgetNode::setupNodeChildren : " << newinfo.absoluteFilePath(); } m_byteConfig = file.readAll(); } else if (newinfo.isDir() && QDir(newinfo.absoluteFilePath()).dirName().compare("icon", Qt::CaseInsensitive) == 0) { list = QDir(newinfo.absoluteFilePath()).entryInfoList(); for (int j = 0; j < list.count(); j++) { // check if selected child is icon file if (list.at(j).baseName().compare(dir.dirName()) == 0) { // get icon m_icon = QIcon(list.at(j).absoluteFilePath()); } } } break; default: break; } } if (m_intNodeType == WIDGET) { m_mapIconByClassName.insert(m_strName, m_icon); } // set name for category if (m_intNodeType == CATEGORY && count > 0) { m_strName = dir.dirName(); } // just in case updateRowNumbers(); }