diff options
author | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2009-10-27 10:59:55 (GMT) |
---|---|---|
committer | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2009-10-27 10:59:55 (GMT) |
commit | ca7640ff5e12f9e818d3b8ca38318f0fdcf47e3e (patch) | |
tree | f90d78da363ca65387915d2bcc1eae89e100abd4 /src | |
parent | 8a9ab43e572443eefbf19d59740fdc64d25d1005 (diff) | |
parent | 0f6ab9612eba6c5418991443b65a10820d6b5a1f (diff) | |
download | Qt-ca7640ff5e12f9e818d3b8ca38318f0fdcf47e3e.zip Qt-ca7640ff5e12f9e818d3b8ca38318f0fdcf47e3e.tar.gz Qt-ca7640ff5e12f9e818d3b8ca38318f0fdcf47e3e.tar.bz2 |
Merge branch '4.6' of scm.dev.nokia.troll.no:qt/qt-widget-team into 4.6
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/itemviews/qitemselectionmodel.cpp | 2 | ||||
-rw-r--r-- | src/gui/itemviews/qlistwidget.cpp | 31 | ||||
-rw-r--r-- | src/gui/itemviews/qlistwidget_p.h | 3 | ||||
-rw-r--r-- | src/gui/kernel/qguiplatformplugin.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/qmenu.cpp | 4 | ||||
-rw-r--r-- | src/gui/widgets/qmenubar.cpp | 29 | ||||
-rw-r--r-- | src/sql/models/qsqlquerymodel.cpp | 2 |
7 files changed, 41 insertions, 32 deletions
diff --git a/src/gui/itemviews/qitemselectionmodel.cpp b/src/gui/itemviews/qitemselectionmodel.cpp index dfebe03..f2ccb6e 100644 --- a/src/gui/itemviews/qitemselectionmodel.cpp +++ b/src/gui/itemviews/qitemselectionmodel.cpp @@ -599,7 +599,7 @@ void QItemSelectionModelPrivate::_q_rowsAboutToBeRemoved(const QModelIndex &pare while (itParent.isValid() && itParent.parent() != parent) itParent = itParent.parent(); - if (parent.isValid() && start <= itParent.row() && itParent.row() <= end) { + if (itParent.isValid() && start <= itParent.row() && itParent.row() <= end) { deselected.append(*it); it = ranges.erase(it); } else { diff --git a/src/gui/itemviews/qlistwidget.cpp b/src/gui/itemviews/qlistwidget.cpp index a978d0f..5dd1d76 100644 --- a/src/gui/itemviews/qlistwidget.cpp +++ b/src/gui/itemviews/qlistwidget.cpp @@ -169,6 +169,20 @@ QListWidgetItem *QListModel::take(int row) return item; } +void QListModel::move(int srcRow, int dstRow) +{ + if (srcRow == dstRow + || srcRow < 0 || srcRow >= items.count() + || dstRow < 0 || dstRow >= items.count()) + return; + + beginMoveRows(QModelIndex(), srcRow, srcRow, QModelIndex(), dstRow); + if (srcRow < dstRow) + --dstRow; + items.move(srcRow, dstRow); + endMoveRows(); +} + int QListModel::rowCount(const QModelIndex &parent) const { return parent.isValid() ? 0 : items.count(); @@ -1804,22 +1818,15 @@ void QListWidget::dropEvent(QDropEvent *event) { if (persIndexes.contains(topIndex)) return; + qSort(persIndexes); // The dropped items will remain in the same visual order. QPersistentModelIndex dropRow = model()->index(row, col, topIndex); - QList<QListWidgetItem *> taken; - for (int i = 0; i < persIndexes.count(); ++i) - taken.append(takeItem(persIndexes.at(i).row())); - - // insert them back in at their new positions + int r = row == -1 ? count() : (dropRow.row() >= 0 ? dropRow.row() : row); for (int i = 0; i < persIndexes.count(); ++i) { - // Either at a specific point or appended - if (row == -1) { - insertItem(count(), taken.takeFirst()); - } else { - int r = dropRow.row() >= 0 ? dropRow.row() : row; - insertItem(qMin(r, count()), taken.takeFirst()); - } + const QPersistentModelIndex &pIndex = persIndexes.at(i); + d->listModel()->move(pIndex.row(), r); + r = pIndex.row() + 1; // Dropped items are inserted contiguously and in the right order. } event->accept(); diff --git a/src/gui/itemviews/qlistwidget_p.h b/src/gui/itemviews/qlistwidget_p.h index 69cfa26..b5f28e3 100644 --- a/src/gui/itemviews/qlistwidget_p.h +++ b/src/gui/itemviews/qlistwidget_p.h @@ -77,7 +77,7 @@ public: { return *i2 < *i1; } }; -class QListModel : public QAbstractListModel +class Q_AUTOTEST_EXPORT QListModel : public QAbstractListModel { Q_OBJECT public: @@ -90,6 +90,7 @@ public: void insert(int row, const QStringList &items); void remove(QListWidgetItem *item); QListWidgetItem *take(int row); + void move(int srcRow, int dstRow); int rowCount(const QModelIndex &parent = QModelIndex()) const; diff --git a/src/gui/kernel/qguiplatformplugin.cpp b/src/gui/kernel/qguiplatformplugin.cpp index 6e074a1..b01d40f 100644 --- a/src/gui/kernel/qguiplatformplugin.cpp +++ b/src/gui/kernel/qguiplatformplugin.cpp @@ -288,6 +288,8 @@ int QGuiPlatformPlugin::platformHint(PlatformHint hint) #endif //by default keep ret = 0 so QCommonStyle will use the style default break; + default: + break; } return ret; } diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index ea25901..1b5d1cd 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -1878,6 +1878,10 @@ void QMenu::popup(const QPoint &p, QAction *atAction) if(snapToMouse) //position flowing left from the mouse pos.setX(mouse.x()-size.width()); + //if in a menubar, it should be right-aligned + if (qobject_cast<QMenuBar*>(d->causedPopup.widget)) + pos.rx() -= size.width(); + if (pos.x() < screen.left()+desktopFrame) pos.setX(qMax(p.x(), screen.left()+desktopFrame)); if (pos.x()+size.width()-1 > screen.right()-desktopFrame) diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp index f2f0722..689d2e1 100644 --- a/src/gui/widgets/qmenubar.cpp +++ b/src/gui/widgets/qmenubar.cpp @@ -336,30 +336,25 @@ void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst) const bool fitUp = (q->mapToGlobal(adjustedActionRect.topLeft()).y() >= popup_size.height()); const bool fitDown = (pos.y() + popup_size.height() <= screenRect.bottom()); + const bool rtl = q->isRightToLeft(); const int actionWidth = adjustedActionRect.width(); if (!fitUp && !fitDown) { //we should shift the menu - bool shouldShiftToRight = !q->isRightToLeft(); - if (q->isRightToLeft() && popup_size.width() > pos.x()) + bool shouldShiftToRight = !rtl; + if (rtl && popup_size.width() > pos.x()) shouldShiftToRight = true; else if (actionWidth + popup_size.width() + pos.x() > screenRect.right()) shouldShiftToRight = false; - if (shouldShiftToRight) - pos.rx() += actionWidth; - else - pos.rx() -= popup_size.width(); - } else if (q->isRightToLeft()) { - pos.setX(pos.x()-(popup_size.width() - actionWidth)); - } - - if(pos.x() < screenRect.x()) { - pos.setX(screenRect.x()); - } else { - const int off = pos.x()+popup_size.width() - screenRect.right(); - if(off > 0) - pos.setX(qMax(screenRect.x(), pos.x()-off)); - + if (shouldShiftToRight) { + pos.rx() += actionWidth + (rtl ? popup_size.width() : 0); + } else { + //shift to left + if (!rtl) + pos.rx() -= popup_size.width(); + } + } else if (rtl) { + pos.rx() += actionWidth; } if(!defaultPopDown || (fitUp && !fitDown)) diff --git a/src/sql/models/qsqlquerymodel.cpp b/src/sql/models/qsqlquerymodel.cpp index a72ad8c..1719239 100644 --- a/src/sql/models/qsqlquerymodel.cpp +++ b/src/sql/models/qsqlquerymodel.cpp @@ -417,7 +417,7 @@ bool QSqlQueryModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) { Q_D(QSqlQueryModel); - if (orientation != Qt::Horizontal || section < 0) + if (orientation != Qt::Horizontal || section < 0 || columnCount() <= section) return false; if (d->headers.size() <= section) |