toonz/sources/toonz/cellselection.cpp
//-----------------------------------------------------------------------------
// special paste command - overwrite paste cell numbers only
special paste command - overwrite paste cell numbers only
special paste command - overwrite paste cell numbers only
void TCellSelection::overwritePasteNumbers() {
  int r0, c0, r1, c1;
  getSelectedCells(r0, c0, r1, c1);
  if (c0 < 0) c0 = 0;  
  QClipboard *clipboard     = QApplication::clipboard();
  const QMimeData *mimeData = clipboard->mimeData();
  TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet();
  if (const TCellData *cellData = dynamic_cast<const TCellData *>(mimeData)) {
    if (isEmpty()) return;
    if (cellData->getCellCount() == 0) {
      DVGui::error(QObject::tr("No data to paste."));
      return;
    }
    XsheetViewer *viewer = TApp::instance()->getCurrentXsheetViewer();
    if (viewer && !viewer->orientation()->isVerticalTimeline()) {
      int cAdj = cellData->getColCount() - 1;
      c0 -= cAdj;
      c1 -= cAdj;
    }
    int oldR0 = r0;
    int oldC0 = c0;
    int oldR1 = r1;
    int oldC1 = c1;
    if (!cellData->canChange(xsh, c0)) {
      DVGui::error(
          QObject::tr("It is not possible to paste the cells: "
                      "Some column is locked or column type is not match."));
      return;
    }
    int i;
    for (i = 0; i < cellData->getCellCount(); i++) {
      if (!xsh->checkCircularReferences(cellData->getCell(i))) continue;
      DVGui::error(
          QObject::tr("It is not possible to paste the cells: there is a "
                      "circular reference."));
      return;
    }
    r1 = r0 + cellData->getRowCount() - 1;
    if (cellData->getColCount() != 1 || c0 == c1)
      c1 = c0 + cellData->getColCount() - 1;
    TCellData *beforeData = new TCellData();
    beforeData->setCells(xsh, r0, c0, r1, c1);
    bool isPaste = pasteNumbersWithoutUndo(r0, c0, r1, c1);
    if (!isPaste) {
      delete beforeData;
      return;
    }
    TUndoManager::manager()->add(new OverwritePasteNumbersUndo(
        r0, c0, r1, c1, oldR0, oldC0, oldR1, oldC1, beforeData));
    TApp::instance()->getCurrentScene()->setDirtyFlag(true);
    delete beforeData;
  } else
    DVGui::error(QObject::tr("Cannot paste data \n Nothing to paste"));
  TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
}
void TCellSelection :: overwritePasteNumbers ( ) { int r0 , c0 , r1 , c1 ; getSelectedCells ( r0 , c0 , r1 , c1 ) ; if ( c0 < 0 ) c0 = 0 ; QClipboard * clipboard = QApplication :: clipboard ( ) ; const QMimeData * mimeData = clipboard -> mimeData ( ) ; TXsheet * xsh = TApp :: instance ( ) -> getCurrentXsheet ( ) -> getXsheet ( ) ; if ( const TCellData * cellData = dynamic_cast < const TCellData * > ( mimeData ) ) { if ( isEmpty ( ) ) return ; if ( cellData -> getCellCount ( ) == 0 ) { DVGui :: error ( QObject :: tr ( " " ) ) ; return ; } XsheetViewer * viewer = TApp :: instance ( ) -> getCurrentXsheetViewer ( ) ; if ( viewer && ! viewer -> orientation ( ) -> isVerticalTimeline ( ) ) { int cAdj = cellData -> getColCount ( ) - 1 ; c0 -= cAdj ; c1 -= cAdj ; } int oldR0 = r0 ; int oldC0 = c0 ; int oldR1 = r1 ; int oldC1 = c1 ; if ( ! cellData -> canChange ( xsh , c0 ) ) { DVGui :: error ( QObject :: tr ( " " " " ) ) ; return ; } int i ; for ( i = 0 ; i < cellData -> getCellCount ( ) ; i ++ ) { if ( ! xsh -> checkCircularReferences ( cellData -> getCell ( i ) ) ) continue ; DVGui :: error ( QObject :: tr ( " " " " ) ) ; return ; } r1 = r0 + cellData -> getRowCount ( ) - 1 ; if ( cellData -> getColCount ( ) != 1 || c0 == c1 ) c1 = c0 + cellData -> getColCount ( ) - 1 ; TCellData * beforeData = new TCellData ( ) ; beforeData -> setCells ( xsh , r0 , c0 , r1 , c1 ) ; bool isPaste = pasteNumbersWithoutUndo ( r0 , c0 , r1 , c1 ) ; if ( ! isPaste ) { delete beforeData ; return ; } TUndoManager :: manager ( ) -> add ( new OverwritePasteNumbersUndo ( r0 , c0 , r1 , c1 , oldR0 , oldC0 , oldR1 , oldC1 , beforeData ) ) ; TApp :: instance ( ) -> getCurrentScene ( ) -> setDirtyFlag ( true ) ; delete beforeData ; } else DVGui :: error ( QObject :: tr ( " \n " ) ) ; TApp :: instance ( ) -> getCurrentXsheet ( ) -> notifyXsheetChanged ( ) ; }
special paste command - overwrite paste cell numbers only
special paste command - overwrite paste cell numbers only
// Ignore camera column // Check if the copied cells are the same type as the target columns // Check Circular References // store celldata for undo // r0,c0,r1,c1 : pasted region  oldR0,oldC0,oldR1,oldC1 : selected area // before pasting