64
58
tab1 = plainPage();
65
59
grid1 = new QGridLayout( tab1, 4, 1, 0, spacingHint() );
67
rc = new QLabel( type == ROW ? i18n( "Delete Row:" ) : i18n( "Delete Column:" ), tab1 );
60
QString message =type == ROW ? i18n( "Delete rows:" ) : i18n( "Delete columns:" );
61
bool firstSelectedCell = true; // used to know whether to add a ", " to the message string.
63
uint max = (type == ROW) ? table->getRows() : table->getCols(); // max row/col to loop up to
64
for (uint i=0;i<max; i++)
66
if ( ( (type == ROW) && table->isRowSelected(i)) ||
67
( (type == COL) && table->isColSelected(i) ) )
69
if (!firstSelectedCell)
70
message += ", "; // i18n??
71
message += QString::number(i +1);
72
m_toRemove.push_back(i);
73
firstSelectedCell = false;
76
if ( m_toRemove.isEmpty() ) // Nothing selected, so we want to remove the row/col where the cursor is
78
int val = type == ROW ? canvas->currentTableRow() : canvas->currentTableCol();
79
Q_ASSERT( val != -1 );
80
message += QString::number(val+1);
81
m_toRemove.push_back(val);
83
Q_ASSERT(m_toRemove.count() > 0);
85
if (m_toRemove.count() == ( (type == ROW) ? table->getRows() : table->getCols() ) )
86
// all the columns are selected and the user asked to remove columns or the same with rows
87
// => we want to delete the whole table
88
message = i18n("Delete the whole table");
90
// do not display hugely long dialogs if many rows/cells are selected
91
if (m_toRemove.count() > 10)
92
message = ROW ? i18n("Delete all selected rows") : i18n("Delete all selected cells");
94
rc = new QLabel( message , tab1 );
68
95
rc->resize( rc->sizeHint() );
69
96
rc->setAlignment( AlignLeft | AlignBottom );
70
97
grid1->addWidget( rc, 1, 0 );
72
value = new QSpinBox( 1, type == ROW ? table->getRows() : table->getCols(), 1, tab1 );
73
value->resize( value->sizeHint() );
74
value->setValue( type == ROW ? table->getRows() : table->getCols() );
75
grid1->addWidget( value, 2, 0 );
77
grid1->addRowSpacing( 1, rc->height() );
78
grid1->addRowSpacing( 2, value->height() );
79
grid1->setRowStretch( 0, 1 );
80
grid1->setRowStretch( 1, 0 );
81
grid1->setRowStretch( 2, 0 );
82
grid1->setRowStretch( 3, 1 );
84
grid1->addColSpacing( 0, rc->width() );
85
grid1->addColSpacing( 0, value->width() );
86
grid1->setColStretch( 0, 1 );
89
100
bool KWDeleteDia::doDelete()
91
unsigned int remove= value->value() - 1;
94
KWRemoveRowCommand *cmd = new KWRemoveRowCommand( i18n("Remove row"), table, remove);
97
//table->deleteRow( value->value() - 1 );
101
KWRemoveColumnCommand *cmd = new KWRemoveColumnCommand( i18n("Remove column"), table, remove);
103
doc->addCommand(cmd);
104
//table->deleteCol( value->value() - 1 );
114
table->deleteRow( value->value() - 1 );
116
table->deleteCol( value->value() - 1 );
118
canvas->getCursor()->setFrameSet( doc->getFrameSetNum( table->getFrameSet( 0, 0 ) ) + 1 );
119
doc->drawMarker( *canvas->getCursor(), &p, canvas->contentsX(), canvas->contentsY() );
120
canvas->getCursor()->init( dynamic_cast<KWTextFrameSet*>( doc->getFrameSet( canvas->getCursor()->getFrameSet() - 1 ) )->getFirstParag(), true );
121
canvas->getCursor()->gotoStartOfParag();
122
canvas->getCursor()->cursorGotoLineStart();
125
canvas->recalcCursor();
102
KWView *view = canvas->gui()->getView();
103
if(!view) return false; // can't happen
106
view->tableDeleteRow(m_toRemove);
108
view->tableDeleteCol(m_toRemove);