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

List:       koffice-devel
Subject:    [patch] remove row/columns from table
From:       "Emmanuel Touzery" <emmanuel.touzery () wanadoo ! fr>
Date:       2002-05-22 6:45:11
[Download RAW message or body]

Hello,

    In vanilla kword, to remove rows from a table, you have to right click
on a table "remove row", and then say which row number in the dialog. this
is not very good (imho), for instance think multipages tables, etc, i don't
want to count which row i want to remove and then realise i got it wrong.
additionnally to remove 3 rows/columns you have to do it one by one.
    with this patch (that changes i18n strings!), kword uses the selected
cells to deduce which rows/cols should be removed (so we act like other WP
out there).

    testing it i noticed bugs on my older kword (undo on removing the 1st
row of a table that does not work or on removing a column that SIGSEGV), but
they are not related to my patch and since i don't know if they are fixed in
CVS i didn't look too much (well, enough to know that they are difficult to
solve for me :O( ).

    thank you,

emmanuel

PS: i plan to get a proper connectivity soon (well i guess), so you won't
have to bother with those patches on older CVS so long (and it's starting to
be a pain for me as well)

["removerowcol.diff" (application/octet-stream)]

Index: deldia.cc
===================================================================
RCS file: /home/kde/koffice/kword/deldia.cc,v
retrieving revision 1.20
diff -u -3 -p -r1.20 deldia.cc
--- deldia.cc	13 Oct 2001 00:17:00 -0000	1.20
+++ deldia.cc	22 May 2002 06:27:45 -0000
@@ -41,6 +41,7 @@ KWDeleteDia::KWDeleteDia( QWidget *paren
     table = _table;
     doc = _doc;
     canvas = _canvas;
+    m_toRemove.clear();
 
     setupTab1();
     setButtonOKText(i18n("&Delete"), type == ROW ?
@@ -55,44 +56,63 @@ void KWDeleteDia::setupTab1()
     tab1 = plainPage();
     grid1 = new QGridLayout( tab1, 4, 1, 0, spacingHint() );
 
-    rc = new QLabel( type == ROW ? i18n( "Delete Row:" ) : i18n( "Delete Column:" ), \
tab1 ); +    QString message =type == ROW ? i18n( "Delete Row(s):" ) : i18n( "Delete \
Column(s):" ); +    bool firstSelectedCell = true; // used to know whether to add a \
", " to the message string. +    
+    uint max = (type == ROW) ? table->getRows() : table->getCols(); // max row/col \
to loop up to +    for (uint i=0;i<max; i++)
+    {
+        if ( ( (type == ROW) && table->isRowSelected(i)) ||
+                ( (type == COL) && table->isColumnSelected(i) ) )
+        {
+            if (!firstSelectedCell)
+                message += ", "; // i18n??
+            message += QString::number(i +1);
+            m_toRemove.push_back(i);
+            firstSelectedCell = false;
+       }
+    }
+    if (m_toRemove.count() == ( (type == ROW) ? table->getRows() : table->getCols() \
) ) +        // all the columns are selected and the user asked to remove columns or \
the same with rows +        // => we want to delete the whole table
+        message = i18n("Delete the whole table");
+    rc = new QLabel( message , tab1 );
     rc->resize( rc->sizeHint() );
     rc->setAlignment( AlignLeft | AlignBottom );
     grid1->addWidget( rc, 1, 0 );
-
-    value = new QSpinBox( 1, type == ROW ? table->getRows() : table->getCols(), 1, \
                tab1 );
-    value->resize( value->sizeHint() );
-    value->setValue( type == ROW ? table->getRows() : table->getCols() );
-    grid1->addWidget( value, 2, 0 );
-
-    grid1->addRowSpacing( 1, rc->height() );
-    grid1->addRowSpacing( 2, value->height() );
-    grid1->setRowStretch( 0, 1 );
-    grid1->setRowStretch( 1, 0 );
-    grid1->setRowStretch( 2, 0 );
-    grid1->setRowStretch( 3, 1 );
-
-    grid1->addColSpacing( 0, rc->width() );
-    grid1->addColSpacing( 0, value->width() );
-    grid1->setColStretch( 0, 1 );
 }
 
 bool KWDeleteDia::doDelete()
 {
-    unsigned int remove= value->value() - 1;
-    if ( type == ROW )
-    {
-        KWRemoveRowCommand *cmd = new KWRemoveRowCommand( i18n("Remove row"), table, \
                remove);
-        cmd->execute();
-        doc->addCommand(cmd);
-        //table->deleteRow( value->value() - 1 );
+    KCommand *globalCommand;
+    
+    if (m_toRemove.count() == ( (type == ROW) ? table->getRows() : table->getCols() \
) ) +    {   // we have to delete the whole table
+        //globalCommand = new KWDeleteTableCommand(i18n("Remove table"), table);
+        doc->deleteTable(table);
     }
     else
-    {
-        KWRemoveColumnCommand *cmd = new KWRemoveColumnCommand( i18n("Remove \
                column"), table, remove);
-        cmd->execute();
-        doc->addCommand(cmd);
-        //table->deleteCol( value->value() - 1 );
+    {   // we will just delete some row/cols
+        if ( type == ROW )
+        {
+            globalCommand = new KMacroCommand(i18n("Remove rows"));
+            for (uint i=0;i<m_toRemove.count();i++)
+            {
+                KWRemoveRowCommand *cmd = new KWRemoveRowCommand( i18n("Remove \
row"), table, m_toRemove[i] ); +                \
static_cast<KMacroCommand*>(globalCommand)->addCommand(cmd); +            }
+        }
+        else
+        {
+            globalCommand = new KMacroCommand(i18n("Remove columns"));
+            for (uint i=0;i<m_toRemove.count();i++)
+            {
+                KWRemoveColumnCommand *cmd = new KWRemoveColumnCommand( i18n("Remove \
column"), table, m_toRemove[i] ); +                \
static_cast<KMacroCommand*>(globalCommand)->addCommand(cmd); +            }
+        }
+        globalCommand->execute();
+        doc->addCommand(globalCommand);
     }
 
     return true;
Index: deldia.h
===================================================================
RCS file: /home/kde/koffice/kword/deldia.h,v
retrieving revision 1.10
diff -u -3 -p -r1.10 deldia.h
--- deldia.h	14 Apr 2001 23:49:15 -0000	1.10
+++ deldia.h	22 May 2002 06:27:45 -0000
@@ -55,6 +55,8 @@ protected:
     KWDocument *doc;
     DeleteType type;
     KWCanvas *canvas;
+    
+    QValueList<uint> m_toRemove; 
 
 protected slots:
     virtual void slotOk();
Index: kwtableframeset.cc
===================================================================
RCS file: /home/kde/koffice/kword/kwtableframeset.cc,v
retrieving revision 1.191
diff -u -3 -p -r1.191 kwtableframeset.cc
--- kwtableframeset.cc	3 Apr 2002 06:11:15 -0000	1.191
+++ kwtableframeset.cc	22 May 2002 06:27:45 -0000
@@ -819,6 +819,36 @@ bool KWTableFrameSet::isOneSelected(unsi
     return false;
 }
 
+bool KWTableFrameSet::isRowSelected(uint row) {
+    Q_ASSERT(row <= getRows());
+    for ( uint i = 0; i < m_cells.count(); i++ ) {
+        if (m_cells.at( i )->frame( 0 )->isSelected()) {
+            if (m_cells.at( i )->m_row == row)
+            {
+                kdDebug() << "row " << row << " row is selected" << endl;
+                return true;
+            }
+        }
+    }
+    kdDebug() << "row " << row << " row is not selected" << endl;
+    return false;
+}
+
+bool KWTableFrameSet::isColumnSelected(uint column) {
+    Q_ASSERT(column <= getCols());
+    for ( uint i = 0; i < m_cells.count(); i++ ) {
+        if (m_cells.at( i )->frame( 0 )->isSelected()) {
+            if (m_cells.at( i )->m_col == column)
+            {
+                kdDebug() << "column " << column << " column is selected" << endl;
+                return true;
+            }
+        }
+    }
+    kdDebug() << "column " << column << " column is not selected" << endl;
+    return false;
+}
+
 bool KWTableFrameSet::getFirstSelected( unsigned int &row, unsigned int &col )
 {
     for ( unsigned int i = 0; i < m_cells.count(); i++ ) {
Index: kwtableframeset.h
===================================================================
RCS file: /home/kde/koffice/kword/kwtableframeset.h,v
retrieving revision 1.86
diff -u -3 -p -r1.86 kwtableframeset.h
--- kwtableframeset.h	5 Apr 2002 16:30:23 -0000	1.86
+++ kwtableframeset.h	22 May 2002 06:27:45 -0000
@@ -52,7 +52,6 @@ class KWordFrameSetIface;
  * can be used to describe the same thing: one table-cell
  */
 
-
 class KWTableFrameSet : public KWFrameSet
 {
     Q_OBJECT
@@ -145,13 +144,13 @@ public:
     void recalcRows(int _col=-1,int _row=-1);
 
     /** returns the number of rows */
-    unsigned int getRows() { return m_rows; }
+    unsigned int getRows() const { return m_rows; }
     /** returns the number of columns */
-    unsigned int getCols() { return m_colPositions.count()-1; }
+    unsigned int getCols() const { return m_colPositions.count()-1; }
 
     /** returns the number of cells the table contains, this includes
      * temporary headers. */
-    unsigned int getNumCells() { return m_cells.count(); }
+    unsigned int getNumCells() const { return m_cells.count(); }
 
     /** returns the fact if one cell (==frame) has been selected */
     bool hasSelectedFrame();
@@ -172,7 +171,10 @@ public:
     /** convenience method */
     void selectUntil( double x, double y);
 
-    bool getFirstSelected(unsigned int &row, unsigned int &col );
+    bool isRowSelected(uint row);
+    bool isColumnSelected(uint column);
+
+    bool getFirstSelected(unsigned int &row, unsigned int &col);
     /** Return true if exactly one frame is selected. The parameters row
     *  and col will receive the values of the active row and col.<br>
     *  When no frame or more then one frame is selected row and col will
@@ -284,6 +286,7 @@ public:
     virtual void printDebug( KWFrame * frame );
     virtual void printDebug();
 #endif
+
 protected:
     /* Overloaded methods, look for docu in kwframe.h */
     virtual void deleteAnchors();


_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/koffice-devel

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

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