bool REntity::setProperty(RPropertyTypeId propertyTypeId, const QVariant& value, RTransaction* transaction) { bool ret = RObject::setProperty(propertyTypeId, value, transaction); if (propertyTypeId == PropertyBlock) { ret = ret || RObject::setMember(getData().blockId, value.toInt(), true); } else if (propertyTypeId == PropertyLayer) { if (value.type() == QVariant::Int || value.type() == QVariant::LongLong) { ret = ret || RObject::setMember(getData().layerId, value.toInt(), true); } else if (value.type() == QVariant::String) { RDocument* document = getData().getDocument(); if (document != NULL) { ret = ret || RObject::setMember(getData().layerId, document->getLayerId(value.toString()), true); } } } else if (propertyTypeId == PropertyLinetype) { if (value.type() == QVariant::Int || value.type() == QVariant::LongLong) { ret = ret || RObject::setMember(getData().linetypeId, value.toInt(), true); } else { RDocument* document = getData().getDocument(); if (document != NULL) { RLinetypePattern t = value.value<RLinetypePattern> (); int id = document->getLinetypeId(t.getName()); ret = ret || RObject::setMember(getData().linetypeId, id, true); } } } else if (propertyTypeId == PropertyLinetypeScale) { ret = ret || RObject::setMember(getData().linetypeScale, value.toDouble(), true); } else if (propertyTypeId == PropertyLineweight) { if (value.type()==QVariant::Int || value.type()==QVariant::Double) { ret = ret || RObject::setMember((int&)getData().lineweight, value.value<int>(), true); } else { ret = ret || RObject::setMember((int&)getData().lineweight, (int)value.value<RLineweight::Lineweight>(), true); } } else if (propertyTypeId == PropertyColor) { ret = ret || RObject::setMember(getData().color, value, true); } else if (propertyTypeId == PropertyDrawOrder) { ret = ret || RObject::setMember(getData().drawOrder, value, true); } return ret; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { resize(800, 600); // init script handler for ECMAScript: RScriptHandlerRegistry::registerScriptHandler( RScriptHandlerEcma::factory, RScriptHandlerEcma::getSupportedFileExtensionsStatic() ); RScriptHandlerEcma* handler = dynamic_cast<RScriptHandlerEcma*>(RScriptHandlerRegistry::getGlobalScriptHandler("js")); // create central widget from UI file: // this widget contains a child called 'Viewport00'. This child // widget will be filled with our graphics display with scroll // bars, etc. QFile file("support/examples/mainwindow/MyDisplay.ui"); file.open(QIODevice::ReadOnly); QUiLoader loader; QWidget* widget = loader.load(&file, this); file.close(); setCentralWidget(widget); // create drawing document with document interface: RMemoryStorage* storage = new RMemoryStorage(); RSpatialIndexNavel* spatialIndex = new RSpatialIndexNavel(); RDocument* document = new RDocument(*storage, *spatialIndex); documentInterface = new RDocumentInterface(*document); // import a DXF file into the drawing: documentInterface->importFile("support/examples/mainwindow/drawing_file_to_display.dxf"); // operation used to add various objects: RAddObjectOperation* op; // add a layer 'MyLayer': QSharedPointer<RLayer> layer = QSharedPointer<RLayer>( new RLayer(document, "MyLayer") ); layer->setLinetypeId(document->getLinetypeId("continuous")); op = new RAddObjectOperation(layer); documentInterface->applyOperation(op); RLayer::Id layerId = layer->getId(); // create and add a line entity: QSharedPointer<RLineEntity> lineEntity = QSharedPointer<RLineEntity>( new RLineEntity(document, RLineData(RVector(0,0), RVector(100,0))) ); // set attributes: lineEntity->setLayerId(layerId); lineEntity->setColor(RColor(0,128,255)); lineEntity->setLinetypeId(document->getLinetypeId("dashed")); lineEntity->setLineweight(RLineweight::Weight100); // set a custom property: lineEntity->setCustomProperty("MyIntProperty", 77); lineEntity->setCustomProperty("MyStringProperty", "Some text"); op = new RAddObjectOperation( lineEntity, false // false: don't use current attributes but // custom attributes set above ); // add the line entity to the drawing: documentInterface->applyOperation(op); // make 'widget' and 'documentInterface' available for the script engine: QScriptEngine& engine = handler->getScriptEngine(); QScriptValue globalObject = engine.globalObject(); globalObject.setProperty("widget", engine.newQObject(widget)); globalObject.setProperty("documentInterface", qScriptValueFromValue(&engine, documentInterface)); // call script to initialize viewport (add scroll bars, rulers, etc.): handler->doScript("support/examples/mainwindow/init_viewport.js"); }