//Det borde vara möjligt att titta på stylen för att avgöra om en //cell är en grupp cell. Då borde det gå att kopiera in underceller //också. // // Kontrollera på stylen hur cellerna ska kopieras. Speciellt ska // gruppceller specialbehandlas så att deras subceller också // kopieras. Just nu funkar det att kopiera enstaka celler. Men // inte gruppceller. void PasteCellsCommand::execute() { try { vector<Cell *> cells = application()->pasteboard(); // Insert new cells before this position. if(!cells.empty()) { //Reverse iterator!!!!! //vector<Cell *>::reverse_iterator i = cells.rbegin(); //for(;i != cells.rend();++i) // AF, Not reverse vector<Cell *>::iterator i = cells.begin(); for(;i != cells.end();++i) { try { pasteCell( (*i) ); } catch(exception &e) { throw e; } } } //2006-01-18 AF, set docuement changed document()->setChanged( true ); } catch(exception &e) { // 2006-01-30 AF, add exception string str = string("PasteCellsCommand(), Exception: \n") + e.what(); throw runtime_error( str.c_str() ); } }
/** * Class constructor. */ DatasetEditWidget::DatasetEditWidget(QWidget *parent): QWidget(parent), ui(new Ui::DatasetEditWidget), model(NULL), contextMenu(NULL) { //autogenerated stuff ui->setupUi(this); //connects signals and slots connect(ui->tableView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu())); connect(ui->patternCountBox, SIGNAL(valueChanged(int)), this, SLOT(changePatternCount(int))); connect(ui->inputCountBox, SIGNAL(valueChanged(int)), this, SLOT(changeInputCount(int))); connect(ui->outputCountBox, SIGNAL(valueChanged(int)), this, SLOT(changeOutputCount(int))); connect(ui->closeButton, SIGNAL(pressed()), this, SLOT(closeBtnPressed())); //context menu of editor contextMenu = new QMenu(this); contextMenu->addAction(tr("Cut"), this, SLOT(cutCell()), Qt::CTRL | Qt::Key_X); contextMenu->addAction(tr("Copy"), this, SLOT(copyCell()), Qt::CTRL | Qt::Key_C); contextMenu->addAction(tr("Paste"), this, SLOT(pasteCell()), Qt::CTRL | Qt::Key_V); contextMenu->addAction(tr("Delete"), this, SLOT(deleteCell()), Qt::Key_Delete); this->addActions(contextMenu->actions()); }
// 2006-01-16 AF, move this code to a seperated function // 2006-09-04 AF, redid entire function, so groupcells are created, have there // children added and THEN add to the documnet void PasteCellsCommand::pasteCell( Cell *cell, CellGroup *groupcell ) { // get cursor, factory and cell style CellCursor *cursor = document()->getCursor(); Factory *factory = document()->cellFactory(); CellStyle style = *cell->style(); // set focus and readonly stuff (from old implementation, IA) if(cursor->currentCell()->isClosed()) { if(cursor->currentCell()->hasChilds()) { cursor->currentCell()->child()->setReadOnly(true); cursor->currentCell()->child()->setFocus(false); } } else { cursor->currentCell()->setReadOnly(true); cursor->currentCell()->setFocus(false); } // create the new cell, if there exists a groupcell add the new cell to // that groupcell. Cell* newCell = factory->createCell( style.name() ); // if( groupcell ) // groupcell->addChild( newCell ); // set content of cell // ************************************************************************* // COPY - EVERY CELL TYPE // ---------------------- newCell->setCellTag( cell->cellTag() ); // rules rules_t rules = cell->rules(); rules_t::iterator current = rules.begin(); while( current != rules.end() ) { newCell->addRule( (*current) ); ++current; } // COPY - SPECIFIC FOR CELL TYPE // ----------------------------- if( typeid(CellGroup) == typeid( *newCell )) { CellGroup *newCellGroup = dynamic_cast<CellGroup *>( newCell ); newCellGroup->setClosed( cell->isClosed() ); if( cell->hasChilds() ) { Cell* child = cell->child(); while( child ) { pasteCell( child, newCellGroup ); child = child->next(); } } } else if( typeid(InputCell) == typeid( *newCell )) { InputCell *newInputCell = dynamic_cast<InputCell *>( newCell ); InputCell *oldInputCell = dynamic_cast<InputCell *>( cell ); newInputCell->setStyle( style ); newInputCell->setText( oldInputCell->text() ); if( oldInputCell->isEvaluated() ) { newInputCell->setEvaluated( true ); newInputCell->setTextOutput( oldInputCell->textOutput() ); } else newInputCell->setEvaluated( false ); newInputCell->setClosed( oldInputCell->isClosed() ); } else if( typeid(GraphCell) == typeid( *newCell )) { GraphCell *newGraphCell = dynamic_cast<GraphCell *>( newCell ); GraphCell *oldGraphCell = dynamic_cast<GraphCell *>( cell ); newGraphCell->setStyle( style ); newGraphCell->setText( oldGraphCell->text() ); if( oldGraphCell->isEvaluated() ) { newGraphCell->setEvaluated( true ); newGraphCell->setTextOutput( oldGraphCell->textOutput() ); } else newGraphCell->setEvaluated( false ); newGraphCell->setClosed( oldGraphCell->isClosed() ); } else if( typeid(TextCell) == typeid( *newCell )) { newCell->setStyle( style ); newCell->setTextHtml( cell->textHtml() ); } else { // Error throw runtime_error("pasteCell(): Unknown celltype."); } // ************************************************************************* // Add cell to document if( !groupcell ) cursor->addBefore( newCell ); else //if there exists a groupcell add the new cell to that groupcell. groupcell->addChild( newCell ); // set focus and readonly stuff (from old implementation, IA) if(cursor->currentCell()->isClosed()) { if(cursor->currentCell()->hasChilds()) { cursor->currentCell()->child()->setReadOnly(false); cursor->currentCell()->child()->setFocus(true); } } else { cursor->currentCell()->setReadOnly(false); cursor->currentCell()->setFocus(true); } }