diff options
Diffstat (limited to 'src/gui/itemviews')
-rw-r--r-- | src/gui/itemviews/qabstractitemview.cpp | 13 | ||||
-rw-r--r-- | src/gui/itemviews/qfileiconprovider.cpp | 5 | ||||
-rw-r--r-- | src/gui/itemviews/qtableview.cpp | 207 | ||||
-rw-r--r-- | src/gui/itemviews/qtableview_p.h | 4 | ||||
-rw-r--r-- | src/gui/itemviews/qtablewidget.cpp | 2 | ||||
-rw-r--r-- | src/gui/itemviews/qtreewidget.cpp | 2 |
6 files changed, 156 insertions, 77 deletions
diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index 27528de..d91cedd 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -761,7 +761,7 @@ void QAbstractItemView::setItemDelegate(QAbstractItemDelegate *delegate) } } d->itemDelegate = delegate; - update(); + viewport()->update(); } /*! @@ -826,7 +826,7 @@ void QAbstractItemView::setItemDelegateForRow(int row, QAbstractItemDelegate *de } d->rowDelegates.insert(row, delegate); } - update(); + viewport()->update(); } /*! @@ -883,7 +883,7 @@ void QAbstractItemView::setItemDelegateForColumn(int column, QAbstractItemDelega } d->columnDelegates.insert(column, delegate); } - update(); + viewport()->update(); } /*! @@ -1697,7 +1697,7 @@ void QAbstractItemView::mouseMoveEvent(QMouseEvent *event) if ((event->buttons() & Qt::LeftButton) && d->selectionAllowed(index) && d->selectionModel) { setState(DragSelectingState); QItemSelectionModel::SelectionFlags command = selectionCommand(index, event); - if (command.testFlag(QItemSelectionModel::Toggle)) { + if (d->ctrlDragSelectionFlag != QItemSelectionModel::NoUpdate && command.testFlag(QItemSelectionModel::Toggle)) { command &= ~QItemSelectionModel::Toggle; command |= d->ctrlDragSelectionFlag; } @@ -2185,6 +2185,9 @@ void QAbstractItemView::keyPressEvent(QKeyEvent *event) } else { d->selectionModel->setCurrentIndex(newCurrent, command); d->pressedPosition = visualRect(newCurrent).center() + d->offset(); + // We copy the same behaviour as for mousePressEvent(). + QRect rect(d->pressedPosition - d->offset(), QSize(1, 1)); + setSelection(rect, command); } return; } @@ -3026,7 +3029,7 @@ void QAbstractItemView::update(const QModelIndex &index) //this test is important for peformance reason //For example in dataChanged we simply update all the cells without checking //it can be a major bottleneck to update rects that aren't even part of the viewport - if (d->viewport->geometry().intersects(rect)) + if (d->viewport->rect().intersects(rect)) d->viewport->update(rect); } } diff --git a/src/gui/itemviews/qfileiconprovider.cpp b/src/gui/itemviews/qfileiconprovider.cpp index c78a49b..e3d17ad 100644 --- a/src/gui/itemviews/qfileiconprovider.cpp +++ b/src/gui/itemviews/qfileiconprovider.cpp @@ -61,6 +61,7 @@ #endif #include <private/qfunctions_p.h> +#include <private/qguiplatformplugin_p.h> #ifndef SHGFI_ADDOVERLAYS #define SHGFI_ADDOVERLAYS 0x000000020 @@ -385,6 +386,10 @@ QIcon QFileIconProvider::icon(const QFileInfo &info) const { Q_D(const QFileIconProvider); + QIcon platformIcon = qt_guiPlatformPlugin()->fileSystemIcon(info); + if (!platformIcon.isNull()) + return platformIcon; + #if defined(Q_WS_X11) && !defined(QT_NO_STYLE_GTK) if (X11->desktopEnvironment == DE_GNOME) { QIcon gtkIcon = QGtk::getFilesystemIcon(info); diff --git a/src/gui/itemviews/qtableview.cpp b/src/gui/itemviews/qtableview.cpp index 15bd445..a610b73 100644 --- a/src/gui/itemviews/qtableview.cpp +++ b/src/gui/itemviews/qtableview.cpp @@ -779,8 +779,6 @@ void QTableViewPrivate::drawAndClipSpans(const QRegion &area, QPainter *painter, foreach (QSpanCollection::Span *span, visibleSpans) { int row = span->top(); int col = span->left(); - if (isHidden(row, col)) - continue; QModelIndex index = model->index(row, col, root); if (!index.isValid()) continue; @@ -1119,6 +1117,9 @@ void QTableView::setHorizontalHeader(QHeaderView *header) connect(d->horizontalHeader, SIGNAL(sectionHandleDoubleClicked(int)), this, SLOT(resizeColumnToContents(int))); connect(d->horizontalHeader, SIGNAL(geometriesChanged()), this, SLOT(updateGeometries())); + + //update the sorting enabled states on the new header + setSortingEnabled(d->sortingEnabled); } /*! @@ -1480,12 +1481,30 @@ QModelIndex QTableView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifi ++column; while (isRowHidden(d->logicalRow(row)) && row < bottom) ++row; + d->visualCursor = QPoint(column, row); return d->model->index(d->logicalRow(row), d->logicalColumn(column), d->root); } - int visualRow = d->visualRow(current.row()); + // Update visual cursor if current index has changed. + QPoint visualCurrent(d->visualColumn(current.column()), d->visualRow(current.row())); + if (visualCurrent != d->visualCursor) { + if (d->hasSpans()) { + QSpanCollection::Span span = d->span(current.row(), current.column()); + if (span.top() > d->visualCursor.y() || d->visualCursor.y() > span.bottom() + || span.left() > d->visualCursor.x() || d->visualCursor.x() > span.right()) + d->visualCursor = visualCurrent; + } else { + d->visualCursor = visualCurrent; + } + } + + int visualRow = d->visualCursor.y(); + if (visualRow > bottom) + visualRow = bottom; Q_ASSERT(visualRow != -1); - int visualColumn = d->visualColumn(current.column()); + int visualColumn = d->visualCursor.x(); + if (visualColumn > right) + visualColumn = right; Q_ASSERT(visualColumn != -1); if (isRightToLeft()) { @@ -1496,22 +1515,33 @@ QModelIndex QTableView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifi } switch (cursorAction) { - case MoveUp: + case MoveUp: { + int originalRow = visualRow; #ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled() && visualRow == 0) visualRow = d->visualRow(model()->rowCount() - 1) + 1; + // FIXME? visualRow = bottom + 1; #endif - --visualRow; - while (visualRow > 0 && d->isVisualRowHiddenOrDisabled(visualRow, visualColumn)) + int r = d->logicalRow(visualRow); + int c = d->logicalColumn(visualColumn); + if (r != -1 && d->hasSpans()) { + QSpanCollection::Span span = d->span(r, c); + if (span.width() > 1 || span.height() > 1) + visualRow = d->visualRow(span.top()); + } + while (visualRow >= 0) { --visualRow; - if (d->hasSpans()) { - int row = d->logicalRow(visualRow); - QSpanCollection::Span span = d->span(row, current.column()); - visualRow = d->visualRow(span.top()); - visualColumn = d->visualColumn(span.left()); + r = d->logicalRow(visualRow); + c = d->logicalColumn(visualColumn); + if (r == -1 || (!isRowHidden(r) && d->isCellEnabled(r, c))) + break; } + if (visualRow < 0) + visualRow = originalRow; break; - case MoveDown: + } + case MoveDown: { + int originalRow = visualRow; if (d->hasSpans()) { QSpanCollection::Span span = d->span(current.row(), current.column()); visualRow = d->visualRow(d->rowSpanEndLogical(span.top(), span.height())); @@ -1520,71 +1550,106 @@ QModelIndex QTableView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifi if (QApplication::keypadNavigationEnabled() && visualRow >= bottom) visualRow = -1; #endif - ++visualRow; - while (visualRow < bottom && d->isVisualRowHiddenOrDisabled(visualRow, visualColumn)) + int r = d->logicalRow(visualRow); + int c = d->logicalColumn(visualColumn); + if (r != -1 && d->hasSpans()) { + QSpanCollection::Span span = d->span(r, c); + if (span.width() > 1 || span.height() > 1) + visualRow = d->visualRow(d->rowSpanEndLogical(span.top(), span.height())); + } + while (visualRow <= bottom) { ++visualRow; - if (d->hasSpans()) { - int row = d->logicalRow(visualRow); - QSpanCollection::Span span = d->span(row, current.column()); - visualColumn = d->visualColumn(span.left()); + r = d->logicalRow(visualRow); + c = d->logicalColumn(visualColumn); + if (r == -1 || (!isRowHidden(r) && d->isCellEnabled(r, c))) + break; } + if (visualRow > bottom) + visualRow = originalRow; break; - case MovePrevious: { - int left = 0; - while (d->isVisualColumnHiddenOrDisabled(visualRow, left) && left < right) - ++left; - if (visualColumn == left) { - visualColumn = right; - int top = 0; - while (top < bottom && d->isVisualRowHiddenOrDisabled(top, visualColumn)) - ++top; - if (visualRow == top) + } + case MovePrevious: + case MoveLeft: { + int originalRow = visualRow; + int originalColumn = visualColumn; + bool firstTime = true; + bool looped = false; + bool wrapped = false; + do { + int r = d->logicalRow(visualRow); + int c = d->logicalColumn(visualColumn); + if (firstTime && c != -1 && d->hasSpans()) { + firstTime = false; + QSpanCollection::Span span = d->span(r, c); + if (span.width() > 1 || span.height() > 1) + visualColumn = d->visualColumn(span.left()); + } + while (visualColumn >= 0) { + --visualColumn; + r = d->logicalRow(visualRow); + c = d->logicalColumn(visualColumn); + if (r == -1 || c == -1 || (!isRowHidden(r) && !isColumnHidden(c) && d->isCellEnabled(r, c))) + break; + if (wrapped && (originalRow < visualRow || (originalRow == visualRow && originalColumn <= visualColumn))) { + looped = true; + break; + } + } + if (cursorAction == MoveLeft || visualColumn >= 0) + break; + visualColumn = right + 1; + if (visualRow == 0) { + wrapped == true; visualRow = bottom; - else - --visualRow; - while (visualRow > 0 && d->isVisualRowHiddenOrDisabled(visualRow, visualColumn)) + } else { --visualRow; - break; - } // else MoveLeft - } - case MoveLeft: - --visualColumn; - while (visualColumn > 0 && d->isVisualColumnHiddenOrDisabled(visualRow, visualColumn)) - --visualColumn; - if (d->hasSpans()) { - int column = d->logicalColumn(visualColumn); - QSpanCollection::Span span = d->span(current.row(), column); - visualRow = d->visualRow(span.top()); - visualColumn = d->visualColumn(span.left()); - } + } + } while (!looped); + if (visualColumn < 0) + visualColumn = originalColumn; break; + } case MoveNext: - if (visualColumn == right) { - visualColumn = 0; - while (visualColumn < right && d->isVisualColumnHiddenOrDisabled(visualRow, visualColumn)) + case MoveRight: { + int originalRow = visualRow; + int originalColumn = visualColumn; + bool firstTime = true; + bool looped = false; + bool wrapped = false; + do { + int r = d->logicalRow(visualRow); + int c = d->logicalColumn(visualColumn); + if (firstTime && c != -1 && d->hasSpans()) { + firstTime = false; + QSpanCollection::Span span = d->span(r, c); + if (span.width() > 1 || span.height() > 1) + visualColumn = d->visualColumn(d->columnSpanEndLogical(span.left(), span.width())); + } + while (visualColumn <= right) { ++visualColumn; - if (visualRow == bottom) + r = d->logicalRow(visualRow); + c = d->logicalColumn(visualColumn); + if (r == -1 || c == -1 || (!isRowHidden(r) && !isColumnHidden(c) && d->isCellEnabled(r, c))) + break; + if (wrapped && (originalRow > visualRow || (originalRow == visualRow && originalColumn >= visualColumn))) { + looped = true; + break; + } + } + if (cursorAction == MoveRight || visualColumn <= right) + break; + visualColumn = -1; + if (visualRow == bottom) { + wrapped = true; visualRow = 0; - else - ++visualRow; - while (visualRow < bottom && d->isVisualRowHiddenOrDisabled(visualRow, visualColumn)) + } else { ++visualRow; - break; - } // else MoveRight - case MoveRight: - if (d->hasSpans()) { - QSpanCollection::Span span = d->span(current.row(), current.column()); - visualColumn = d->visualColumn(d->columnSpanEndLogical(span.left(), span.width())); - } - ++visualColumn; - while (visualColumn < right && d->isVisualColumnHiddenOrDisabled(visualRow, visualColumn)) - ++visualColumn; - if (d->hasSpans()) { - int column = d->logicalColumn(visualColumn); - QSpanCollection::Span span = d->span(current.row(), column); - visualRow = d->visualRow(span.top()); - } + } + } while (!looped); + if (visualColumn > right) + visualColumn = originalColumn; break; + } case MoveHome: visualColumn = 0; while (visualColumn < right && d->isVisualColumnHiddenOrDisabled(visualRow, visualColumn)) @@ -1613,14 +1678,15 @@ QModelIndex QTableView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifi return d->model->index(newRow, current.column(), d->root); }} + d->visualCursor = QPoint(visualColumn, visualRow); int logicalRow = d->logicalRow(visualRow); int logicalColumn = d->logicalColumn(visualColumn); if (!d->model->hasIndex(logicalRow, logicalColumn, d->root)) return QModelIndex(); QModelIndex result = d->model->index(logicalRow, logicalColumn, d->root); - if (!isIndexHidden(result) && d->isIndexEnabled(result)) - return d->model->index(logicalRow, logicalColumn, d->root); + if (!d->isRowHidden(logicalRow) && !d->isColumnHidden(logicalColumn) && d->isIndexEnabled(result)) + return result; return QModelIndex(); } @@ -2375,7 +2441,8 @@ bool QTableView::isCornerButtonEnabled() const QRect QTableView::visualRect(const QModelIndex &index) const { Q_D(const QTableView); - if (!d->isIndexValid(index) || index.parent() != d->root || isIndexHidden(index) ) + if (!d->isIndexValid(index) || index.parent() != d->root + || (!d->hasSpans() && isIndexHidden(index))) return QRect(); d->executePostedLayout(); diff --git a/src/gui/itemviews/qtableview_p.h b/src/gui/itemviews/qtableview_p.h index c785bd7..9fa14c2 100644 --- a/src/gui/itemviews/qtableview_p.h +++ b/src/gui/itemviews/qtableview_p.h @@ -135,7 +135,8 @@ public: rowSectionAnchor(-1), columnSectionAnchor(-1), columnResizeTimerID(0), rowResizeTimerID(0), horizontalHeader(0), verticalHeader(0), - sortingEnabled(false), geometryRecursionBlock(false) + sortingEnabled(false), geometryRecursionBlock(false), + visualCursor(QPoint()) { wrapItemText = true; #ifndef QT_NO_DRAGANDDROP @@ -183,6 +184,7 @@ public: QWidget *cornerWidget; bool sortingEnabled; bool geometryRecursionBlock; + QPoint visualCursor; // (Row,column) cell coordinates to track through span navigation. QSpanCollection spans; diff --git a/src/gui/itemviews/qtablewidget.cpp b/src/gui/itemviews/qtablewidget.cpp index a086498..21c4e0a 100644 --- a/src/gui/itemviews/qtablewidget.cpp +++ b/src/gui/itemviews/qtablewidget.cpp @@ -571,6 +571,8 @@ void QTableModel::ensureSorted(int column, Qt::SortOrder order, colItems.remove(oldRow); vit = sortedInsertionIterator(vit, colItems.end(), order, item); int newRow = qMax((int)(vit - colItems.begin()), 0); + if ((newRow < oldRow) && !(*item < *colItems.at(oldRow - 1)) && !(*colItems.at(oldRow - 1) < *item)) + newRow = oldRow; vit = colItems.insert(vit, item); if (newRow != oldRow) { changed = true; diff --git a/src/gui/itemviews/qtreewidget.cpp b/src/gui/itemviews/qtreewidget.cpp index 06342d8..040c498 100644 --- a/src/gui/itemviews/qtreewidget.cpp +++ b/src/gui/itemviews/qtreewidget.cpp @@ -623,7 +623,7 @@ void QTreeModel::ensureSorted(int column, Qt::SortOrder order, lit = sortedInsertionIterator(lit, lst.end(), order, item); int newRow = qMax(lit - lst.begin(), 0); - if ((newRow < oldRow) && !(*item < *lst.at(oldRow - 1))) + if ((newRow < oldRow) && !(*item < *lst.at(oldRow - 1)) && !(*lst.at(oldRow - 1) < *item )) newRow = oldRow; lit = lst.insert(lit, item); |