Beispiel #1
0
   void MakeGroupCellCommand::execute()
   {
      try
      {
   Factory *fac = document()->cellFactory();
   CellCursor *cursor = document()->getCursor();

   Cell *prev = cursor->currentCell();
   cursor->currentCell()->parentCell()->removeChild(prev);

   Cell *group = fac->createCell("cellgroup", cursor->parentCell());

   group->addChild(prev);
   cursor->addBefore(group);
   cursor->moveToLastChild(group);

   //2006-01-18 AF, set docuement changed
      document()->setChanged( true );
      }
      catch(exception &e)
      {
      // 2006-01-30 AF, add exception
      string str = string("MakeGroupCellCommand(), Exception: \n") + e.what();
    throw runtime_error( str.c_str() );

      }
   }
Beispiel #2
0
   /*!
    * \class CreateNewCellCommand
  * \author Ingemar Axelsson
    *
    * \brief Command for creating a new cell.
    */
   void CreateNewCellCommand::execute()
   {
      try
      {
   CellCursor *cursor = document()->getCursor();

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

   //This does not work.
   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);
   }

   cursor->addBefore(fac->createCell(style_));

   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);
   }

    //2006-01-18 AF, set docuement changed
    document()->setChanged( true );
      }
      catch(exception &e)
      {
      // 2006-01-30 AF, add exception
      string str = string("CreateNewCommand(), Exception: \n") + e.what();
      throw runtime_error( str.c_str() );
      }
   }
Beispiel #3
0
   /*!
    * \class AddCellCommand
  * \author Ingemar Axelsson and Anders Fernström
    *
    * \brief Command for adding a new cell to the cellstructure.
    */
  void AddCellCommand::execute()
  {
    try
    {
      CellCursor *cursor = document()->getCursor();

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

      // 2005-10-28 AF, changed style from QString to CellStyle
      CellStyle style;

      if(cursor->currentCell()->hasChilds())
        style = *cursor->currentCell()->child()->style();
      else
        style = *cursor->currentCell()->style();


      //This does not work.
      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);
      }

      // 2005-11-21 AF, Added check if the current cell is a
      // inputcell, set style to 'text' insted.
      // 2006-02-03 AF, added check if the current cell is a
      // groupcell
      if( style.name() == "input" || style.name() == "Input" || style.name() == "ModelicaInput" ||
        style.name() == "cellgroup" )
        cursor->addBefore(fac->createCell( "Text" ));
      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);
      }

      //2006-01-18 AF, set docuement changed
      document()->setChanged( true );
    }
    catch(exception &e)
    {
      // 2006-01-30 AF, add exception
      string str = string("AddCellCommand(), Exception: \n") + e.what();
      throw runtime_error( str.c_str() );
    }
  }
Beispiel #4
0
  // 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);
    }
  }