1
/***************************************************************************
4
Description : View class for Table
5
--------------------------------------------------------------------
6
Copyright : (C) 2007 Tilman Benkert (thzs*gmx.net)
7
(replace * with @ in the email addresses)
9
***************************************************************************/
11
/***************************************************************************
13
* This program is free software; you can redistribute it and/or modify *
14
* it under the terms of the GNU General Public License as published by *
15
* the Free Software Foundation; either version 2 of the License, or *
16
* (at your option) any later version. *
18
* This program is distributed in the hope that it will be useful, *
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21
* GNU General Public License for more details. *
23
* You should have received a copy of the GNU General Public License *
24
* along with this program; if not, write to the Free Software *
25
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26
* Boston, MA 02110-1301 USA *
28
***************************************************************************/
30
#include "table/future_Table.h"
31
#include "table/TableView.h"
32
#include "table/TableModel.h"
33
#include "table/TableItemDelegate.h"
34
#include "table/tablecommands.h"
35
#include "table/TableDoubleHeaderView.h"
37
#include "core/column/Column.h"
38
#include "core/AbstractFilter.h"
39
#include "core/datatypes/SimpleCopyThroughFilter.h"
40
#include "core/datatypes/Double2StringFilter.h"
41
#include "core/datatypes/String2DoubleFilter.h"
42
#include "core/datatypes/DateTime2StringFilter.h"
43
#include "core/datatypes/String2DateTimeFilter.h"
47
#include <QHeaderView>
51
#include <QFontMetrics>
53
#include <QItemSelectionModel>
54
#include <QItemSelection>
56
#include <QModelIndex>
57
#include <QGridLayout>
58
#include <QScrollArea>
61
#ifndef LEGACY_CODE_0_2_x
62
TableView::TableView(future::Table *table)
65
TableView::TableView(const QString& label, QWidget* parent, const char* name, Qt::WFlags f)
66
: MyWidget(label, parent, name, f)
69
#ifndef LEGACY_CODE_0_2_x
70
d_model = new TableModel(table);
77
TableView::~TableView()
82
void TableView::setTable(future::Table * table)
85
d_model = new TableModel(table);
89
void TableView::init()
91
d_main_layout = new QHBoxLayout(this);
92
d_main_layout->setSpacing(0);
93
d_main_layout->setContentsMargins(0, 0, 0, 0);
95
d_view_widget = new TableViewWidget(this);
96
d_view_widget->setModel(d_model);
97
connect(d_view_widget, SIGNAL(advanceCell()), this, SLOT(advanceCell()));
98
d_main_layout->addWidget(d_view_widget);
100
d_horizontal_header = new TableDoubleHeaderView();
101
d_horizontal_header->setClickable(true);
102
d_horizontal_header->setHighlightSections(true);
103
d_view_widget->setHorizontalHeader(d_horizontal_header);
105
d_hide_button = new QToolButton();
106
d_hide_button->setArrowType(Qt::RightArrow);
107
d_hide_button->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding));
108
d_hide_button->setCheckable(false);
109
d_main_layout->addWidget(d_hide_button);
110
connect(d_hide_button, SIGNAL(pressed()), this, SLOT(toggleControlTabBar()));
111
d_control_tabs = new QWidget();
112
ui.setupUi(d_control_tabs);
113
d_main_layout->addWidget(d_control_tabs);
115
d_delegate = new TableItemDelegate(d_view_widget);
116
d_view_widget->setItemDelegate(d_delegate);
118
d_view_widget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
119
d_main_layout->setStretchFactor(d_view_widget, 1);
121
setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
123
d_view_widget->setFocusPolicy(Qt::StrongFocus);
124
setFocusPolicy(Qt::StrongFocus);
126
#if QT_VERSION >= 0x040300
127
d_view_widget->setCornerButtonEnabled(true);
130
d_view_widget->setSelectionMode(QAbstractItemView::ExtendedSelection);
132
QHeaderView * v_header = d_view_widget->verticalHeader();
133
// Remark: ResizeToContents works in Qt 4.2.3 but is broken in 4.3.0
134
// Should be fixed in 4.3.1 though, see:
135
// http://trolltech.com/developer/task-tracker/index_html?method=entry&id=165567
136
v_header->setResizeMode(QHeaderView::ResizeToContents);
137
v_header->setMovable(false);
138
d_horizontal_header->setResizeMode(QHeaderView::Interactive);
139
d_horizontal_header->setMovable(true);
140
connect(d_horizontal_header, SIGNAL(sectionMoved(int,int,int)), this, SLOT(handleHorizontalSectionMoved(int,int,int)));
141
connect(d_horizontal_header, SIGNAL(sectionDoubleClicked(int)), this, SLOT(handleHorizontalHeaderDoubleClicked(int)));
143
d_horizontal_header->setDefaultSectionSize(future::Table::defaultColumnWidth());
145
v_header->installEventFilter(this);
146
d_horizontal_header->installEventFilter(this);
147
d_view_widget->installEventFilter(this);
149
connect(d_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d_view_widget,
150
SLOT(updateHeaderGeometry(Qt::Orientation,int,int)) );
151
connect(d_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), this,
152
SLOT(handleHeaderDataChanged(Qt::Orientation,int,int)) );
153
connect(d_table, SIGNAL(aspectDescriptionChanged(const AbstractAspect*)),
154
this, SLOT(handleAspectDescriptionChanged(const AbstractAspect*)));
155
connect(d_table, SIGNAL(aspectAdded(const AbstractAspect*)),
156
this, SLOT(handleAspectAdded(const AbstractAspect*)));
157
connect(d_table, SIGNAL(aspectAboutToBeRemoved(const AbstractAspect*,int)),
158
this, SLOT(handleAspectAboutToBeRemoved(const AbstractAspect*,int)));
160
rereadSectionSizes();
162
// keyboard shortcuts
163
QShortcut * sel_all = new QShortcut(QKeySequence(tr("Ctrl+A", "Table: select all")), d_view_widget);
164
connect(sel_all, SIGNAL(activated()), d_view_widget, SLOT(selectAll()));
166
connect(ui.type_box, SIGNAL(currentIndexChanged(int)), this, SLOT(updateFormatBox()));
167
connect(ui.format_box, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTypeInfo()));
168
connect(ui.digits_box, SIGNAL(valueChanged(int)), this, SLOT(updateTypeInfo()));
169
connect(ui.previous_column_button, SIGNAL(clicked()), this, SLOT(goToPreviousColumn()));
170
connect(ui.next_column_button, SIGNAL(clicked()), this, SLOT(goToNextColumn()));
171
retranslateStrings();
173
QItemSelectionModel * sel_model = d_view_widget->selectionModel();
175
connect(sel_model, SIGNAL(currentColumnChanged(const QModelIndex&, const QModelIndex&)),
176
this, SLOT(currentColumnChanged(const QModelIndex&, const QModelIndex&)));
177
connect(sel_model, SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),
178
this, SLOT(selectionChanged(const QItemSelection&,const QItemSelection&)));
179
connect(ui.button_set_description, SIGNAL(pressed()),
180
this, SLOT(applyDescription()));
181
connect(ui.button_set_type, SIGNAL(pressed()),
182
this, SLOT(applyType()));
185
void TableView::rereadSectionSizes()
187
disconnect(d_horizontal_header, SIGNAL(sectionResized(int, int, int)), this, SLOT(handleHorizontalSectionResized(int, int, int)));
189
int cols = d_table->columnCount();
190
for (int i=0; i<cols; i++)
191
d_horizontal_header->resizeSection(i, d_table->columnWidth(i));
193
connect(d_horizontal_header, SIGNAL(sectionResized(int, int, int)), this, SLOT(handleHorizontalSectionResized(int, int, int)));
196
void TableView::setColumnWidth(int col, int width)
198
d_horizontal_header->resizeSection(col, width);
201
int TableView::columnWidth(int col) const
203
return d_horizontal_header->sectionSize(col);
206
void TableView::handleHorizontalSectionResized(int logicalIndex, int oldSize, int newSize)
208
static bool inside = false;
209
d_table->setColumnWidth(logicalIndex, newSize);
213
int cols = d_table->columnCount();
214
for (int i=0; i<cols; i++)
215
if(isColumnSelected(i, true))
216
d_horizontal_header->resizeSection(i, newSize);
221
void TableView::changeEvent(QEvent * event)
223
if (event->type() == QEvent::LanguageChange)
224
retranslateStrings();
225
MyWidget::changeEvent(event);
228
void TableView::retranslateStrings()
230
d_hide_button->setToolTip(tr("Show/hide control tabs"));
231
ui.retranslateUi(d_control_tabs);
233
ui.type_box->clear();
234
ui.type_box->addItem(tr("Numeric"), QVariant(int(SciDAVis::Numeric)));
235
ui.type_box->addItem(tr("Text"), QVariant(int(SciDAVis::Text)));
236
ui.type_box->addItem(tr("Month names"), QVariant(int(SciDAVis::Month)));
237
ui.type_box->addItem(tr("Day names"), QVariant(int(SciDAVis::Day)));
238
ui.type_box->addItem(tr("Date and time"), QVariant(int(SciDAVis::DateTime)));
240
ui.type_box->setCurrentIndex(0);
242
// TODO: implement formula stuff
243
//ui.formula_info->document()->setPlainText("not implemented yet");
246
void TableView::advanceCell()
248
QModelIndex idx = d_view_widget->currentIndex();
249
if(idx.row()+1 >= d_table->rowCount())
251
int new_size = d_table->rowCount()+1;
252
d_table->setRowCount(new_size);
254
d_view_widget->setCurrentIndex(idx.sibling(idx.row()+1, idx.column()));
257
void TableView::goToCell(int row, int col)
259
QModelIndex index = d_model->index(row, col);
260
d_view_widget->scrollTo(index);
261
d_view_widget->setCurrentIndex(index);
264
void TableView::selectAll()
266
d_view_widget->selectAll();
269
void TableView::deselectAll()
271
d_view_widget->clearSelection();
274
void TableView::toggleControlTabBar()
276
d_control_tabs->setVisible(!d_control_tabs->isVisible());
277
if(d_control_tabs->isVisible())
278
d_hide_button->setArrowType(Qt::RightArrow);
280
d_hide_button->setArrowType(Qt::LeftArrow);
283
void TableView::handleHorizontalSectionMoved(int index, int from, int to)
285
static bool inside = false;
288
Q_ASSERT(index == from);
291
d_view_widget->horizontalHeader()->moveSection(to, from);
293
d_table->moveColumn(from, to);
296
void TableView::handleHorizontalHeaderDoubleClicked(int index)
299
showControlDescriptionTab();
302
bool TableView::areCommentsShown() const
304
return d_horizontal_header->areCommentsShown();
307
void TableView::toggleComments()
309
showComments(!areCommentsShown());
312
void TableView::showComments(bool on)
314
d_horizontal_header->showComments(on);
318
void TableView::currentColumnChanged(const QModelIndex & current, const QModelIndex & previous)
321
int col = current.column();
322
if(col < 0 || col >= d_table->columnCount()) return;
323
setColumnForControlTabs(col);
326
void TableView::setColumnForControlTabs(int col)
328
if(col < 0 || col >= d_table->columnCount()) return;
329
Column *col_ptr = d_table->column(col);
331
QString str = tr("Current column:\nName: %1\nPosition: %2")\
332
.arg(col_ptr->name()).arg(col+1);
334
ui.name_edit->setText(col_ptr->name());
335
ui.comment_box->document()->setPlainText(col_ptr->comment());
336
ui.type_box->setCurrentIndex(ui.type_box->findData((int)col_ptr->columnMode()));
337
switch(col_ptr->columnMode()) {
338
case SciDAVis::Numeric:
340
Double2StringFilter * filter = static_cast<Double2StringFilter*>(col_ptr->outputFilter());
341
ui.format_box->setCurrentIndex(ui.format_box->findData(filter->numericFormat()));
342
ui.digits_box->setValue(filter->numDigits());
345
case SciDAVis::Month:
347
case SciDAVis::DateTime:
349
DateTime2StringFilter * filter = static_cast<DateTime2StringFilter*>(col_ptr->outputFilter());
350
ui.format_box->setCurrentIndex(ui.format_box->findData(filter->format()));
356
ui.formula_box->setText(col_ptr->formula(0));
359
void TableView::handleAspectDescriptionChanged(const AbstractAspect * aspect)
361
const Column * col = qobject_cast<const Column*>(aspect);
362
if (!col || col->parentAspect() != static_cast<AbstractAspect*>(d_table))
364
ui.add_reference_combobox->setItemText(d_table->columnIndex(col), "col(\"" + col->name() + "\")");
367
void TableView::handleAspectAdded(const AbstractAspect *aspect) {
368
const Column * col = qobject_cast<const Column*>(aspect);
369
if (!col || col->parentAspect() != static_cast<AbstractAspect*>(d_table))
371
ui.add_reference_combobox->insertItem(d_table->indexOfChild(aspect), "col(\"" + col->name() + "\")");
374
void TableView::handleAspectAboutToBeRemoved(const AbstractAspect *parent, int index) {
375
if (parent != d_table)
377
ui.add_reference_combobox->removeItem(index);
380
void TableView::selectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
383
Q_UNUSED(deselected);
386
void TableView::updateFormatBox()
388
int type_index = ui.type_box->currentIndex();
389
if(type_index < 0) return; // should never happen
390
ui.format_box->clear();
391
ui.digits_box->setEnabled(false);
392
switch(ui.type_box->itemData(type_index).toInt())
394
case SciDAVis::Numeric:
395
ui.digits_box->setEnabled(true);
396
ui.format_box->addItem(tr("Decimal"), QVariant('f'));
397
ui.format_box->addItem(tr("Scientific (e)"), QVariant('e'));
398
ui.format_box->addItem(tr("Scientific (E)"), QVariant('E'));
399
ui.format_box->addItem(tr("Automatic (e)"), QVariant('g'));
400
ui.format_box->addItem(tr("Automatic (E)"), QVariant('G'));
403
ui.format_box->addItem(tr("Text"), QVariant());
405
case SciDAVis::Month:
406
ui.format_box->addItem(tr("Number without leading zero"), QVariant("M"));
407
ui.format_box->addItem(tr("Number with leading zero"), QVariant("MM"));
408
ui.format_box->addItem(tr("Abbreviated month name"), QVariant("MMM"));
409
ui.format_box->addItem(tr("Full month name"), QVariant("MMMM"));
412
ui.format_box->addItem(tr("Number without leading zero"), QVariant("d"));
413
ui.format_box->addItem(tr("Number with leading zero"), QVariant("dd"));
414
ui.format_box->addItem(tr("Abbreviated day name"), QVariant("ddd"));
415
ui.format_box->addItem(tr("Full day name"), QVariant("dddd"));
417
case SciDAVis::DateTime:
419
// TODO: allow adding of the combo box entries here
420
const char * date_strings[] = {
433
const char * time_strings[] = {
446
for(i=0; date_strings[i] != 0; i++)
447
ui.format_box->addItem(QString(date_strings[i]), QVariant(date_strings[i]));
448
for(j=0; time_strings[j] != 0; j++)
449
ui.format_box->addItem(QString(time_strings[j]), QVariant(time_strings[j]));
450
for(i=0; date_strings[i] != 0; i++)
451
for(j=0; time_strings[j] != 0; j++)
452
ui.format_box->addItem(QString("%1 %2").arg(date_strings[i]).arg(time_strings[j]),
453
QVariant(QString(date_strings[i]) + " " + QString(time_strings[j])));
457
ui.format_box->addItem(QString()); // just for savety to have at least one item in any case
459
ui.format_box->setCurrentIndex(0);
462
void TableView::updateTypeInfo()
464
int format_index = ui.format_box->currentIndex();
465
int type_index = ui.type_box->currentIndex();
467
QString str = tr("Selected column type:\n");
468
if(format_index >= 0 && type_index >= 0)
470
int type = ui.type_box->itemData(type_index).toInt();
473
case SciDAVis::Numeric:
474
str += tr("Double precision\nfloating point values\n");
475
ui.digits_box->setEnabled(true);
480
case SciDAVis::Month:
481
str += tr("Month names\n");
484
str += tr("Days of the week\n");
486
case SciDAVis::DateTime:
487
str += tr("Dates and/or times\n");
490
str += tr("Example: ");
493
case SciDAVis::Numeric:
494
str += QString::number(123.1234567890123456, ui.format_box->itemData(format_index).toChar().toLatin1(), ui.digits_box->value());
497
str += tr("Hello world!\n");
499
case SciDAVis::Month:
500
str += QLocale().toString(QDate(1900,1,1), ui.format_box->itemData(format_index).toString());
503
str += QLocale().toString(QDate(1900,1,1), ui.format_box->itemData(format_index).toString());
505
case SciDAVis::DateTime:
506
str += QDateTime(QDate(1900,1,1), QTime(23,59,59,999)).toString(ui.format_box->itemData(format_index).toString());
510
ui.type_info->setText(str);
513
void TableView::showControlDescriptionTab()
515
d_control_tabs->setVisible(true);
516
d_hide_button->setArrowType(Qt::RightArrow);
517
ui.tab_widget->setCurrentIndex(0);
518
ui.tab_widget->setFocus();
521
void TableView::showControlTypeTab()
523
d_control_tabs->setVisible(true);
524
d_hide_button->setArrowType(Qt::RightArrow);
525
ui.tab_widget->setCurrentIndex(1);
526
ui.tab_widget->setFocus();
529
void TableView::showControlFormulaTab()
531
d_control_tabs->setVisible(true);
532
d_hide_button->setArrowType(Qt::RightArrow);
533
ui.tab_widget->setCurrentIndex(2);
534
ui.tab_widget->setFocus();
537
void TableView::applyDescription()
539
QItemSelectionModel * sel_model = d_view_widget->selectionModel();
540
int index = sel_model->currentIndex().column();
543
// changing the name triggers an update of the UI, which also resets the content of the
544
// comment box => need to cache it so name and comment can be changed simultaneously
545
QString comment = ui.comment_box->document()->toPlainText();
546
d_table->column(index)->setName(ui.name_edit->text());
547
d_table->column(index)->setComment(comment);
551
void TableView::applyType()
553
int format_index = ui.format_box->currentIndex();
554
int type_index = ui.type_box->currentIndex();
555
if(format_index < 0 && type_index < 0) return;
557
SciDAVis::ColumnMode mode = (SciDAVis::ColumnMode)ui.type_box->itemData(type_index).toInt();
558
QList<Column*> list = selectedColumns();
561
case SciDAVis::Numeric:
562
foreach(Column* col, list)
564
col->setColumnMode(mode);
565
Double2StringFilter * filter = static_cast<Double2StringFilter*>(col->outputFilter());
566
int digits = ui.digits_box->value(); // setNumericFormat causes digits_box to be modified...
567
filter->setNumericFormat(ui.format_box->itemData(format_index).toChar().toLatin1());
568
filter->setNumDigits(digits);
569
// TODO: make sure this is done by a signal from the filter to the column on to the table
570
// d_model->emitColumnChanged(col);
574
foreach(Column* col, list)
575
col->setColumnMode(mode);
577
case SciDAVis::Month:
579
case SciDAVis::DateTime:
580
foreach(Column* col, list)
582
col->setColumnMode(mode);
583
DateTime2StringFilter * filter = static_cast<DateTime2StringFilter*>(col->outputFilter());
584
filter->setFormat(ui.format_box->itemData(format_index).toString());
585
// TODO: make sure this is done by a signal from the filter to the column on to the table
586
// d_model->emitColumnChanged(col);
592
void TableView::handleHeaderDataChanged(Qt::Orientation orientation, int first, int last)
594
if(orientation != Qt::Horizontal) return;
596
QItemSelectionModel * sel_model = d_view_widget->selectionModel();
598
int col = sel_model->currentIndex().column();
599
if(col < first || col > last) return;
600
setColumnForControlTabs(col);
603
int TableView::selectedColumnCount(bool full)
606
int cols = d_table->columnCount();
607
for (int i=0; i<cols; i++)
608
if(isColumnSelected(i, full)) count++;
612
int TableView::selectedColumnCount(SciDAVis::PlotDesignation pd)
615
int cols = d_table->columnCount();
616
for(int i=0; i<cols; i++)
617
if( isColumnSelected(i, false) && (d_table->column(i)->plotDesignation() == pd) ) count++;
622
bool TableView::isColumnSelected(int col, bool full)
625
return d_view_widget->selectionModel()->isColumnSelected(col, QModelIndex());
627
return d_view_widget->selectionModel()->columnIntersectsSelection(col, QModelIndex());
630
QList<Column*> TableView::selectedColumns(bool full)
633
int cols = d_table->columnCount();
634
for (int i=0; i<cols; i++)
635
if(isColumnSelected(i, full)) list << d_table->column(i);
640
int TableView::selectedRowCount(bool full)
643
int rows = d_table->rowCount();
644
for (int i=0; i<rows; i++)
645
if(isRowSelected(i, full)) count++;
649
bool TableView::isRowSelected(int row, bool full)
652
return d_view_widget->selectionModel()->isRowSelected(row, QModelIndex());
654
return d_view_widget->selectionModel()->rowIntersectsSelection(row, QModelIndex());
657
int TableView::firstSelectedColumn(bool full)
659
int cols = d_table->columnCount();
660
for (int i=0; i<cols; i++)
662
if(isColumnSelected(i, full))
668
int TableView::lastSelectedColumn(bool full)
670
int cols = d_table->columnCount();
671
for(int i=cols-1; i>=0; i--)
672
if(isColumnSelected(i, full)) return i;
677
int TableView::firstSelectedRow(bool full)
679
int rows = d_table->rowCount();
680
for (int i=0; i<rows; i++)
682
if(isRowSelected(i, full))
688
int TableView::lastSelectedRow(bool full)
690
int rows = d_table->rowCount();
691
for(int i=rows-1; i>=0; i--)
692
if(isRowSelected(i, full)) return i;
697
IntervalAttribute<bool> TableView::selectedRows(bool full) {
698
IntervalAttribute<bool> result;
699
int rows = d_table->rowCount();
700
for (int i=0; i<rows; i++)
701
if (isRowSelected(i, full))
702
result.setValue(i, true);
706
bool TableView::isCellSelected(int row, int col)
708
if(row < 0 || col < 0 || row >= d_table->rowCount() || col >= d_table->columnCount()) return false;
710
return d_view_widget->selectionModel()->isSelected(d_model->index(row, col));
713
void TableView::setCellSelected(int row, int col, bool select)
715
d_view_widget->selectionModel()->select(d_model->index(row, col),
716
select ? QItemSelectionModel::Select : QItemSelectionModel::Deselect);
719
void TableView::setCellsSelected(int first_row, int first_col, int last_row, int last_col, bool select)
721
QModelIndex top_left = d_model->index(first_row, first_col);
722
QModelIndex bottom_right = d_model->index(last_row, last_col);
723
d_view_widget->selectionModel()->select(QItemSelection(top_left, bottom_right),
724
select ? QItemSelectionModel::SelectCurrent : QItemSelectionModel::Deselect);
727
void TableView::getCurrentCell(int * row, int * col)
729
QModelIndex index = d_view_widget->selectionModel()->currentIndex();
733
*col = index.column();
742
bool TableView::eventFilter(QObject * watched, QEvent * event)
744
QHeaderView * v_header = d_view_widget->verticalHeader();
746
if (event->type() == QEvent::ContextMenu)
748
QContextMenuEvent *cm_event = static_cast<QContextMenuEvent *>(event);
749
QPoint global_pos = cm_event->globalPos();
750
if(watched == v_header)
751
d_table->showTableViewRowContextMenu(global_pos);
752
else if(watched == d_horizontal_header) {
753
int col = d_horizontal_header->logicalIndexAt(cm_event->pos());
754
if (!isColumnSelected(col, true)) {
755
QItemSelectionModel * sel_model = d_view_widget->selectionModel();
756
sel_model->clearSelection();
757
sel_model->select(QItemSelection(d_model->index(0, col, QModelIndex()),
758
d_model->index(d_model->rowCount()-1, col, QModelIndex())),
759
QItemSelectionModel::Select);
761
d_table->showTableViewColumnContextMenu(global_pos);
762
} else if(watched == d_view_widget)
763
d_table->showTableViewContextMenu(global_pos);
765
return MyWidget::eventFilter(watched, event);
770
return MyWidget::eventFilter(watched, event);
773
bool TableView::formulaModeActive() const
775
return d_model->formulaModeActive();
778
void TableView::activateFormulaMode(bool on)
780
d_model->activateFormulaMode(on);
783
void TableView::goToNextColumn()
785
if (d_table->columnCount() == 0) return;
787
QModelIndex idx = d_view_widget->currentIndex();
788
int col = idx.column()+1;
789
if (col >= d_table->columnCount())
791
d_view_widget->setCurrentIndex(idx.sibling(idx.row(), col));
794
void TableView::goToPreviousColumn()
796
if (d_table->columnCount() == 0) return;
798
QModelIndex idx = d_view_widget->currentIndex();
799
int col = idx.column()-1;
801
col = d_table->columnCount()-1;
802
d_view_widget->setCurrentIndex(idx.sibling(idx.row(), col));
806
/* ================== TableViewWidget ================ */
808
void TableViewWidget::selectAll()
810
// the original QTableView::selectAll() toggles all cells which is strange behavior IMHO - thzs
811
QItemSelectionModel * sel_model = selectionModel();
812
QItemSelection sel(model()->index(0, 0, QModelIndex()), model()->index(model()->rowCount()-1,
813
model()->columnCount()-1, QModelIndex()));
814
sel_model->select(sel, QItemSelectionModel::Select);
817
void TableViewWidget::updateHeaderGeometry(Qt::Orientation o, int first, int last)
821
if(o != Qt::Horizontal) return;
822
horizontalHeader()->setStretchLastSection(true); // ugly hack (flaw in Qt? Does anyone know a better way?)
823
horizontalHeader()->updateGeometry();
824
horizontalHeader()->setStretchLastSection(false); // ugly hack part 2
827
void TableViewWidget::keyPressEvent(QKeyEvent * event)
829
if(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
831
QTableView::keyPressEvent(event);