[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    =?utf-8?q?=5Bkoffice=5D_libs/kotext=3A_Copying_Code_to_enable_un?=
From:       Ganesh Paramasivam <ganesh () crystalfab ! com>
Date:       2011-03-25 7:42:26
Message-ID: 20110325074226.28E0BA609B () git ! kde ! org
[Download RAW message or body]

Git commit 9e5c2978413ed9e25b7b6c7041b551d62953ec45 by Ganesh Paramasivam.
Committed on 25/03/2011 at 08:42.
Pushed by ganeshp into branch 'master'.

Copying Code to enable undo/redo of table editing actions authored by Casper Boemann

M  +5    -0    libs/kotext/CMakeLists.txt     
M  +19   -145  libs/kotext/KoTextEditor.cpp     
A  +90   -0    libs/kotext/commands/DeleteTableColumnCommand.cpp         [License: \
LGPL (v2+)] A  +50   -0    libs/kotext/commands/DeleteTableColumnCommand.h         \
[License: LGPL (v2+)] A  +89   -0    libs/kotext/commands/DeleteTableRowCommand.cpp   \
[License: LGPL (v2+)] A  +50   -0    libs/kotext/commands/DeleteTableRowCommand.h     \
[License: LGPL (v2+)] A  +87   -0    \
libs/kotext/commands/InsertTableColumnCommand.cpp         [License: LGPL (v2+)] A  \
+50   -0    libs/kotext/commands/InsertTableColumnCommand.h         [License: LGPL \
(v2+)] A  +89   -0    libs/kotext/commands/InsertTableRowCommand.cpp         \
[License: LGPL (v2+)] A  +50   -0    libs/kotext/commands/InsertTableRowCommand.h     \
[License: LGPL (v2+)]

http://commits.kde.org/koffice/9e5c2978413ed9e25b7b6c7041b551d62953ec45

diff --git a/libs/kotext/CMakeLists.txt b/libs/kotext/CMakeLists.txt
index dc0f06e..4f81b4c 100644
--- a/libs/kotext/CMakeLists.txt
+++ b/libs/kotext/CMakeLists.txt
@@ -83,6 +83,11 @@ set(kotext_LIB_SRCS
     changetracker/KoDeletedColumnData.cpp
     changetracker/KoDeletedCellData.cpp
     KoTextDrag.cpp
+
+    commands/DeleteTableRowCommand.cpp
+    commands/DeleteTableColumnCommand.cpp
+    commands/InsertTableRowCommand.cpp
+    commands/InsertTableColumnCommand.cpp
 )
 
 if( Soprano_FOUND )
diff --git a/libs/kotext/KoTextEditor.cpp b/libs/kotext/KoTextEditor.cpp
index 7ca5843..925943a 100644
--- a/libs/kotext/KoTextEditor.cpp
+++ b/libs/kotext/KoTextEditor.cpp
@@ -40,6 +40,10 @@
 #include "styles/KoTableColumnStyle.h"
 #include "styles/KoTableRowStyle.h"
 #include "KoTableColumnAndRowStyleManager.h"
+#include "commands/DeleteTableRowCommand.h"
+#include "commands/DeleteTableColumnCommand.h"
+#include "commands/InsertTableRowCommand.h"
+#include "commands/InsertTableColumnCommand.h"
 
 #include <KLocale>
 #include <KUndoStack>
@@ -991,217 +995,87 @@ void KoTextEditor::insertTable(int rows, int columns)
 
 void KoTextEditor::insertTableRowAbove()
 {
-    d->updateState(KoTextEditor::Private::Custom, i18n("Insert Row Above"));
-
     QTextTable *table = d->caret.currentTable();
-
     if (table) {
-        KoTableColumnAndRowStyleManager carsManager = \
                KoTableColumnAndRowStyleManager::getManager(table);
-        QTextTableCell cell = table->cellAt(d->caret);
-        int row = cell.row();
-        table->insertRows(row, 1);
-        carsManager.insertRows(row, 1, carsManager.rowStyle(row));
-    
+        int changeId = 0;
         KoChangeTracker *changeTracker = \
KoTextDocument(d->document).changeTracker();  if (changeTracker && \
                changeTracker->recordChanges()) {
-            int changeId;
             QString title(i18n("Insert Row Above"));
             changeId = changeTracker->getInsertChangeId(title, 0);
-            for (int i=0; i < table->columns(); i++) {
-                QTextTableCellFormat cellFormat = table->cellAt(row, \
                i).format().toTableCellFormat();
-                cellFormat.setProperty(KoCharacterStyle::ChangeTrackerId, changeId);
-                table->cellAt(row, i).setFormat(cellFormat);
-            }
         }
+        addCommand(new InsertTableRowCommand(this, table, false, changeId));
     }
-
-    d->updateState(KoTextEditor::Private::NoOp);
 }
 
 void KoTextEditor::insertTableRowBelow()
 {
-    d->updateState(KoTextEditor::Private::Custom, i18n("Insert Row Below"));
-
     QTextTable *table = d->caret.currentTable();
-
     if (table) {
-        KoTableColumnAndRowStyleManager carsManager = \
                KoTableColumnAndRowStyleManager::getManager(table);
-        QTextTableCell cell = table->cellAt(d->caret);
-        int row = cell.row() +1;
-        if (row == table->rows()) {
-            table->appendRows(1);
-            carsManager.setRowStyle(row, carsManager.rowStyle(row-1));
-
-            // Copy the cells styles.
-            for (int col = 0; col < table->columns(); ++col) {
-                QTextTableCell cell = table->cellAt(row-1, col);
-                QTextCharFormat format = cell.format();
-                cell = table->cellAt(row, col);
-                cell.setFormat(format);
-            }
-        } else {
-            table->insertRows(row, 1);
-            carsManager.insertRows(row, 1, carsManager.rowStyle(row-1));
-        }
-
+        int changeId = 0;
         KoChangeTracker *changeTracker = \
KoTextDocument(d->document).changeTracker();  if (changeTracker && \
                changeTracker->recordChanges()) {
-            int changeId;
             QString title(i18n("Insert Row Above"));
             changeId = changeTracker->getInsertChangeId(title, 0);
-            for (int i=0; i < table->columns(); i++) {
-                QTextTableCellFormat cellFormat = table->cellAt(row, \
                i).format().toTableCellFormat();
-                cellFormat.setProperty(KoCharacterStyle::ChangeTrackerId, changeId);
-                table->cellAt(row, i).setFormat(cellFormat);
-            }
         }
+        addCommand(new InsertTableRowCommand(this, table, true, changeId));
     }
-
-    d->updateState(KoTextEditor::Private::NoOp);
 }
 
 void KoTextEditor::insertTableColumnLeft()
 {
-    d->updateState(KoTextEditor::Private::Custom, i18n("Insert Column Left"));
-
     QTextTable *table = d->caret.currentTable();
-
     if (table) {
-        KoTableColumnAndRowStyleManager carsManager = \
                KoTableColumnAndRowStyleManager::getManager(table);
-        QTextTableCell cell = table->cellAt(d->caret);
-        int column = cell.column();
-        table->insertColumns(column, 1);
-        carsManager.insertColumns(column, 1, carsManager.columnStyle(column));
-
+        int changeId = 0;
         KoChangeTracker *changeTracker = \
KoTextDocument(d->document).changeTracker();  if (changeTracker && \
                changeTracker->recordChanges()) {
-            int changeId;
             QString title(i18n("Insert Column Left"));
             changeId = changeTracker->getInsertChangeId(title, 0);
-            for (int i=0; i < table->rows(); i++) {
-                QTextTableCellFormat cellFormat = table->cellAt(i, \
                column).format().toTableCellFormat();
-                cellFormat.setProperty(KoCharacterStyle::ChangeTrackerId, changeId);
-                table->cellAt(i, column).setFormat(cellFormat);
-            }
         }
+        addCommand(new InsertTableColumnCommand(this, table, false, changeId));
     }
-
-    d->updateState(KoTextEditor::Private::NoOp);
 }
 
 void KoTextEditor::insertTableColumnRight()
 {
-    d->updateState(KoTextEditor::Private::Custom, i18n("Insert Column Right"));
-
     QTextTable *table = d->caret.currentTable();
-
     if (table) {
-        KoTableColumnAndRowStyleManager carsManager = \
                KoTableColumnAndRowStyleManager::getManager(table);
-        QTextTableCell cell = table->cellAt(d->caret);
-        int column = cell.column()+1;
-        if (column == table->columns()) {
-            table->appendColumns(1);
-            carsManager.setColumnStyle(column, carsManager.columnStyle(column-1));
-            // Copy the cells style. for the bottomright cell which Qt doesn't
-            QTextTableCell cell = table->cellAt(table->rows()-1, column-1);
-            QTextCharFormat format = cell.format();
-            cell = table->cellAt(table->rows()-1, column);
-            cell.setFormat(format);
-        } else {
-            table->insertColumns(column, 1);
-            carsManager.insertColumns(column, 1, carsManager.columnStyle(column-1));
-        }
-
+        int changeId = 0;
         KoChangeTracker *changeTracker = \
KoTextDocument(d->document).changeTracker();  if (changeTracker && \
                changeTracker->recordChanges()) {
-            int changeId;
             QString title(i18n("Insert Column Right"));
             changeId = changeTracker->getInsertChangeId(title, 0);
-            for (int i=0; i < table->rows(); i++) {
-                QTextTableCellFormat cellFormat = table->cellAt(i, \
                column).format().toTableCellFormat();
-                cellFormat.setProperty(KoCharacterStyle::ChangeTrackerId, changeId);
-                table->cellAt(i, column).setFormat(cellFormat);
-            }
         }
+        addCommand(new InsertTableColumnCommand(this, table, true, changeId));
     }
-
-    d->updateState(KoTextEditor::Private::NoOp);
 }
 
 void KoTextEditor::deleteTableColumn()
 {
-    d->updateState(KoTextEditor::Private::Custom, i18n("Delete Column"));
-
     QTextTable *table = d->caret.currentTable();
-
     if (table) {
-        KoTableColumnAndRowStyleManager carsManager = \
                KoTableColumnAndRowStyleManager::getManager(table);
-        int selectionRow;
-        int selectionColumn;
-        int selectionRowSpan;
-        int selectionColumnSpan;
-        if(d->caret.hasComplexSelection()) {
-            d->caret.selectedTableCells(&selectionRow, &selectionRowSpan, \
                &selectionColumn, &selectionColumnSpan);
-        } else {
-            QTextTableCell cell = table->cellAt(d->caret);
-            selectionColumn = cell.column();
-            selectionColumnSpan = 1;
-        }
-
+        int changeId = 0;
         KoChangeTracker *changeTracker = \
KoTextDocument(d->document).changeTracker();  if (changeTracker && \
changeTracker->recordChanges()) {  QString title(i18n("Delete Column"));
-            int changeId = changeTracker->getDeleteChangeId(title, \
                QTextDocumentFragment(), 0);
-            for (int i=0; i < table->rows(); i++) {
-                QTextTableCellFormat cellFormat = table->cellAt(i, \
                selectionColumn).format().toTableCellFormat();
-                cellFormat.setProperty(KoCharacterStyle::ChangeTrackerId, changeId);
-                table->cellAt(i, selectionColumn).setFormat(cellFormat);
-            }
-        } else {
-            table->removeColumns(selectionColumn, selectionColumnSpan);
-            carsManager.removeColumns(selectionColumn, selectionColumnSpan);
+            changeId = changeTracker->getDeleteChangeId(title, \
QTextDocumentFragment(), 0);  }
-    }
 
-    d->updateState(KoTextEditor::Private::NoOp);
+        addCommand(new DeleteTableColumnCommand(this, table, changeId));
+    }
 }
 
 void KoTextEditor::deleteTableRow()
 {
-    d->updateState(KoTextEditor::Private::Custom, i18n("Delete Row"));
-
     QTextTable *table = d->caret.currentTable();
-
     if (table) {
-        KoTableColumnAndRowStyleManager carsManager = \
                KoTableColumnAndRowStyleManager::getManager(table);
-        int selectionRow;
-        int selectionColumn;
-        int selectionRowSpan;
-        int selectionColumnSpan;
-        if(d->caret.hasComplexSelection()) {
-            d->caret.selectedTableCells(&selectionRow, &selectionRowSpan, \
                &selectionColumn, &selectionColumnSpan);
-        } else {
-            QTextTableCell cell = table->cellAt(d->caret);
-            selectionRow = cell.row();
-            selectionRowSpan = 1;
-        }
-
         KoChangeTracker *changeTracker = \
KoTextDocument(d->document).changeTracker(); +        int changeId = 0;
         if (changeTracker && changeTracker->recordChanges()) {
             QString title(i18n("Delete Row"));
-            int changeId = changeTracker->getDeleteChangeId(title, \
                QTextDocumentFragment(), 0);
-            for (int i=0; i < table->columns(); i++) {
-                QTextTableCellFormat cellFormat = table->cellAt(selectionRow, \
                i).format().toTableCellFormat();
-                cellFormat.setProperty(KoCharacterStyle::ChangeTrackerId, changeId);
-                table->cellAt(selectionRow, i).setFormat(cellFormat);
-            }
-        } else {
-            table->removeRows(selectionRow, selectionRowSpan);
-            carsManager.removeRows(selectionRow, selectionRowSpan);
+            changeId = changeTracker->getDeleteChangeId(title, \
QTextDocumentFragment(), 0);  }
+        addCommand(new DeleteTableRowCommand(this, table, changeId));
     }
-
-    d->updateState(KoTextEditor::Private::NoOp);
 }
 
 void KoTextEditor::mergeTableCells()
