void AddShape::performAction(Block* block) const { Node* node = static_cast<Node*>(block); GenerateShape dialog(_generator, PantinEngine::MainWindow()); if(dialog.createShape()) { K_ASSERT( node->instance()->fastInherits<Model>() ); // The instance HAS to be a model in Nigel. Only models can contain geometry. Model* model = static_cast<Model*>(node->instance()); QUndoStack* undoStack = PantinEngine::InstanceUndoStack( model ); undoStack->setActive(true); undoStack->beginMacro( tr("Adding new %1 to node %2") .arg(_generator->shape()->blockName(), node->blockName()) ); AddBlock* addGeometry = new AddBlock(model->geometries(), dialog.geometry()); undoStack->push(addGeometry); AddBlock* addReference = new AddBlock(node, dialog.geometryInstance()); undoStack->push(addReference); undoStack->endMacro(); } }
void tst_QUndoGroup::addStackAndDie() { // Test that QUndoStack doesn't keep a reference to QUndoGroup after the // group is deleted. QUndoStack *stack = new QUndoStack; QUndoGroup *group = new QUndoGroup; group->addStack(stack); delete group; stack->setActive(true); delete stack; }
void ProjectAddModel::performAction(Block* block) const { K_ASSERT( block->fastInherits<Project>() ) // It has to be a Project ! Project* project = static_cast<Project*>(block); bool nameOk; QString name = QInputDialog::getText( GooeyEngine::MainWindow(), tr("Add Model"), tr("Please enter a name for the new Model"), QLineEdit::Normal, tr("New Model"), &nameOk ); if(!nameOk) { // User canceled ! return; } if(name.isEmpty()) { QMessageBox::warning( GooeyEngine::MainWindow(), tr("Add Model"), tr("Invalid Model name !") ); return; } // Create a new model in the project ! Model* model = project->createModel(name); // Retrieve the undo stack for the project. QUndoStack* stack = PantinEngine::InstanceUndoStack(project); K_ASSERT( stack ) stack->setActive(true); Pantin::commands::ProjectAddModel* add = new Pantin::commands::ProjectAddModel(project, model); stack->push(add); }
void LoadObjectsProgressPage::ended(kint status) { _ended = status; // Add all data to the project Project* project = static_cast<Project*>(PantinEngine::ActiveManager()->rootInstance()); QFileInfo info(((FileImporterWizard*)wizard())->file()->fileName()); // Create a model within the project Nigel::project::Model* model = project->createModel(info.baseName()); model->blockName(info.baseName()); QList<Geometry*> geometries = _tasklet->geometries(); for(kint i=0; i<geometries.size(); i++) { model->geometries()->addBlock(geometries.at(i)); } QList<Node*> sceneNodes = _tasklet->sceneNodes(); Node* rootNode = model->scene()->visualSceneInstance()->instantiatedElement()->node(0); for(kint i=0; i<sceneNodes.size(); i++) { rootNode->addBlock(sceneNodes.at(i)); } // Save the model to disk model->manager()->saveInstance(model); // Add a reference to the project ProjectAddModel* add = new ProjectAddModel(project, model); QUndoStack* stack = PantinEngine::InstanceUndoStack(project); stack->setActive(true); stack->push(add); emit completeChanged(); }