diff options
author | David Boddie <dboddie@trolltech.com> | 2009-07-17 14:47:49 (GMT) |
---|---|---|
committer | David Boddie <dboddie@trolltech.com> | 2009-07-17 14:47:49 (GMT) |
commit | c0a9fe18baec3c0ea1f37326ef5a7f527511c33c (patch) | |
tree | 5cf0aea1d402264536b58ad5ae69f9c42d0975fd /tests | |
parent | bffc7a79c71ddebf4048242aa65173615d69030c (diff) | |
parent | 7febf8c3eb21e5681b71910fcd08b2933ba82464 (diff) | |
download | Qt-c0a9fe18baec3c0ea1f37326ef5a7f527511c33c.zip Qt-c0a9fe18baec3c0ea1f37326ef5a7f527511c33c.tar.gz Qt-c0a9fe18baec3c0ea1f37326ef5a7f527511c33c.tar.bz2 |
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qabstractitemview/tst_qabstractitemview.cpp | 83 | ||||
-rw-r--r-- | tests/auto/qaction/tst_qaction.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qcompleter/tst_qcompleter.cpp | 68 | ||||
-rw-r--r-- | tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp | 15 | ||||
-rw-r--r-- | tests/auto/qtoolbutton/tst_qtoolbutton.cpp | 27 | ||||
-rw-r--r-- | tests/manual/qdesktopwidget/main.cpp | 188 | ||||
-rw-r--r-- | tests/manual/qdesktopwidget/qdesktopwidget.pro | 2 |
7 files changed, 357 insertions, 30 deletions
diff --git a/tests/auto/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/qabstractitemview/tst_qabstractitemview.cpp index 0bc459e..e7b94d1 100644 --- a/tests/auto/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/qabstractitemview/tst_qabstractitemview.cpp @@ -55,6 +55,7 @@ #include <qpushbutton.h> #include <qscrollbar.h> #include <qboxlayout.h> +#include <qlineedit.h> #include "../../shared/util.h" //TESTED_CLASS= @@ -209,10 +210,11 @@ private slots: void noFallbackToRoot(); void setCurrentIndex_data(); void setCurrentIndex(); - + void task221955_selectedEditor(); void task250754_fontChange(); void task200665_itemEntered(); + void task257481_emptyEditor(); }; class MyAbstractItemDelegate : public QAbstractItemDelegate @@ -945,12 +947,12 @@ void tst_QAbstractItemView::dragAndDropOnChild() class TestModel : public QStandardItemModel { public: - TestModel(int rows, int columns) : QStandardItemModel(rows, columns) + TestModel(int rows, int columns) : QStandardItemModel(rows, columns) { setData_count = 0; } - virtual bool setData(const QModelIndex &/*index*/, const QVariant &/*value*/, int /*role = Qt::EditRole*/) + virtual bool setData(const QModelIndex &/*index*/, const QVariant &/*value*/, int /*role = Qt::EditRole*/) { ++setData_count; return true; @@ -967,20 +969,20 @@ void tst_QAbstractItemView::setItemDelegate_data() // default is rows, a -1 will switch to columns QTest::addColumn<IntList>("rowsOrColumnsWithDelegate"); QTest::addColumn<QPoint>("cellToEdit"); - QTest::newRow("4 columndelegates") - << (IntList() << -1 << 0 << 1 << 2 << 3) + QTest::newRow("4 columndelegates") + << (IntList() << -1 << 0 << 1 << 2 << 3) << QPoint(0, 0); - QTest::newRow("2 identical rowdelegates on the same row") - << (IntList() << 0 << 0) + QTest::newRow("2 identical rowdelegates on the same row") + << (IntList() << 0 << 0) << QPoint(0, 0); - QTest::newRow("2 identical columndelegates on the same column") - << (IntList() << -1 << 2 << 2) + QTest::newRow("2 identical columndelegates on the same column") + << (IntList() << -1 << 2 << 2) << QPoint(2, 0); - QTest::newRow("2 duplicate delegates, 1 row and 1 column") - << (IntList() << 0 << -1 << 2) + QTest::newRow("2 duplicate delegates, 1 row and 1 column") + << (IntList() << 0 << -1 << 2) << QPoint(2, 0); - QTest::newRow("4 duplicate delegates, 2 row and 2 column") - << (IntList() << 0 << 0 << -1 << 2 << 2) + QTest::newRow("4 duplicate delegates, 2 row and 2 column") + << (IntList() << 0 << 0 << -1 << 2 << 2) << QPoint(2, 0); } @@ -1002,7 +1004,7 @@ void tst_QAbstractItemView::setItemDelegate() if (row) { v.setItemDelegateForRow(rc, delegate); } else { - v.setItemDelegateForColumn(rc, delegate); + v.setItemDelegateForColumn(rc, delegate); } } } @@ -1120,42 +1122,42 @@ void tst_QAbstractItemView::setCurrentIndex() void tst_QAbstractItemView::task221955_selectedEditor() { QPushButton *button; - + QTreeWidget tree; tree.setColumnCount(2); tree.addTopLevelItem(new QTreeWidgetItem(QStringList() << "Foo" <<"1")); tree.addTopLevelItem(new QTreeWidgetItem(QStringList() << "Bar" <<"2")); tree.addTopLevelItem(new QTreeWidgetItem(QStringList() << "Baz" <<"3")); - + QTreeWidgetItem *dummy = new QTreeWidgetItem(); tree.addTopLevelItem(dummy); tree.setItemWidget(dummy, 0, button = new QPushButton("More...")); button->setAutoFillBackground(true); // as recommended in doc - + tree.show(); tree.setFocus(); tree.setCurrentIndex(tree.model()->index(1,0)); QTest::qWait(100); QApplication::setActiveWindow(&tree); - + QVERIFY(! tree.selectionModel()->selectedIndexes().contains(tree.model()->index(3,0))); //We set the focus to the button, the index need to be selected - button->setFocus(); + button->setFocus(); QTest::qWait(100); QVERIFY(tree.selectionModel()->selectedIndexes().contains(tree.model()->index(3,0))); - + tree.setCurrentIndex(tree.model()->index(1,0)); QVERIFY(! tree.selectionModel()->selectedIndexes().contains(tree.model()->index(3,0))); - + //Same thing but with the flag NoSelection, nothing can be selected. tree.setFocus(); tree.setSelectionMode(QAbstractItemView::NoSelection); tree.clearSelection(); QVERIFY(tree.selectionModel()->selectedIndexes().isEmpty()); QTest::qWait(10); - button->setFocus(); + button->setFocus(); QTest::qWait(50); QVERIFY(tree.selectionModel()->selectedIndexes().isEmpty()); } @@ -1196,7 +1198,7 @@ void tst_QAbstractItemView::task250754_fontChange() QTest::qWait(30); //now with the huge items, the scrollbar must be visible QVERIFY(tree.verticalScrollBar()->isVisible()); - + qApp->setStyleSheet(app_css); } @@ -1217,6 +1219,41 @@ void tst_QAbstractItemView::task200665_itemEntered() } +void tst_QAbstractItemView::task257481_emptyEditor() +{ + QIcon icon = qApp->style()->standardIcon(QStyle::SP_ComputerIcon); + + QStandardItemModel model; + + model.appendRow( new QStandardItem(icon, QString()) ); + model.appendRow( new QStandardItem(icon, "Editor works") ); + model.appendRow( new QStandardItem( QString() ) ); + + QTreeView treeView; + treeView.setRootIsDecorated(false); + treeView.setModel(&model); + treeView.show(); + + treeView.edit(model.index(0,0)); + QList<QLineEdit *> lineEditors = qFindChildren<QLineEdit *>(treeView.viewport()); + QCOMPARE(lineEditors.count(), 1); + QVERIFY(!lineEditors.first()->size().isEmpty()); + + QTest::qWait(30); + + treeView.edit(model.index(1,0)); + lineEditors = qFindChildren<QLineEdit *>(treeView.viewport()); + QCOMPARE(lineEditors.count(), 1); + QVERIFY(!lineEditors.first()->size().isEmpty()); + + QTest::qWait(30); + + treeView.edit(model.index(2,0)); + lineEditors = qFindChildren<QLineEdit *>(treeView.viewport()); + QCOMPARE(lineEditors.count(), 1); + QVERIFY(!lineEditors.first()->size().isEmpty()); +} + QTEST_MAIN(tst_QAbstractItemView) #include "tst_qabstractitemview.moc" diff --git a/tests/auto/qaction/tst_qaction.cpp b/tests/auto/qaction/tst_qaction.cpp index 452ca58..3c71baf 100644 --- a/tests/auto/qaction/tst_qaction.cpp +++ b/tests/auto/qaction/tst_qaction.cpp @@ -105,6 +105,10 @@ void tst_QAction::getSetCheck() obj1.setMenu((QMenu *)0); QCOMPARE((QMenu *)0, obj1.menu()); delete var2; + + QCOMPARE(obj1.priority(), QAction::NormalPriority); + obj1.setPriority(QAction::LowPriority); + QCOMPARE(obj1.priority(), QAction::LowPriority); } class MyWidget : public QWidget diff --git a/tests/auto/qcompleter/tst_qcompleter.cpp b/tests/auto/qcompleter/tst_qcompleter.cpp index fb03e1a..0a9c16a 100644 --- a/tests/auto/qcompleter/tst_qcompleter.cpp +++ b/tests/auto/qcompleter/tst_qcompleter.cpp @@ -102,6 +102,8 @@ public: ~tst_QCompleter(); private slots: + void getSetCheck(); + void multipleWidgets(); void focusIn(); @@ -268,6 +270,72 @@ void tst_QCompleter::filter() QCOMPARE(completer->currentCompletion(), completionText); } +// Testing get/set functions +void tst_QCompleter::getSetCheck() +{ + QStandardItemModel model(3,3); + QCompleter completer(&model); + + // QString QCompleter::completionPrefix() + // void QCompleter::setCompletionPrefix(QString) + completer.setCompletionPrefix(QString("te")); + QCOMPARE(completer.completionPrefix(), QString("te")); + completer.setCompletionPrefix(QString()); + QCOMPARE(completer.completionPrefix(), QString()); + + // ModelSorting QCompleter::modelSorting() + // void QCompleter::setModelSorting(ModelSorting) + completer.setModelSorting(QCompleter::CaseSensitivelySortedModel); + QCOMPARE(completer.modelSorting(), QCompleter::CaseSensitivelySortedModel); + completer.setModelSorting(QCompleter::CaseInsensitivelySortedModel); + QCOMPARE(completer.modelSorting(), QCompleter::CaseInsensitivelySortedModel); + completer.setModelSorting(QCompleter::UnsortedModel); + QCOMPARE(completer.modelSorting(), QCompleter::UnsortedModel); + + // CompletionMode QCompleter::completionMode() + // void QCompleter::setCompletionMode(CompletionMode) + QCOMPARE(completer.completionMode(), QCompleter::PopupCompletion); // default value + completer.setCompletionMode(QCompleter::UnfilteredPopupCompletion); + QCOMPARE(completer.completionMode(), QCompleter::UnfilteredPopupCompletion); + completer.setCompletionMode(QCompleter::InlineCompletion); + QCOMPARE(completer.completionMode(), QCompleter::InlineCompletion); + + // int QCompleter::completionColumn() + // void QCompleter::setCompletionColumn(int) + completer.setCompletionColumn(2); + QCOMPARE(completer.completionColumn(), 2); + completer.setCompletionColumn(1); + QCOMPARE(completer.completionColumn(), 1); + + // int QCompleter::completionRole() + // void QCompleter::setCompletionRole(int) + QCOMPARE(completer.completionRole(), static_cast<int>(Qt::EditRole)); // default value + completer.setCompletionRole(Qt::DisplayRole); + QCOMPARE(completer.completionRole(), static_cast<int>(Qt::DisplayRole)); + + // int QCompleter::maxVisibleItems() + // void QCompleter::setMaxVisibleItems(int) + QCOMPARE(completer.maxVisibleItems(), 7); // default value + completer.setMaxVisibleItems(10); + QCOMPARE(completer.maxVisibleItems(), 10); + QTest::ignoreMessage(QtWarningMsg, "QCompleter::setMaxVisibleItems: " + "Invalid max visible items (-2147483648) must be >= 0"); + completer.setMaxVisibleItems(INT_MIN); + QCOMPARE(completer.maxVisibleItems(), 10); // Cannot be set to something negative => old value + + // Qt::CaseSensitivity QCompleter::caseSensitivity() + // void QCompleter::setCaseSensitivity(Qt::CaseSensitivity) + QCOMPARE(completer.caseSensitivity(), Qt::CaseSensitive); // default value + completer.setCaseSensitivity(Qt::CaseInsensitive); + QCOMPARE(completer.caseSensitivity(), Qt::CaseInsensitive); + + // bool QCompleter::wrapAround() + // void QCompleter::setWrapAround(bool) + QCOMPARE(completer.wrapAround(), true); // default value + completer.setWrapAround(false); + QCOMPARE(completer.wrapAround(), false); +} + void tst_QCompleter::csMatchingOnCsSortedModel_data() { delete completer; diff --git a/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp b/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp index e116624..aa0705d 100644 --- a/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp +++ b/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp @@ -244,8 +244,8 @@ void tst_QHttpNetworkConnection::get() QByteArray ba; do { QCoreApplication::instance()->processEvents(); - if (reply->bytesAvailable()) - ba += reply->read(); + while (reply->bytesAvailable()) + ba += reply->readAny(); if (stopWatch.elapsed() >= 30000) break; } while (!reply->isFinished()); @@ -327,7 +327,8 @@ void tst_QHttpNetworkConnection::put() if (reply->isFinished()) { QByteArray ba; - ba += reply->read(); + while (reply->bytesAvailable()) + ba += reply->readAny(); } else if(finishedWithErrorCalled) { if(!succeed) { delete reply; @@ -417,8 +418,8 @@ void tst_QHttpNetworkConnection::post() QByteArray ba; do { QCoreApplication::instance()->processEvents(); - if (reply->bytesAvailable()) - ba += reply->read(); + while (reply->bytesAvailable()) + ba += reply->readAny(); if (stopWatch.elapsed() >= 30000) break; } while (!reply->isFinished()); @@ -616,8 +617,8 @@ void tst_QHttpNetworkConnection::compression() QByteArray ba; do { QCoreApplication::instance()->processEvents(); - if (reply->bytesAvailable()) - ba += reply->read(); + while (reply->bytesAvailable()) + ba += reply->readAny(); if (stopWatch.elapsed() >= 30000) break; } while (!reply->isFinished()); diff --git a/tests/auto/qtoolbutton/tst_qtoolbutton.cpp b/tests/auto/qtoolbutton/tst_qtoolbutton.cpp index 9e342ad..4176507 100644 --- a/tests/auto/qtoolbutton/tst_qtoolbutton.cpp +++ b/tests/auto/qtoolbutton/tst_qtoolbutton.cpp @@ -64,6 +64,7 @@ public: private slots: void getSetCheck(); void triggered(); + void collapseTextOnPriority(); void task230994_iconSize(); void task176137_autoRepeatOfAction(); @@ -160,6 +161,32 @@ void tst_QToolButton::triggered() delete menu; } +void tst_QToolButton::collapseTextOnPriority() +{ + class MyToolButton : public QToolButton + { + friend class tst_QToolButton; + public: + void initStyleOption(QStyleOptionToolButton *option) + { + QToolButton::initStyleOption(option); + } + }; + + MyToolButton button; + button.setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + QAction action(button.style()->standardIcon(QStyle::SP_ArrowBack), "test", 0); + button.setDefaultAction(&action); + + QStyleOptionToolButton option; + button.initStyleOption(&option); + QVERIFY(option.toolButtonStyle == Qt::ToolButtonTextBesideIcon); + action.setPriority(QAction::LowPriority); + button.initStyleOption(&option); + QVERIFY(option.toolButtonStyle == Qt::ToolButtonIconOnly); +} + + void tst_QToolButton::task230994_iconSize() { //we check that the iconsize returned bu initStyleOption is valid diff --git a/tests/manual/qdesktopwidget/main.cpp b/tests/manual/qdesktopwidget/main.cpp new file mode 100644 index 0000000..1afc82e --- /dev/null +++ b/tests/manual/qdesktopwidget/main.cpp @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +class DesktopView : public QGraphicsView +{ + Q_OBJECT +public: + DesktopView() + : that(0) + { + scene = new QGraphicsScene; + setScene(scene); + + QDesktopWidget *desktop = QApplication::desktop(); + connect(desktop, SIGNAL(resized(int)), this, SLOT(updateScene())); + connect(desktop, SIGNAL(workAreaResized(int)), this, SLOT(updateScene())); + connect(desktop, SIGNAL(screenCountChanged(int)), this, SLOT(updateScene())); + + updateScene(); + + QTransform transform; + transform.scale(0.25, 0.25); + setTransform(transform); + + setBackgroundBrush(Qt::darkGray); + } + +protected: + void moveEvent(QMoveEvent *e) + { + if (that) { + that->setRect(appRect()); + scene->update(); + } + QGraphicsView::moveEvent(e); + } + void resizeEvent(QResizeEvent *e) + { + if (that) { + that->setRect(appRect()); + } + QGraphicsView::resizeEvent(e); + } + +private slots: + void updateScene() + { + scene->clear(); + + const QDesktopWidget *desktop = QApplication::desktop(); + const bool isVirtualDesktop = desktop->isVirtualDesktop(); + const int homeScreen = desktop->screenNumber(this); + + QRect sceneRect; + int screenCount = desktop->screenCount(); + for (int s = 0; s < screenCount; ++s) { + const bool isPrimary = desktop->primaryScreen() == s; + const QRect screenRect = desktop->screenGeometry(s); + const QRect workRect = desktop->availableGeometry(s); + const QBrush fillBrush = palette().brush(isPrimary ? QPalette::Active : QPalette::Inactive, QPalette::Highlight); + QGraphicsRectItem *screen = new QGraphicsRectItem(0, 0, screenRect.width(), screenRect.height()); + + if (isVirtualDesktop) { + thatRoot = QPoint(); + screen->setPos(screenRect.x(), screenRect.y()); + } else { + // for non-virtual desktops we assume that screens are + // simply next to each other + if (s) + screen->setPos(sceneRect.right(), 0); + if (s == homeScreen) + thatRoot = screen->pos().toPoint(); + } + + screen->setBrush(fillBrush); + scene->addItem(screen); + sceneRect.setLeft(qMin(sceneRect.left(), screenRect.left())); + sceneRect.setRight(qMax(sceneRect.right(), screenRect.right())); + sceneRect.setTop(qMin(sceneRect.top(), screenRect.top())); + sceneRect.setBottom(qMax(sceneRect.bottom(), screenRect.bottom())); + + QGraphicsRectItem *workArea = new QGraphicsRectItem(screen); + workArea->setRect(0, 0, workRect.width(), workRect.height()); + workArea->setPos(workRect.x() - screenRect.x(), workRect.y() - screenRect.y()); + workArea->setBrush(Qt::white); + + QGraphicsSimpleTextItem *screenNumber = new QGraphicsSimpleTextItem(workArea); + screenNumber->setText(QString::number(s)); + screenNumber->setPen(QPen(Qt::black, 1)); + screenNumber->setBrush(fillBrush); + screenNumber->setFont(QFont("Arial Black", 18)); + screenNumber->setTransform(QTransform().scale(10, 10)); + screenNumber->setTransformOrigin(screenNumber->boundingRect().center()); + QSizeF center = (workRect.size() - screenNumber->boundingRect().size()) / 2; + screenNumber->setPos(center.width(), center.height()); + + screen->show(); + screen->setZValue(1); + } + + if (isVirtualDesktop) { + QGraphicsRectItem *virtualDesktop = new QGraphicsRectItem; + virtualDesktop->setRect(sceneRect); + virtualDesktop->setPen(QPen(Qt::black)); + virtualDesktop->setBrush(Qt::DiagCrossPattern); + scene->addItem(virtualDesktop); + virtualDesktop->setZValue(-1); + virtualDesktop->show(); + } + + that = new QGraphicsRectItem; + that->setBrush(Qt::red); + that->setOpacity(0.5); + that->setZValue(2); + that->setRect(appRect()); + that->show(); + scene->addItem(that); + + scene->setSceneRect(sceneRect); + scene->update(); + } + + QRect appRect() const + { + QRect rect = frameGeometry(); + if (!QApplication::desktop()->isVirtualDesktop()) { + rect.translate(thatRoot); + } + return rect; + } + +private: + QGraphicsScene *scene; + QGraphicsRectItem *that; + QPoint thatRoot; +}; + +#include "main.moc" + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + DesktopView view; + view.show(); + + return app.exec(); +} diff --git a/tests/manual/qdesktopwidget/qdesktopwidget.pro b/tests/manual/qdesktopwidget/qdesktopwidget.pro new file mode 100644 index 0000000..93d56eb --- /dev/null +++ b/tests/manual/qdesktopwidget/qdesktopwidget.pro @@ -0,0 +1,2 @@ +TEMPLATE = app +SOURCES += main.cpp |