MCPcopy Create free account
hub / github.com/KDE/labplot / pasteIntoSelection

Method pasteIntoSelection

src/frontend/matrix/MatrixView.cpp:681–746  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

679}
680
681void MatrixView::pasteIntoSelection() {
682 if (m_matrix->columnCount() < 1 || m_matrix->rowCount() < 1)
683 return;
684
685 const QMimeData* mime_data = QApplication::clipboard()->mimeData();
686 if (!mime_data->hasFormat(QStringLiteral("text/plain")))
687 return;
688
689 WAIT_CURSOR;
690 m_matrix->beginMacro(i18n("%1: paste from clipboard", m_matrix->name()));
691
692 int first_col = firstSelectedColumn(false);
693 int last_col = lastSelectedColumn(false);
694 int first_row = firstSelectedRow(false);
695 int last_row = lastSelectedRow(false);
696 int input_row_count = 0;
697 int input_col_count = 0;
698 int rows, cols;
699
700 QString input_str = QLatin1String(mime_data->data(QStringLiteral("text/plain")));
701 QList<QStringList> cell_texts;
702 QStringList input_rows(input_str.split(QLatin1Char('\n')));
703 input_row_count = input_rows.count();
704 input_col_count = 0;
705 for (int i = 0; i < input_row_count; i++) {
706 cell_texts.append(input_rows.at(i).split(QLatin1Char('\t')));
707 if (cell_texts.at(i).count() > input_col_count)
708 input_col_count = cell_texts.at(i).count();
709 }
710
711 // if the is no selection or only one cell selected, the
712 // selection will be expanded to the needed size from the current cell
713 if ((first_col == -1 || first_row == -1) || (last_row == first_row && last_col == first_col)) {
714 int current_row, current_col;
715 getCurrentCell(&current_row, &current_col);
716 if (current_row == -1)
717 current_row = 0;
718 if (current_col == -1)
719 current_col = 0;
720 setCellSelected(current_row, current_col);
721 first_col = current_col;
722 first_row = current_row;
723 last_row = first_row + input_row_count - 1;
724 last_col = first_col + input_col_count - 1;
725 // resize the matrix if necessary
726 if (last_col >= m_matrix->columnCount())
727 m_matrix->appendColumns(last_col + 1 - m_matrix->columnCount());
728 if (last_row >= m_matrix->rowCount())
729 m_matrix->appendRows(last_row + 1 - m_matrix->rowCount());
730 // select the rectangle to be pasted in
731 setCellsSelected(first_row, first_col, last_row, last_col);
732 }
733
734 rows = last_row - first_row + 1;
735 cols = last_col - first_col + 1;
736 const auto numberLocale = QLocale();
737 for (int r = 0; r < rows && r < input_row_count; r++) {
738 for (int c = 0; c < cols && c < input_col_count; c++) {

Calls 12

beginMacroMethod · 0.80
splitMethod · 0.80
appendMethod · 0.80
endMacroMethod · 0.80
columnCountMethod · 0.45
rowCountMethod · 0.45
nameMethod · 0.45
dataMethod · 0.45
countMethod · 0.45
appendColumnsMethod · 0.45
appendRowsMethod · 0.45
setCellMethod · 0.45