diff --git a/libs/kotext/commands/DeleteTableColumnCommand.cpp \
b/libs/kotext/commands/DeleteTableColumnCommand.cpp new file mode 100644
index 0000000..b4b04f8
--- /dev/null
+++ b/libs/kotext/commands/DeleteTableColumnCommand.cpp
@@ -0,0 +1,90 @@
+/*
+ This file is part of the KDE project
+ * Copyright (C) 2009 Pierre Stirnweiss <pstirnweiss@googlemail.com>
+ * Copyright (C) 2010 Casper Boemann <cbo@boemann.dk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.*/
+
+#include "DeleteTableColumnCommand.h"
+
+#include <KoTextEditor.h>
+#include "KoTableColumnAndRowStyleManager.h"
+
+#include <QTextTableCell>
+#include <QTextTable>
+
+#include <klocale.h>
+#include <kdebug.h>
+
+DeleteTableColumnCommand::DeleteTableColumnCommand(KoTextEditor *te, QTextTable *t, \
int changeId, +                                             QUndoCommand *parent) :
+    QUndoCommand (parent)
+    ,m_first(true)
+    ,m_textEditor(te)
+    ,m_table(t)
+    ,m_changeId(changeId)
+{
+    setText(i18n("Delete Column"));
+}
+
+void DeleteTableColumnCommand::undo()
+{
+    if (!m_changeId) {
+        KoTableColumnAndRowStyleManager carsManager = \
KoTableColumnAndRowStyleManager::getManager(m_table); +        for (int i = 0; i < \
m_selectionColumnSpan; ++i) { +            \
carsManager.insertColumns(m_selectionColumn + i, 1, m_deletedStyles.at(i)); +        \
} +    }
+
+    QUndoCommand::undo();
+}
+
+void DeleteTableColumnCommand::redo()
+{
+    KoTableColumnAndRowStyleManager carsManager = \
KoTableColumnAndRowStyleManager::getManager(m_table); +    if (!m_first) {
+        if (!m_changeId) {
+            carsManager.removeColumns(m_selectionColumn, m_selectionColumnSpan);
+        }
+        QUndoCommand::redo();
+    } else {
+        m_first = false;
+        int selectionRow;
+        int selectionRowSpan;
+        if(m_textEditor->hasComplexSelection()) {
+            m_textEditor->cursor()->selectedTableCells(&selectionRow, \
&selectionRowSpan, &m_selectionColumn, &m_selectionColumnSpan); +        } else {
+            QTextTableCell cell = m_table->cellAt(*m_textEditor->cursor());
+            m_selectionColumn = cell.column();
+            m_selectionColumnSpan = 1;
+        }
+        
+        if (!m_changeId) {
+            m_table->removeColumns(m_selectionColumn, m_selectionColumnSpan);
+
+            for (int i = m_selectionColumn; i < m_selectionColumn + \
m_selectionColumnSpan; ++i) { +                \
m_deletedStyles.append(carsManager.columnStyle(i)); +            }
+            carsManager.removeColumns(m_selectionColumn, m_selectionColumnSpan);
+        } else {
+            for (int i=0; i < m_table->rows(); i++) {
+                QTextTableCellFormat cellFormat = m_table->cellAt(i, \
m_selectionColumn).format().toTableCellFormat(); +                \
cellFormat.setProperty(KoCharacterStyle::ChangeTrackerId, m_changeId); +              \
m_table->cellAt(i, m_selectionColumn).setFormat(cellFormat); +            }    
+        }
+    }
+}
diff --git a/libs/kotext/commands/DeleteTableColumnCommand.h \
b/libs/kotext/commands/DeleteTableColumnCommand.h new file mode 100644
index 0000000..812feb0
--- /dev/null
+++ b/libs/kotext/commands/DeleteTableColumnCommand.h
@@ -0,0 +1,50 @@
+/*
+ This file is part of the KDE project
+ * Copyright (C) 2009 Pierre Stirnweiss <pstirnweiss@googlemail.com>
+ * Copyright (C) 2010 Casper Boemann <cbo@boemann.dk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.*/
+
+#ifndef DELETETABLECOLUMNCOMMAND_H
+#define DELETETABLECOLUMNCOMMAND_H
+
+#include <QUndoStack>
+#include <QList>
+#include <KoTableColumnStyle.h>
+
+class KoTextEditor;
+class QTextTable;
+
+class DeleteTableColumnCommand : public QUndoCommand
+{
+public:
+
+    DeleteTableColumnCommand(KoTextEditor *te, QTextTable *t, int changeId = 0, \
QUndoCommand *parent = 0); +
+    virtual void undo();
+    virtual void redo();
+
+private:
+    bool m_first;
+    KoTextEditor *m_textEditor;
+    QTextTable *m_table;
+    int m_selectionColumn;
+    int m_selectionColumnSpan;
+    int m_changeId;
+    QList<KoTableColumnStyle> m_deletedStyles;
+};
+
+#endif // DELETETABLEROWCOMMAND_H
diff --git a/libs/kotext/commands/DeleteTableRowCommand.cpp \
b/libs/kotext/commands/DeleteTableRowCommand.cpp new file mode 100644
index 0000000..21f3c18
--- /dev/null
+++ b/libs/kotext/commands/DeleteTableRowCommand.cpp
@@ -0,0 +1,89 @@
+/*
+ This file is part of the KDE project
+ * Copyright (C) 2009 Pierre Stirnweiss <pstirnweiss@googlemail.com>
+ * Copyright (C) 2010 Casper Boemann <cbo@boemann.dk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.*/
+
+#include "DeleteTableRowCommand.h"
+
+#include <KoTextEditor.h>
+#include "KoTableColumnAndRowStyleManager.h"
+
+#include <QTextTableCell>
+#include <QTextTable>
+
+#include <klocale.h>
+#include <kdebug.h>
+
+DeleteTableRowCommand::DeleteTableRowCommand(KoTextEditor *te, QTextTable *t, int \
changeId, +                                             QUndoCommand *parent) :
+    QUndoCommand (parent)
+    ,m_first(true)
+    ,m_textEditor(te)
+    ,m_table(t)
+    ,m_changeId(changeId)
+{
+    setText(i18n("Delete Row"));
+}
+
+void DeleteTableRowCommand::undo()
+{
+    if (!m_changeId) {
+        KoTableColumnAndRowStyleManager carsManager = \
KoTableColumnAndRowStyleManager::getManager(m_table); +        for (int i = 0; i < \
m_selectionRowSpan; ++i) { +            carsManager.insertRows(m_selectionRow + i, 1, \
m_deletedStyles.at(i)); +        }
+    }
+    QUndoCommand::undo();
+}
+
+void DeleteTableRowCommand::redo()
+{
+    KoTableColumnAndRowStyleManager carsManager = \
KoTableColumnAndRowStyleManager::getManager(m_table); +    if (!m_first) {
+        if (!m_changeId) {
+            carsManager.removeRows(m_selectionRow, m_selectionRowSpan);
+        }
+        QUndoCommand::redo();
+    } else {
+        m_first = false;
+        int selectionColumn;
+        int selectionColumnSpan;
+        if(m_textEditor->hasComplexSelection()) {
+            m_textEditor->cursor()->selectedTableCells(&m_selectionRow, \
&m_selectionRowSpan, &selectionColumn, &selectionColumnSpan); +        } else {
+            QTextTableCell cell = m_table->cellAt(*m_textEditor->cursor());
+            m_selectionRow = cell.row();
+            m_selectionRowSpan = 1;
+        }
+
+        if (!m_changeId) {
+            for (int i = m_selectionRow; i < m_selectionRow + m_selectionRowSpan; \
++i) { +                m_deletedStyles.append(carsManager.rowStyle(i));
+            }
+            carsManager.removeRows(m_selectionRow, m_selectionRowSpan);
+    
+            m_table->removeRows(m_selectionRow, m_selectionRowSpan);
+        } else {
+            for (int i=0; i < m_table->columns(); i++) {
+                QTextTableCellFormat cellFormat = m_table->cellAt(m_selectionRow, \
i).format().toTableCellFormat(); +                \
cellFormat.setProperty(KoCharacterStyle::ChangeTrackerId, m_changeId); +              \
m_table->cellAt(m_selectionRow, i).setFormat(cellFormat); +            }    
+        }
+    }
+}
diff --git a/libs/kotext/commands/DeleteTableRowCommand.h \
b/libs/kotext/commands/DeleteTableRowCommand.h new file mode 100644
index 0000000..3aa25b3
--- /dev/null
+++ b/libs/kotext/commands/DeleteTableRowCommand.h
@@ -0,0 +1,50 @@
+/*
+ This file is part of the KDE project
+ * Copyright (C) 2009 Pierre Stirnweiss <pstirnweiss@googlemail.com>
+ * Copyright (C) 2010 Casper Boemann <cbo@boemann.dk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.*/
+
+#ifndef DELETETABLEROWCOMMAND_H
+#define DELETETABLEROWCOMMAND_H
+
+#include <QUndoStack>
+#include <QList>
+#include <KoTableRowStyle.h>
+
+class KoTextEditor;
+class QTextTable;
+
+class DeleteTableRowCommand : public QUndoCommand
+{
+public:
+
+    DeleteTableRowCommand(KoTextEditor *te, QTextTable *t, int changeId = 0, \
QUndoCommand *parent = 0); +
+    virtual void undo();
+    virtual void redo();
+
+private:
+    bool m_first;
+    KoTextEditor *m_textEditor;
+    QTextTable *m_table;
+    int m_selectionRow;
+    int m_selectionRowSpan;
+    int m_changeId;
+    QList<KoTableRowStyle> m_deletedStyles;
+};
+
+#endif // DELETETABLEROWCOMMAND_H
diff --git a/libs/kotext/commands/InsertTableColumnCommand.cpp \
b/libs/kotext/commands/InsertTableColumnCommand.cpp new file mode 100644
index 0000000..341e529
--- /dev/null
+++ b/libs/kotext/commands/InsertTableColumnCommand.cpp
@@ -0,0 +1,87 @@
+/*
+ This file is part of the KDE project
+ * Copyright (C) 2009 Pierre Stirnweiss <pstirnweiss@googlemail.com>
+ * Copyright (C) 2010-2011 Casper Boemann <cbo@boemann.dk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.*/
+
+#include "InsertTableColumnCommand.h"
+
+#include <KoTextEditor.h>
+#include "KoTableColumnAndRowStyleManager.h"
+
+#include <QTextTableCell>
+#include <QTextTable>
+
+#include <klocale.h>
+#include <kdebug.h>
+
+InsertTableColumnCommand::InsertTableColumnCommand(KoTextEditor *te, QTextTable *t, \
bool right, int changeId, +                                 QUndoCommand *parent) :
+    QUndoCommand (parent)
+    ,m_first(true)
+    ,m_textEditor(te)
+    ,m_table(t)
+    ,m_right(right)
+    ,m_changeId(changeId)
+{
+    if(right) {
+        setText(i18n("Insert Column Right"));
+    } else {
+        setText(i18n("Insert Column Left"));
+    }
+}
+
+void InsertTableColumnCommand::undo()
+{
+    KoTableColumnAndRowStyleManager carsManager = \
KoTableColumnAndRowStyleManager::getManager(m_table); +
+    carsManager.removeColumns(m_column, 1);
+
+    QUndoCommand::undo();
+}
+
+void InsertTableColumnCommand::redo()
+{
+    KoTableColumnAndRowStyleManager carsManager = \
KoTableColumnAndRowStyleManager::getManager(m_table); +    if (!m_first) {
+        carsManager.insertColumns(m_column, 1, m_style);
+        QUndoCommand::redo();
+    } else {
+        m_first = false;
+        QTextTableCell cell = m_table->cellAt(*m_textEditor->cursor());
+        m_column = cell.column() + (m_right ? 1 : 0);
+        m_style = carsManager.columnStyle(cell.column());
+        m_table->insertColumns(m_column, 1);
+        carsManager.insertColumns(m_column, 1, m_style);
+
+        if (m_right && m_column == m_table->columns()-1) {
+            // Copy the cell style. for the bottomright cell which Qt doesn't
+            QTextTableCell cell = m_table->cellAt(m_table->rows()-1, m_column - 1);
+            QTextCharFormat format = cell.format();
+            cell = m_table->cellAt(m_table->rows()-1, m_column);
+            cell.setFormat(format);
+        }
+
+        if (m_changeId) {
+            for (int i=0; i < m_table->rows(); i++) {
+                QTextTableCellFormat cellFormat = m_table->cellAt(i, \
m_column).format().toTableCellFormat(); +                \
cellFormat.setProperty(KoCharacterStyle::ChangeTrackerId, m_changeId); +              \
m_table->cellAt(i, m_column).setFormat(cellFormat); +            }
+        }
+    }
+}
diff --git a/libs/kotext/commands/InsertTableColumnCommand.h \
b/libs/kotext/commands/InsertTableColumnCommand.h new file mode 100644
index 0000000..2cfc267
--- /dev/null
+++ b/libs/kotext/commands/InsertTableColumnCommand.h
@@ -0,0 +1,50 @@
+/*
+ This file is part of the KDE project
+ * Copyright (C) 2009 Pierre Stirnweiss <pstirnweiss@googlemail.com>
+ * Copyright (C) 2010-2011 Casper Boemann <cbo@boemann.dk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.*/
+
+#ifndef INSERTTABLECOLUMNCOMMAND_H
+#define INSERTTABLECOLUMNCOMMAND_H
+
+#include <QUndoStack>
+#include <QList>
+#include <KoTableColumnStyle.h>
+
+class KoTextEditor;
+class QTextTable;
+
+class InsertTableColumnCommand : public QUndoCommand
+{
+public:
+
+    InsertTableColumnCommand(KoTextEditor *te, QTextTable *t, bool right, int \
changeId = 0, QUndoCommand *parent = 0); +
+    virtual void undo();
+    virtual void redo();
+
+private:
+    bool m_first;
+    KoTextEditor *m_textEditor;
+    QTextTable *m_table;
+    int m_column;
+    bool m_right;
+    int m_changeId;
+    KoTableColumnStyle m_style;
+};
+
+#endif // INSERTTABLECOLUMNCOMMAND_H
diff --git a/libs/kotext/commands/InsertTableRowCommand.cpp \
b/libs/kotext/commands/InsertTableRowCommand.cpp new file mode 100644
index 0000000..f30948b
--- /dev/null
+++ b/libs/kotext/commands/InsertTableRowCommand.cpp
@@ -0,0 +1,89 @@
+/*
+ This file is part of the KDE project
+ * Copyright (C) 2009 Pierre Stirnweiss <pstirnweiss@googlemail.com>
+ * Copyright (C) 2010-2011 Casper Boemann <cbo@boemann.dk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.*/
+
+#include "InsertTableRowCommand.h"
+
+#include <KoTextEditor.h>
+#include "KoTableColumnAndRowStyleManager.h"
+
+#include <QTextTableCell>
+#include <QTextTable>
+
+#include <klocale.h>
+#include <kdebug.h>
+
+InsertTableRowCommand::InsertTableRowCommand(KoTextEditor *te, QTextTable *t, bool \
below, int changeId, +                                 QUndoCommand *parent) :
+    QUndoCommand (parent)
+    ,m_first(true)
+    ,m_textEditor(te)
+    ,m_table(t)
+    ,m_changeId(changeId)
+    ,m_below(below)
+{
+    if(below) {
+        setText(i18n("Insert Row Below"));
+    } else {
+        setText(i18n("Insert Row Above"));
+    }
+}
+
+void InsertTableRowCommand::undo()
+{
+    KoTableColumnAndRowStyleManager carsManager = \
KoTableColumnAndRowStyleManager::getManager(m_table); +
+    carsManager.removeRows(m_row, 1);
+
+    QUndoCommand::undo();
+}
+
+void InsertTableRowCommand::redo()
+{
+    KoTableColumnAndRowStyleManager carsManager = \
KoTableColumnAndRowStyleManager::getManager(m_table); +    if (!m_first) {
+        carsManager.insertRows(m_row, 1, m_style);
+        QUndoCommand::redo();
+    } else {
+        m_first = false;
+        QTextTableCell cell = m_table->cellAt(*m_textEditor->cursor());
+        m_row = cell.row() + (m_below ? 1 : 0);
+        m_style = carsManager.rowStyle(cell.row());
+        m_table->insertRows(m_row, 1);
+        carsManager.insertRows(m_row, 1, m_style);
+
+        if (m_below && m_row == m_table->rows()-1) {
+            // Copy the cells styles. when Qt doesn't do it for us
+            for (int col = 0; col < m_table->columns(); ++col) {
+                QTextTableCell cell = m_table->cellAt(m_row - 1, col);
+                QTextCharFormat format = cell.format();
+                cell = m_table->cellAt(m_row, col);
+                cell.setFormat(format);
+            }
+        }
+
+        if (m_changeId) {
+            for (int i=0; i < m_table->columns(); i++) {
+                QTextTableCellFormat cellFormat = m_table->cellAt(m_row, \
i).format().toTableCellFormat(); +                \
cellFormat.setProperty(KoCharacterStyle::ChangeTrackerId, m_changeId); +              \
m_table->cellAt(m_row, i).setFormat(cellFormat); +            }
+        }
+    }
+}
diff --git a/libs/kotext/commands/InsertTableRowCommand.h \
b/libs/kotext/commands/InsertTableRowCommand.h new file mode 100644
index 0000000..75f007c
--- /dev/null
+++ b/libs/kotext/commands/InsertTableRowCommand.h
@@ -0,0 +1,50 @@
+/*
+ This file is part of the KDE project
+ * Copyright (C) 2009 Pierre Stirnweiss <pstirnweiss@googlemail.com>
+ * Copyright (C) 2010-2011 Casper Boemann <cbo@boemann.dk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.*/
+
+#ifndef INSERTTABLEROWCOMMAND_H
+#define INSERTTABLEROWCOMMAND_H
+
+#include <QUndoStack>
+#include <QList>
+#include <KoTableRowStyle.h>
+
+class KoTextEditor;
+class QTextTable;
+
+class InsertTableRowCommand : public QUndoCommand
+{
+public:
+
+    InsertTableRowCommand(KoTextEditor *te, QTextTable *t, bool below, int changeId \
= 0, QUndoCommand *parent = 0); +
+    virtual void undo();
+    virtual void redo();
+
+private:
+    bool m_first;
+    KoTextEditor *m_textEditor;
+    QTextTable *m_table;
+    int m_row;
+    int m_changeId;
+    bool m_below;
+    KoTableRowStyle m_style;
+};
+
+#endif // INSERTTABLEROWCOMMAND_H


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic