bool DomConvenience::variantToElement(const QVariant& v, QDomElement& e) { bool ok = true; clearAttributes(e); switch (v.type()) { case QVariant::String: e.setTagName("string"); e.setAttribute("value", v.toString().utf8()); break; case QVariant::CString: e.setTagName("string"); e.setAttribute("value", v.toCString()); break; case QVariant::Int: e.setTagName("int"); e.setAttribute("value", v.toInt()); break; case QVariant::UInt: e.setTagName("uint"); e.setAttribute("value", v.toUInt()); break; case QVariant::Double: e.setTagName("double"); e.setAttribute("value", v.toDouble()); break; case QVariant::Bool: e.setTagName("bool"); e.setAttribute("value", boolString(v.toBool())); break; case QVariant::Color: { e.setTagName("color"); QColor color = v.toColor(); e.setAttribute("red", color.red()); e.setAttribute("green", color.green()); e.setAttribute("blue", color.blue()); } break; case QVariant::Pen: { e.setTagName("pen"); QPen pen = v.toPen(); e.setAttribute("red", pen.color().red()); e.setAttribute("green", pen.color().green()); e.setAttribute("blue", pen.color().blue()); e.setAttribute("style", pen.style()); e.setAttribute("cap", pen.capStyle()); e.setAttribute("join", pen.joinStyle()); } break; case QVariant::Brush: { e.setTagName("brush"); QBrush brush = v.toBrush(); e.setAttribute("red", brush.color().red()); e.setAttribute("green", brush.color().green()); e.setAttribute("blue", brush.color().blue()); e.setAttribute("style", brush.style()); } break; case QVariant::Point: { e.setTagName("point"); QPoint point = v.toPoint(); e.setAttribute("x", point.x()); e.setAttribute("y", point.y()); } break; case QVariant::Rect: { e.setTagName("rect"); QRect rect = v.toRect(); e.setAttribute("x", rect.x()); e.setAttribute("y", rect.y()); e.setAttribute("width", rect.width()); e.setAttribute("height", rect.height()); } break; case QVariant::Size: { e.setTagName("size"); QSize qsize = v.toSize(); e.setAttribute("width", qsize.width()); e.setAttribute("height", qsize.height()); } break; case QVariant::Font: { e.setTagName("font"); QFont f(v.toFont()); e.setAttribute("family", f.family()); e.setAttribute("pointsize", f.pointSize()); e.setAttribute("bold", boolString(f.bold())); e.setAttribute("italic", boolString(f.italic())); e.setAttribute("underline", boolString(f.underline())); e.setAttribute("strikeout", boolString(f.strikeOut())); } break; case QVariant::SizePolicy: { e.setTagName("sizepolicy"); QSizePolicy sp(v.toSizePolicy()); e.setAttribute("hsizetype", sp.horData()); e.setAttribute("vsizetype", sp.verData()); #if (QT_VERSION >= 300) e.setAttribute("horstretch", sp.horStretch()); e.setAttribute("verstretch", sp.verStretch()); #endif } break; case QVariant::Cursor: e.setTagName("cursor"); e.setAttribute("shape", v.toCursor().shape()); break; case QVariant::StringList: { e.setTagName("stringlist"); uint j; QDomNode n; QDomNodeList stringNodeList = e.elementsByTagName("string"); QDomElement stringElem; QStringList stringList = v.toStringList(); QStringList::Iterator it = stringList.begin(); for (j = 0; ((j < stringNodeList.length()) && (it != stringList.end())); j++) { // get the current string element stringElem = stringNodeList.item(j).toElement(); // set it to the current string variantToElement(QVariant(*it), stringElem); // iterate to the next string ++it; } // more nodes in previous stringlist then current, remove excess nodes if (stringNodeList.count() > stringList.count()) { while (j < stringNodeList.count()) e.removeChild(stringNodeList.item(j).toElement()); } else if (j <stringList.count()) { while (it != stringList.end()) { // create a new element stringElem = m_doc.createElement("string"); // set it to the currentstring variantToElement(QVariant(*it), stringElem); // append it to the current element e.appendChild(stringElem); // iterate to the next string ++it; } } } break; #if QT_VERSION >= 300 case QVariant::KeySequence: e.setTagName("key"); e.setAttribute("sequence", (QString)v.toKeySequence()); break; #endif case QVariant::ByteArray: // this is only for [u]int64_t { e.setTagName("uint64"); QByteArray ba = v.toByteArray(); // make sure this only handles [u]int64_t's if (ba.size() != sizeof(uint64_t)) { qWarning("Don't know how to persist variant of type: %s (%d) (size=%d)!", v.typeName(), v.type(), ba.size()); ok = false; break; } // convert the data back into a uint64_t uint64_t num = *(uint64_t*)ba.data(); QChar buff[33]; QChar* p = &buff[32]; const char* digitSet = "0123456789abcdef"; int len = 0; // construct the string do { *--p = digitSet[((int)(num%16))]; num = num >> 4; // divide by 16 len++; } while ( num ); // store it in a QString QString storage; storage.setUnicode(p, len); // set the value e.setAttribute("value", storage); } break; #if 0 case QVariant::List: case QVaraint::Map: #endif default: qWarning("Don't know how to persist variant of type: %s (%d)!", v.typeName(), v.type()); ok = false; break; } return ok; }
void process(const QObject * obj){ if(obj != NULL){ QListViewItem * buf = __current; __current = new QListViewItem(__current,obj->className(),QString(obj->name())); __current->setPixmap(0,__pixgeom); QMetaObject* _m = obj->metaObject(); QListViewItem * att = NULL; if(_m != NULL){ QString _superclass(_m->superClassName()); if(!_superclass.isEmpty()){ att = new QListViewItem(__current,"Inherit",_superclass); att->setPixmap(0,__pixattptr); QMetaObject* _meta = _m->superClass(); QListViewItem * att4 = NULL; while((_meta = _meta->superClass())!= NULL){ att4 = new QListViewItem(att,att4,QString(_meta->className())); att4->setPixmap(0,__pixatt); } } att = new QListViewItem(__current,att,"Priority",(obj->highPriority()?"High":"Normal")); att->setPixmap(0,__pixatt); att = new QListViewItem(__current,att,"Widget",(obj->isWidgetType()?"True":"False")); att->setPixmap(0,__pixatt); QStrList _slots = _m->slotNames(true); if(!_slots.isEmpty()){ att = new QListViewItem(__current,att,"Slots"); att->setPixmap(0,__pixtransf); uint sl_size = _slots.count(); QListViewItem * att2 = NULL; for(uint j = 0; j < sl_size; j++ ){ att2 = new QListViewItem(att,att2,_slots.at(j)); att2->setPixmap(0,__pixatt); } } QStrList _signals = _m->signalNames(true); if(!_signals.isEmpty()){ att = new QListViewItem(__current,att,"Signals"); att->setPixmap(0,__pixtransf); uint si_size = _signals.count(); QListViewItem * att2 = NULL; for(uint j = 0; j < si_size; j++ ){ att2 = new QListViewItem(att,att2,_signals.at(j)); att2->setPixmap(0,__pixatt); } } int numCInfo = _m->numClassInfo(true); if(numCInfo !=0){ att = new QListViewItem(__current,att,"ClassInfo","List<Info>["+QString::number(numCInfo)+']'); att->setPixmap(0,__pixtransf); QListViewItem * att2 = NULL; for(int j = 0; j < numCInfo; j++ ){ const QClassInfo * _inf = _m->classInfo(j); if(_inf != NULL){ att2 = new QListViewItem(att,att2,QString(_inf->name),QString(_inf->value)); att2->setPixmap(0,__pixatt); } } } QStrList _props = _m->propertyNames(true); if(!_props.isEmpty()){ att = new QListViewItem(__current,att,"Properties"); att->setPixmap(0,__pixtransf); uint p_size = _props.count(); QListViewItem * att2 = NULL; for(uint j = 0; j < p_size; j++ ){ att2 = new QListViewItem(att,att2,_props.at(j)); att2->setPixmap(0,__pixatt); QVariant val; QString propname(_props.at(j)); #if QT_VERSION >= 300 const QMetaProperty* prop = _m->property (j,true); #else const QMetaProperty* prop = _m->property (propname,true); #endif QString proptype; if(prop){ proptype = prop->type(); att2->setText(2,proptype); /* QListViewItem * att3 = new QListViewItem(att2,"Writable",(prop->writable()?"True":"False")); att3->setPixmap(0,__pixatt); att3 = new QListViewItem(att2,att3,"Designable",(prop->designable()?"True":"False")); att3->setPixmap(0,__pixatt); */ } val = obj->property(propname); if(!val.isValid())att2->setText(1,"Invalid"); else if(prop->isEnumType()){ att2->setText(1,prop->valueToKey(val.toInt())); } else if(prop->isSetType()){ QStrList st = prop->valueToKeys(val.toInt()); QString t = st.at(0); for(uint i= 1; i < st.count(); i++)t+='/'+st.at(i); att2->setText(1,t); } else if(val.type() == QVariant::String)att2->setText(1,'"'+val.toString()+'"'); else if(val.type() == QVariant::CString)att2->setText(1,'"'+val.toCString()+'"'); else if(val.type() == QVariant::Bool){ if(val.toBool())att2->setText(1,"True"); else att2->setText(1,"False"); } else if(val.type() == QVariant::Int)att2->setText(1,QString::number(val.toInt())); else if(val.type() == QVariant::UInt)att2->setText(1,QString::number(val.toUInt())); else if(val.type() == QVariant::Double)att2->setText(1,QString::number(val.toDouble())); else if(val.type() == QVariant::Rect){ const QRect r = val.toRect(); att2->setText(1,'[' + QString::number(r.left()) + ',' + QString::number(r.top())+ ',' + QString::number(r.right()) + ',' + QString::number(r.bottom())+']'); } else if(val.type() == QVariant::Region){ const QRegion reg = val.toRegion(); QRect r = reg.boundingRect(); att2->setText(1,'[' + QString::number(r.left()) + ',' + QString::number(r.top())+ ',' + QString::number(r.right()) + ',' + QString::number(r.bottom())+"],"); } else if(val.type() == QVariant::Size){ const QSize s = val.toSize(); att2->setText(1,'[' + QString::number(s.width()) + ',' + QString::number(s.height())+']'); } else if(val.type() == QVariant::Point){ const QPoint p = val.toPoint(); att2->setText(1,'[' + QString::number(p.x()) + ',' + QString::number(p.y())+']'); } else if(val.type() == QVariant::Color){ const QColor c = val.toColor(); att2->setText(1,'[' + QString::number(c.red()) + ',' + QString::number(c.green()) + ',' + QString::number(c.blue()) + ']'); } else if(val.type() == QVariant::ColorGroup){ const QColorGroup cg = val.toColorGroup(); QColor c = cg.base(); att2->setText(1,'[' + QString::number(c.red()) + ',' + QString::number(c.green()) + ',' + QString::number(c.blue()) + "], ..."); } else if(val.type() == QVariant::Font){ const QFont f = val.toFont(); QString text = '\'' + f.family() + "', " + QString::number(f.pointSize()) + ", " + QString::number(f.weight()); if(f.italic())text+=", italic"; att2->setText(1,text); } else if(val.type() == QVariant::SizePolicy){ QSizePolicy sp = val.toSizePolicy(); QString text; if(sp.horData() == QSizePolicy::Fixed)text+="Fixed"; else if(sp.horData() == QSizePolicy::Minimum )text+="Minimum"; else if(sp.horData() == QSizePolicy::Maximum )text+="Maximum"; else if(sp.horData() == QSizePolicy::Preferred )text+="Preferred"; else if(sp.horData() == QSizePolicy::MinimumExpanding )text+="MinimumExpanding"; else if(sp.horData() == QSizePolicy::Expanding )text+="Expanding"; text +='/'; if(sp.verData() == QSizePolicy::Fixed)text+="Fixed"; else if(sp.verData() == QSizePolicy::Minimum )text+="Minimum"; else if(sp.verData() == QSizePolicy::Maximum )text+="Maximum"; else if(sp.verData() == QSizePolicy::Preferred )text+="Preferred"; else if(sp.verData() == QSizePolicy::MinimumExpanding )text+="MinimumExpanding"; else if(sp.verData() == QSizePolicy::Expanding )text+="Expanding"; att2->setText(1,text); } else if(val.type() == QVariant::Pixmap){ QPixmap pix = val.toPixmap(); if(!pix.isNull())att2->setPixmap(1,pix); } else if(val.type() == QVariant::Cursor){ const QCursor cur = val.toCursor(); const QBitmap * pix = cur.bitmap(); if(pix && !pix->isNull())att2->setPixmap(1,*pix); else att2->setText(1,QString::number(cur.shape())); } } } } const QObjectList * roots = obj->children(); if(roots != NULL){ __current = new QListViewItem(__current,att,"children","ptr="+QString::number((unsigned long)roots), "List<QObject>["+QString::number(roots->count())+"]"); __current->setPixmap(0,__pixappe); QObjectList r(*roots); uint size = r.count(); for(uint i = 0; i < size; i++ ){ QObject * _obj = r.at(i); process(_obj); } } __current = buf; } }
void CursorEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value) { ComboBox::drawViewer(p, cg, r, value.toCursor().shape()); }
bool DomConvenience::variantToElement(const QVariant& v, QDomElement& e) { bool ok = true; clearAttributes(e); switch (v.type()) { case QVariant::String: e.setTagName("string"); e.setAttribute("value", v.toString().utf8()); break; case QVariant::CString: e.setTagName("string"); e.setAttribute("value", v.toCString()); break; case QVariant::Int: e.setTagName("int"); e.setAttribute("value", v.toInt()); break; case QVariant::UInt: e.setTagName("uint"); e.setAttribute("value", v.toUInt()); break; case QVariant::Double: e.setTagName("double"); e.setAttribute("value", v.toDouble()); break; case QVariant::Bool: e.setTagName("bool"); e.setAttribute("value", boolString(v.toBool())); break; case QVariant::Color: { e.setTagName("color"); QColor color = v.toColor(); e.setAttribute("red", color.red()); e.setAttribute("green", color.green()); e.setAttribute("blue", color.blue()); } break; case QVariant::Point: { e.setTagName("point"); QPoint point = v.toPoint(); e.setAttribute("x", point.x()); e.setAttribute("y", point.y()); } break; case QVariant::Rect: { e.setTagName("rect"); QRect rect = v.toRect(); e.setAttribute("x", rect.x()); e.setAttribute("y", rect.y()); e.setAttribute("width", rect.width()); e.setAttribute("height", rect.height()); } break; case QVariant::Size: { e.setTagName("size"); QSize qsize = v.toSize(); e.setAttribute("width", qsize.width()); e.setAttribute("height", qsize.height()); } break; case QVariant::Font: { e.setTagName("font"); QFont f(v.toFont()); e.setAttribute("family", f.family()); e.setAttribute("pointsize", f.pointSize()); e.setAttribute("bold", boolString(f.bold())); e.setAttribute("italic", boolString(f.italic())); e.setAttribute("underline", boolString(f.underline())); e.setAttribute("strikeout", boolString(f.strikeOut())); } break; case QVariant::SizePolicy: { e.setTagName("sizepolicy"); QSizePolicy sp(v.toSizePolicy()); e.setAttribute("hsizetype", sp.horData()); e.setAttribute("vsizetype", sp.verData()); #if (QT_VERSION >= 300) e.setAttribute("horstretch", sp.horStretch()); e.setAttribute("verstretch", sp.verStretch()); #endif } break; case QVariant::Cursor: e.setTagName("cursor"); e.setAttribute("shape", v.toCursor().shape()); break; case QVariant::StringList: { e.setTagName("stringlist"); uint j; QDomNode n; QDomNodeList stringNodeList = e.elementsByTagName("string"); QDomElement stringElem; QStringList stringList = v.toStringList(); QStringList::Iterator it = stringList.begin(); for (j = 0; ((j < stringNodeList.length()) && (it != stringList.end())); j++) { // get the current string element stringElem = stringNodeList.item(j).toElement(); // set it to the current string variantToElement(QVariant(*it), stringElem); // iterate to the next string ++it; } // more nodes in previous stringlist then current, remove excess nodes if (stringNodeList.count() > stringList.count()) { while (j < stringNodeList.count()) e.removeChild(stringNodeList.item(j).toElement()); } else if (j <stringList.count()) { while (it != stringList.end()) { // create a new element stringElem = m_doc.createElement("string"); // set it to the currentstring variantToElement(QVariant(*it), stringElem); // append it to the current element e.appendChild(stringElem); // iterate to the next string ++it; } } } break; #if QT_VERSION >= 300 case QVariant::KeySequence: e.setTagName("key"); e.setAttribute("sequence", (QString)v.toKeySequence()); break; #endif #if 0 case QVariant::List: case QVaraint::Map: #endif default: qWarning("Don't know how to persist variant of type: %s (%d)!", v.typeName(), v.type()); ok = false; break; } return ok; }
void CursorEdit::setValue(const QVariant &value, bool emitChange) { ComboBox::setValue(value.toCursor().shape(), emitChange); }