Skip to content

Commit

Permalink
fixed bug in paste cell command. // Anders Fernström
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2513 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
x05andfe committed Sep 4, 2006
1 parent 7831d96 commit c5175a9
Showing 1 changed file with 63 additions and 73 deletions.
136 changes: 63 additions & 73 deletions OMNotebook/OMNotebookQT4/cellcommands.cpp
Expand Up @@ -334,17 +334,16 @@ namespace IAEX
}

// 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 current position.
// get cursor, factory and cell style
CellCursor *cursor = document()->getCursor();

Factory *fac = document()->cellFactory();

// 2005-10-28 AF, changed style from QString to CellStyle
Factory *factory = document()->cellFactory();
CellStyle style = *cell->style();

//Create a new cell.
// set focus and readonly stuff (from old implementation, IA)
if(cursor->currentCell()->isClosed())
{
if(cursor->currentCell()->hasChilds())
Expand All @@ -359,107 +358,98 @@ namespace IAEX
cursor->currentCell()->setFocus(false);
}

// 2006-01-16 AF, Added support so groupcell can be pasted.
// create the new cell, if there exists a groupcell add the new cell to
// that groupcell.
Cell* newCell = factory->createCell( style.name() );
if( groupcell )
{
// add child and move cursor to correct position
groupcell->addChild( fac->createCell( style.name() ));
cursor->moveAfter( groupcell->child() );
}
else
cursor->addBefore(fac->createCell(style.name()));

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);
}
groupcell->addChild( newCell );


//Copy its content.
//This is a problem!
// 2006-01-12/16 AF, Updated what is copied
// set content of cell
// *************************************************************************

//copy (every cell type)
cursor->currentCell()->setCellTag( cell->cellTag() );
// COPY - EVERY CELL TYPE
// ----------------------
newCell->setCellTag( cell->cellTag() );

// rules
rules_t rules = cell->rules();
rules_t::iterator current = rules.begin();
while( current != rules.end() )
{
cursor->currentCell()->addRule( (*current) );
newCell->addRule( (*current) );
++current;
}

// copy (specific for cell type)
if( typeid(CellGroup) == typeid( *cursor->currentCell() ))
// COPY - SPECIFIC FOR CELL TYPE
// -----------------------------
if( typeid(CellGroup) == typeid( *newCell ))
{
CellGroup *newCell = dynamic_cast<CellGroup *>(cursor->currentCell());

if( cell->isClosed() )
newCell->setClosed( true );
else
newCell->setClosed( false );
CellGroup *newCellGroup = dynamic_cast<CellGroup *>( newCell );
newCellGroup->setClosed( cell->isClosed() );

if( cell->hasChilds() )
{
//add first child
Cell *child = cell->child();
pasteCell( child, newCell );


// add rest of children
child = child->next();
while( child != 0 )
Cell* child = cell->child();
while( child )
{
pasteCell( child );
pasteCell( child, newCellGroup );
child = child->next();
}
}
}
else if( typeid(InputCell) == typeid( *cursor->currentCell() ))
else if( typeid(InputCell) == typeid( *newCell ))
{
InputCell *newCell = dynamic_cast<InputCell *>(cursor->currentCell());
InputCell *oldCell = dynamic_cast<InputCell *>( cell );
InputCell *newInputCell = dynamic_cast<InputCell *>( newCell );
InputCell *oldInputCell = dynamic_cast<InputCell *>( cell );

newCell->setStyle( style );
newCell->setText( oldCell->text() );
if( oldCell->isEvaluated() )
newInputCell->setStyle( style );
newInputCell->setText( oldInputCell->text() );

if( oldInputCell->isEvaluated() )
{
newCell->setEvaluated( true );
newInputCell->setEvaluated( true );

if( oldCell->isPlot() )
newCell->setTextOutputHtml( oldCell->textOutputHtml() );
if( oldInputCell->isPlot() )
newInputCell->setTextOutputHtml( oldInputCell->textOutputHtml() );
else
newCell->setTextOutput( oldCell->textOutput() );
newInputCell->setTextOutput( oldInputCell->textOutput() );
}
else
newCell->setEvaluated( false );

newInputCell->setEvaluated( false );

if( oldCell->isClosed() )
newCell->setClosed( true );
else
newCell->setClosed( false );
newInputCell->setClosed( oldInputCell->isClosed() );
}
else if( typeid(TextCell) == typeid( *cursor->currentCell() ))
else if( typeid(TextCell) == typeid( *newCell ))
{
cursor->currentCell()->setStyle( style );
cursor->currentCell()->setTextHtml( cell->textHtml() );
newCell->setStyle( style );
newCell->setTextHtml( cell->textHtml() );
}
else
{
// ERROR
throw runtime_error("Unknown cell");
// Error
throw runtime_error("pasteCell(): Unknown celltype.");
}
// *************************************************************************


// Add cell to document
if( !groupcell )
cursor->addBefore( 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);
}
}

Expand Down

0 comments on commit c5175a9

Please sign in to comment.