|
10 | 10 | #include "Wt/WEnvironment" |
11 | 11 | #include "Wt/WTable" |
12 | 12 | #include "Wt/WTableCell" |
| 13 | +#include "Wt/WTableRow" |
13 | 14 | #include "DomElement.h" |
| 15 | +#include "Utils.h" |
14 | 16 |
|
15 | 17 | namespace Wt { |
16 | 18 |
|
@@ -401,4 +403,45 @@ WTableRow::TableData& WTable::itemAt(int row, int column) |
401 | 403 | return rows_[row]->cells_[column]; |
402 | 404 | } |
403 | 405 |
|
| 406 | +void WTable::moveRow(int from, int to) |
| 407 | +{ |
| 408 | + if (from < 0 || from >= (int)rows_.size()) |
| 409 | + throw std::logic_error("WTable::moveRow: the from index is not within the " |
| 410 | + "current table dimensions."); |
| 411 | + |
| 412 | + WTableRow* from_tr = rowAt(from); |
| 413 | + |
| 414 | + Utils::erase(rows_, from_tr); |
| 415 | + if (to > (int)rows_.size()) |
| 416 | + rowAt(to); |
| 417 | + rows_.insert(rows_.begin() + to, from_tr); |
| 418 | + |
| 419 | + flags_.set(BIT_GRID_CHANGED); |
| 420 | + repaint(RepaintInnerHtml); |
| 421 | +} |
| 422 | + |
| 423 | +void WTable::moveColumn(int from, int to) |
| 424 | +{ |
| 425 | + if (from < 0 || from >= (int)columns_.size()) |
| 426 | + throw std::logic_error("WTable::moveColumn: the from index is not within " |
| 427 | + "the current table dimensions."); |
| 428 | + |
| 429 | + WTableColumn* from_tc = columnAt(from); |
| 430 | + |
| 431 | + Utils::erase(columns_, from_tc); |
| 432 | + if (to > (int)columns_.size()) |
| 433 | + columnAt(to); |
| 434 | + columns_.insert(columns_.begin() + to, from_tc); |
| 435 | + |
| 436 | + for (unsigned i = 0; i < rows_.size(); i++) { |
| 437 | + std::vector<WTableRow::TableData>& cells = rows_[i]->cells_; |
| 438 | + WTableRow::TableData cell = cells[from]; |
| 439 | + cells.erase(cells.begin() + from); |
| 440 | + cells.insert(cells.begin() + to, cell); |
| 441 | + } |
| 442 | + |
| 443 | + flags_.set(BIT_GRID_CHANGED); |
| 444 | + repaint(RepaintInnerHtml); |
| 445 | +} |
| 446 | + |
404 | 447 | } |
0 commit comments