bool QAbstractDiagramGraphicsItem::setProperty(const QString & name, const QVariant & value) { if (diagram() && diagram()->layers()->isLocked(this)){ return false; } QDiagramMetaProperty metaProperty = m_metadata->property(m_metadata->indexOfProperty(name)); // Check if property is dynamic if (!metaProperty.isValid()){ QVariant currentValue = m_dynamicProperties.value(name); QVariant newValue = itemPropertyChange(name, value); addDynamicProperty(name, newValue); if (currentValue != newValue){ QAbstractDiagram* d = diagram(); if (d && !m_blockUndoCommands){ d->undoStack()->push(new QDiagramChangePropertyCommand(d, (QDiagramShape*)this, name, currentValue, newValue)); } } return false; } if (metaProperty.isReadOnly()){ // Property is read only return false; } QVariant currentValue = m_properties.value(name); QVariant newValue = itemPropertyChange(name, QDiagramProperty::fromVariant(metaProperty.type(), value)); if (currentValue != newValue){ QAbstractDiagram* d = diagram(); if (d && !m_blockUndoCommands){ d->undoStack()->push(new QDiagramChangePropertyCommand(d, (QDiagramShape*)this, name, currentValue, newValue)); return true; } } return false; }
QColor QAbstractDiagramGraphicsItem::selectionColor() const { if (diagram() !=0){ return diagram()->selectionColor(); } return QColor(Qt::magenta); }
void QAbstractDiagramGraphicsItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { QMenu menu; if (!isSelected()){ setSelected(true); } if (!m_actions.isEmpty()){ menu.addActions(m_actions); menu.addSeparator(); } if (diagram() != 0){ menu.addActions(diagram()->standardItemContextMenuActions()); } menu.exec(event->screenPos()); }
void UndoDiagramModuleAddFn(void *info) { UndoDiagramModuleAdd *undoInfo = (UndoDiagramModuleAdd *)info; CDiagram diagram(undoInfo->mpDiagramNode); ScriptNode *node = undoInfo->mpNode; CModule module(node); diagram.deleteModule(&module); }
QVariant QAbstractDiagramGraphicsItem::itemPositionChange(const QVariant & value) { QPointF p = value.toPointF(); if (p.x() < 0){ p.setX(0); } if (p.y() <0){ p.setY(0); } if (diagram()){ if (diagram()->layers()->isLocked(this)){ return pos(); } if (diagram()->isSnapEnabled()){ p = diagram()->snapPos(p); } } return p; }
QVariant QAbstractDiagramGraphicsItem::propertyValue(int index) const { QDiagramMetaProperty m = m_metadata->property(index); QVariant v; if (m.isValid()){ v = m_properties.value(m.name()); if (v.isNull()){ QAbstractDiagram* d = diagram(); if (d){ return d->defaultValue(m.type()); } else { return QDiagramProperty::defaultValue(m.type()); } } } return v; }
void UndoDiagramModuleDeleteActionFn(void *info) { UndoDiagramModuleDelete *dmInfo = (UndoDiagramModuleDelete *)info; TransformNode *diagramNode = dmInfo->mpDiagramNode; ScriptNode *moduleNode = dmInfo->mpNode; CDiagram diagram(diagramNode); CModule module(moduleNode); diagram.addModule(&module); if (0 < dmInfo->mnRouteInfo) { for (int n=0; n<dmInfo->mnRouteInfo; n++) { RouteInfo *routeInfo = &dmInfo->maRouteInfo[n]; GetWorld()->getSceneGraph()->addRoute(routeInfo->mOutNode, routeInfo->mOutField, routeInfo->mInNode, routeInfo->mInField); } } if (dmInfo->maRouteInfo) delete dmInfo->maRouteInfo; }
void QSysMLAction::paint(QPainter* painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); painter->save(); painter->setPen(diagram()->styleSheet()->lineStyle("ControlFlowLineStyle").pen()); painter->drawPath(shapeConnectionLines()); painter->restore(); painter->save(); QBrush b = qdiagramproperty_cast<QBrush>(property("background")); painter->setBrush(b); painter->setPen(qdiagramproperty_cast<QPen>(property("lineStyle"))); painter->drawPath(shapeInternal()); painter->restore(); paintFocus(painter, option, widget); }
void Process(StrLen file_name) { SplitPath dev_name(file_name); SplitName path_name(dev_name.path); SplitExt name_ext(path_name.name); String in_name; if( !name_ext ) { in_name=StringCat(dev_name.dev,path_name.path,name_ext.name,".lang"); } else { in_name=file_name; } TrackStage("Load file #.q;",StrLen(Range(in_name))); CondLang clang(Range(in_name)); TrackStage("Build top lang"); TopLang top(clang); TrackStage("Run good test on top lang"); if( !RunGoodTest(top) ) return; TrackStage("Build bottom lang"); BottomLang bottom(clang); TrackStage("Extend bottom lang"); ExtLang ext_bottom(bottom); TrackStage("Process top lang"); ExtLang ext_top(top); LangDiagram diagram(ext_top); LangStateMachine<LR1Estimate,LR1MapContext> machine(ext_top,diagram,ext_bottom); StateCompress<LR1Estimate> compress(machine); TrackStage("LR1) #;",PrintCompressCounts(compress)); { ulen conflicts=0; for(auto &est : compress.getProps() ) conflicts+=est.hasConflict(); if( conflicts ) { String out_name=StringCat(dev_name.dev,path_name.path,name_ext.name,".bad.txt"); PrintFile out(Range(out_name)); Putobj(out,clang); PrintBad(out,ext_top,compress); Printf(Exception,"#; CONFLICTs detected. Not LR1 language.",conflicts); } else { TrackStage("No conflicts. LR1 language."); } } StateCompress<LR1Estimate,LR1PropNonEmpty> compress_ne(machine); TrackStage("NonEmpty) #;",PrintCompressCounts(compress_ne)); #if 0 StateCompress<LR1Estimate,LR1PropShiftSet> compress_shift(machine); TrackStage("Shift) #;",PrintCompressCounts(compress_shift)); StateCompress<LR1Estimate,LR1PropValidSet> compress_valid(machine); TrackStage("Valid) #;",PrintCompressCounts(compress_valid)); StateCompress<LR1Estimate,LR1PropRuleSet> compress_rules(machine); TrackStage("Rules) #;",PrintCompressCounts(compress_rules)); StateMap map(compress,compress_ne); String out_name=StringCat(dev_name.dev,path_name.path,"Result.txt"); PrintFile out(Range(out_name)); PrintFibres(out,compress,compress_ne,map); Putobj(out,BindOpt(ext_top,compress_ne)); #endif { String out_name=StringCat(dev_name.dev,path_name.path,name_ext.name,".txt"); PrintFile out(Range(out_name)); Putobj(out,clang); Putobj(out,BindOpt(ext_top,compress)); } { String out_name=StringCat(dev_name.dev,path_name.path,name_ext.name,".ddl"); PosPrint<PrintFile> out(Range(out_name)); Printf(out,"/* #;.ddl */\n\n",name_ext.name); Putobj(out,"//include <LangTypes.ddl>\n\n"); Putobj(out,"Lang lang=\n"); // lang { ListPrint<decltype(out)> lang_out(out); // atoms { ListPrint<decltype(lang_out)> atom_out(lang_out); for(auto &atom : clang.getAtoms() ) Printf(atom_out,"{ #; , #; , lang.elements+#; }#;",atom.index,StrLen(atom.name.inner(2,1)),atom.index,EndItem()); Putobj(atom_out,EndList()); } Putobj(lang_out,EndItem()); // synts { ListPrint<decltype(lang_out)> synt_out(lang_out); ulen element=clang.getAtomCount(); ulen top_index=0; for(auto &synt : clang.getSynts() ) { Printf(synt_out,"{ #; , #.q; ,",synt.index,synt.name); auto kinds=synt.kinds; if( !kinds ) { Indent indent(synt_out.getCol()); Printf(synt_out," { { #; , 0 , \"\" , lang.synts+#; , lang.elements+#; ,#;",top_index,synt.index,element++,AutoIndent()); auto &top_synt=top.getSynts()[top_index++]; ListPrint<decltype(synt_out)> rule_out(synt_out); for(auto &top_rule : top_synt.rules ) Printf(rule_out,"lang.top_rules+#;#;",top_rule.index,EndItem()); Putobj(rule_out,EndList()); Printf(synt_out,"#; }#; } ,#;",indent,indent,indent); } else { Indent indent(synt_out.getCol()); Putobj(synt_out,indent); ListPrint<decltype(synt_out)> kind_out(synt_out); for(auto &kind : kinds ) { Printf(kind_out,"{ #; , #; , #.q; , lang.synts+#; , lang.elements+#; ,#;",top_index,kind.index,kind.name,synt.index,element++,AutoIndent()); auto &top_synt=top.getSynts()[top_index++]; ListPrint<decltype(kind_out)> rule_out(kind_out); for(auto &top_rule : top_synt.rules ) Printf(rule_out,"lang.top_rules+#;#;",top_rule.index,EndItem()); Putobj(rule_out,EndList()); Printf(kind_out,"\n}#;",EndItem()); } Putobj(kind_out,EndList()); Putobj(synt_out," ,",indent); } ListPrint<decltype(synt_out)> rule_out(synt_out); for(auto &rule : synt.rules ) Printf(rule_out,"lang.rules+#;#;",rule.index,EndItem()); Putobj(rule_out,EndList()); Putobj(synt_out,"\n}",EndItem()); } Putobj(synt_out,EndList()); } Putobj(lang_out,EndItem()); // lang { ListPrint<decltype(lang_out)> synt_out(lang_out); for(auto &synt : clang.getSynts() ) if( synt.is_lang ) { Printf(synt_out,"lang.synts+#;",synt.index); } Putobj(synt_out,EndList()); } Putobj(lang_out,EndItem()); // elements { ListPrint<decltype(lang_out)> elem_out(lang_out); ulen element=0; for(auto &atom : clang.getAtoms() ) Printf(elem_out,"{ #; , lang.atoms+#; }#;",element++,atom.index,EndItem()); for(auto &synt : clang.getSynts() ) { auto len=synt.kinds.len; if( !len ) len=1; for(ulen i=0; i<len ;i++) { Printf(elem_out,"{ #; , lang.synts[#;].kinds+#; }#;",element++,synt.index,i,EndItem()); } } Putobj(elem_out,EndList()); } Putobj(lang_out,EndItem()); // rules { ListPrint<decltype(lang_out)> rule_out(lang_out); for(auto &rule : clang.getRules() ) { Printf(rule_out,"{ #; , #.q; , lang.synts[#;].kinds+#; ,#;",rule.index,rule.name,rule.ret->index,rule.getKindIndex(),AutoIndent()); ListPrint<decltype(rule_out)> arg_out(rule_out); for(auto &element : rule.args ) element.apply( [&] (const CondLangBase::AtomDesc *desc) { Printf(arg_out,"lang.atoms+#;#;",desc->index,EndItem()); } , [&] (const CondLangBase::SyntDesc *desc) { Printf(arg_out,"lang.synts+#;#;",desc->index,EndItem()); } ); Putobj(arg_out,EndList()); Putobj(rule_out,"\n}",EndItem()); } Putobj(rule_out,EndList()); } Putobj(lang_out,EndItem()); // top rules { ListPrint<decltype(lang_out)> rule_out(lang_out); for(auto &rule : top.getRules() ) { Printf(rule_out,"{ #; , #.q; , lang.rules+#; , lang.synts[#;].kinds+#; ,#;", rule.index,rule.name,rule.map_index,rule.ret->map_index,rule.ret->kind_index,AutoIndent()); ListPrint<decltype(rule_out)> arg_out(rule_out); for(auto &element : rule.args ) element.apply( [&] (const LangBase::AtomDesc *desc) { Printf(arg_out,"lang.atoms+#;#;",desc->index,EndItem()); } , [&] (const LangBase::SyntDesc *desc) { Printf(arg_out,"lang.synts[#;].kinds+#;#;",desc->map_index,desc->kind_index,EndItem()); } ); Putobj(arg_out,EndList()); Putobj(rule_out,"\n}",EndItem()); } Putobj(rule_out,EndList()); } Putobj(lang_out,EndItem()); // states { ListPrint<decltype(lang_out)> state_out(lang_out); for(auto &state : compress.getStateTable() ) { Printf(state_out,"{ #; , lang.finals+#; ,#;",state.index,state.prop_index,AutoIndent()); ListPrint<decltype(state_out)> trans_out(state_out); for(auto &trans : state.transitions ) Printf(trans_out,"{ lang.elements+#; , lang.states+#; }#;",trans.element,trans.dst->index,EndItem()); Putobj(trans_out,EndList()); Putobj(state_out,"\n}",EndItem()); } Putobj(state_out,EndList()); } Putobj(lang_out,EndItem()); // finals { ListPrint<decltype(lang_out)> final_out(lang_out); ulen atom_count=clang.getAtomCount(); ulen index=0; for(auto &final : compress.getProps() ) { Printf(final_out,"{ #; ,#;",index++,AutoIndent()); ListPrint<decltype(final_out)> action_out(final_out); if( final.hasNull() ) { Printf(action_out,"{ null , null }#;",EndItem()); } else { auto &alpha=final.getAlpha(); if( alpha.nonEmpty() ) { Printf(action_out,"{ null , lang.rules+#; }#;",alpha.getPtr()->getIndex()-atom_count,EndItem()); } } for(auto &rec : Range(final.getBeta()) ) { if( rec.object.shift ) { Printf(action_out,"{ lang.atoms+#; , null }#;",rec.index.getIndex(),EndItem()); } else { auto &rules=rec.object.rules; if( rules.nonEmpty() ) { Printf(action_out,"{ lang.atoms+#; , lang.rules+#; }#;",rec.index.getIndex(),rules.getPtr()->getIndex()-atom_count,EndItem()); } } } Putobj(action_out,EndList()); Putobj(final_out,"\n}",EndItem()); } Putobj(final_out,EndList()); } Putobj(lang_out,EndItem(),EndList()); } Putobj(out,";\n\n"); }
MDiagram *DiagramsView::diagram(int tabIndex) const { DiagramView *diagramView = dynamic_cast<DiagramView *>(widget(tabIndex)); return diagram(diagramView); }
void DiagramsView::onTabCloseRequested(int tabIndex) { emit diagramCloseRequested(diagram(tabIndex)); }
void DiagramsView::onCurrentChanged(int tabIndex) { emit currentDiagramChanged(diagram(tabIndex)); }
void MainWindow::on_actionShow_Diagram_triggered() { Diagram diagram(m_model); diagram.setModal(true); diagram.exec(); }
void SummaryPage::showDiagram() { ConnectionDiagram diagram(this, getWizard()); diagram.exec(); }