Spreadsheet changes
Various changes to support in-place editing, and more.
This commit is contained in:
@@ -26,11 +26,17 @@
|
||||
# include <QAction>
|
||||
# include <QApplication>
|
||||
# include <QClipboard>
|
||||
# include <QMessageBox>
|
||||
# include <QMimeData>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <boost/bind.hpp>
|
||||
#include "../App/Utils.h"
|
||||
#include "../App/Cell.h"
|
||||
#include <App/Range.h>
|
||||
#include "SheetTableView.h"
|
||||
#include "LineEdit.h"
|
||||
@@ -147,7 +153,7 @@ void SheetTableView::insertRows()
|
||||
break;
|
||||
}
|
||||
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.insertRows('%s', %d)", sheet->getNameInDocument(),
|
||||
FCMD_OBJ_CMD2("insertRows('%s', %d)", sheet,
|
||||
rowName(prev).c_str(), count);
|
||||
}
|
||||
Gui::Command::commitCommand();
|
||||
@@ -169,7 +175,7 @@ void SheetTableView::removeRows()
|
||||
/* Remove rows */
|
||||
Gui::Command::openCommand("Remove rows");
|
||||
for (std::vector<int>::const_iterator it = sortedRows.begin(); it != sortedRows.end(); ++it) {
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.removeRows('%s', %d)", sheet->getNameInDocument(),
|
||||
FCMD_OBJ_CMD2("removeRows('%s', %d)", sheet,
|
||||
rowName(*it).c_str(), 1);
|
||||
}
|
||||
Gui::Command::commitCommand();
|
||||
@@ -207,7 +213,7 @@ void SheetTableView::insertColumns()
|
||||
break;
|
||||
}
|
||||
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.insertColumns('%s', %d)", sheet->getNameInDocument(),
|
||||
FCMD_OBJ_CMD2("insertColumns('%s', %d)", sheet,
|
||||
columnName(prev).c_str(), count);
|
||||
}
|
||||
Gui::Command::commitCommand();
|
||||
@@ -229,7 +235,7 @@ void SheetTableView::removeColumns()
|
||||
/* Remove columns */
|
||||
Gui::Command::openCommand("Remove rows");
|
||||
for (std::vector<int>::const_iterator it = sortedColumns.begin(); it != sortedColumns.end(); ++it)
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.removeColumns('%s', %d)", sheet->getNameInDocument(),
|
||||
FCMD_OBJ_CMD2("removeColumns('%s', %d)", sheet,
|
||||
columnName(*it).c_str(), 1);
|
||||
Gui::Command::commitCommand();
|
||||
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
|
||||
@@ -405,6 +411,8 @@ void SheetTableView::deleteSelection()
|
||||
}
|
||||
}
|
||||
|
||||
static const QLatin1String _SheetMime("application/x-fc-spreadsheet");
|
||||
|
||||
void SheetTableView::copySelection()
|
||||
{
|
||||
QModelIndexList selection = selectionModel()->selectedIndexes();
|
||||
@@ -412,7 +420,6 @@ void SheetTableView::copySelection()
|
||||
int maxRow = 0;
|
||||
int minCol = INT_MAX;
|
||||
int maxCol = 0;
|
||||
|
||||
for (auto it : selection) {
|
||||
int row = it.row();
|
||||
int col = it.column();
|
||||
@@ -434,7 +441,13 @@ void SheetTableView::copySelection()
|
||||
if (i < maxRow)
|
||||
selectedText.append(QChar::fromLatin1('\n'));
|
||||
}
|
||||
QApplication::clipboard()->setText(selectedText);
|
||||
|
||||
Base::StringWriter writer;
|
||||
sheet->getCells()->copyCells(writer,selectedRanges());
|
||||
QMimeData *mime = new QMimeData();
|
||||
mime->setText(selectedText);
|
||||
mime->setData(_SheetMime,QByteArray(writer.getString().c_str()));
|
||||
QApplication::clipboard()->setMimeData(mime);
|
||||
}
|
||||
|
||||
void SheetTableView::cutSelection()
|
||||
@@ -445,20 +458,50 @@ void SheetTableView::cutSelection()
|
||||
|
||||
void SheetTableView::pasteClipboard()
|
||||
{
|
||||
QString text = QApplication::clipboard()->text();
|
||||
QStringList rows = text.split(QLatin1Char('\n'));
|
||||
const QMimeData* mimeData = QApplication::clipboard()->mimeData();
|
||||
if(!mimeData || !mimeData->hasText())
|
||||
return;
|
||||
|
||||
if(selectionModel()->selectedIndexes().size()>1) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Spreadsheet"),
|
||||
QObject::tr("Spreadsheet does not support range selection when pasting.\n"
|
||||
"Please select one cell only."));
|
||||
return;
|
||||
}
|
||||
|
||||
QModelIndex current = currentIndex();
|
||||
int i=0;
|
||||
for (auto it : rows) {
|
||||
QStringList cols = it.split(QLatin1Char('\t'));
|
||||
int j=0;
|
||||
for (auto jt : cols) {
|
||||
QModelIndex index = model()->index(current.row()+i, current.column()+j);
|
||||
model()->setData(index, jt);
|
||||
j++;
|
||||
|
||||
App::AutoTransaction committer("Paste cell");
|
||||
try {
|
||||
if (!mimeData->hasFormat(_SheetMime)) {
|
||||
QStringList cells;
|
||||
QString text = mimeData->text();
|
||||
int i=0;
|
||||
for (auto it : text.split(QLatin1Char('\n'))) {
|
||||
QStringList cols = it.split(QLatin1Char('\t'));
|
||||
int j=0;
|
||||
for (auto jt : cols) {
|
||||
QModelIndex index = model()->index(current.row()+i, current.column()+j);
|
||||
model()->setData(index, jt);
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}else{
|
||||
QByteArray res = mimeData->data(_SheetMime);
|
||||
Base::ByteArrayIStreambuf buf(res);
|
||||
std::istream in(0);
|
||||
in.rdbuf(&buf);
|
||||
Base::XMLReader reader("<memory>", in);
|
||||
sheet->getCells()->pasteCells(reader,CellAddress(current.row(),current.column()));
|
||||
}
|
||||
i++;
|
||||
|
||||
GetApplication().getActiveDocument()->recompute();
|
||||
|
||||
}catch(Base::Exception &e) {
|
||||
e.ReportException();
|
||||
QMessageBox::critical(Gui::getMainWindow(), QObject::tr("Copy & Paste failed"),
|
||||
QString::fromLatin1(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user