tests/auto/qtableview/tst_qtableview.cpp
changeset 7 f7bc934e204c
parent 3 41300fa6a67c
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the test suite of the Qt Toolkit.
     7 ** This file is part of the test suite of the Qt Toolkit.
     8 **
     8 **
   197     void task259308_scrollVerticalHeaderSwappedSections();
   197     void task259308_scrollVerticalHeaderSwappedSections();
   198     void task191545_dragSelectRows();
   198     void task191545_dragSelectRows();
   199     void taskQTBUG_5062_spansInconsistency();
   199     void taskQTBUG_5062_spansInconsistency();
   200     void taskQTBUG_4516_clickOnRichTextLabel();
   200     void taskQTBUG_4516_clickOnRichTextLabel();
   201     void taskQTBUG_5237_wheelEventOnHeader();
   201     void taskQTBUG_5237_wheelEventOnHeader();
       
   202     void taskQTBUG_8585_crashForNoGoodReason();
       
   203     void taskQTBUG_7774_RtoLVisualRegionForSelection();
       
   204     void taskQTBUG_8777_scrollToSpans();
   202 
   205 
   203     void mouseWheel_data();
   206     void mouseWheel_data();
   204     void mouseWheel();
   207     void mouseWheel();
   205 
   208 
   206     void addColumnWhileEditing();
   209     void addColumnWhileEditing();
  3022       << (SpanList() << QRect(0, 0, 2, 2) << QRect(0, 0, 1, 1))
  3025       << (SpanList() << QRect(0, 0, 2, 2) << QRect(0, 0, 1, 1))
  3023       << false
  3026       << false
  3024       << QPoint(0, 0)
  3027       << QPoint(0, 0)
  3025       << 1
  3028       << 1
  3026       << 1;
  3029       << 1;
       
  3030 
       
  3031     QTest::newRow("QTBUG-6004 (follow-up): No failing Q_ASSERT, then it passes.")
       
  3032       << 10 << 10
       
  3033       << (SpanList() << QRect(2, 2, 1, 3) << QRect(2, 2, 1, 1))
       
  3034       << false
       
  3035       << QPoint(0, 0)
       
  3036       << 1
       
  3037       << 1;
  3027 }
  3038 }
  3028 
  3039 
  3029 void tst_QTableView::spans()
  3040 void tst_QTableView::spans()
  3030 {
  3041 {
  3031     QFETCH(int, rows);
  3042     QFETCH(int, rows);
  3938     QApplication::sendEvent(header->viewport(), &wheelEvent);
  3949     QApplication::sendEvent(header->viewport(), &wheelEvent);
  3939     int sbValueAfter = view.verticalScrollBar()->value();
  3950     int sbValueAfter = view.verticalScrollBar()->value();
  3940     QVERIFY(sbValueBefore != sbValueAfter);
  3951     QVERIFY(sbValueBefore != sbValueAfter);
  3941 }
  3952 }
  3942 
  3953 
       
  3954 class TestTableView : public QTableView {
       
  3955 Q_OBJECT
       
  3956 public:
       
  3957     TestTableView(QWidget *parent = 0) : QTableView(parent)
       
  3958     {
       
  3959         connect(this, SIGNAL(entered(const QModelIndex&)), this, SLOT(openEditor(const QModelIndex&)));
       
  3960     }
       
  3961     ~TestTableView(){}
       
  3962 public slots:
       
  3963     void onDataChanged()
       
  3964     {
       
  3965         for (int i = 0; i < model()->rowCount(); i++) {
       
  3966             setRowHidden(i, model()->data(model()->index(i, 0)).toBool());
       
  3967         }
       
  3968     }
       
  3969 
       
  3970     void openEditor(const QModelIndex& index)
       
  3971     { openPersistentEditor(index); }
       
  3972 };
       
  3973 
       
  3974 
       
  3975 void tst_QTableView::taskQTBUG_8585_crashForNoGoodReason()
       
  3976 {
       
  3977     QStandardItemModel model;
       
  3978     model.insertColumn(0, QModelIndex());
       
  3979     for(int i = 0; i < 20; i++)
       
  3980     {
       
  3981         model.insertRow(i);
       
  3982     }
       
  3983 
       
  3984     TestTableView w;
       
  3985     w.setMouseTracking(true);
       
  3986     w.setModel(&model);
       
  3987     connect(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), &w, SLOT(onDataChanged()));
       
  3988     w.show();
       
  3989     QTest::qWaitForWindowShown(&w);
       
  3990     for (int i = 0; i < 10; i++)
       
  3991     {
       
  3992         QTest::mouseMove(w.viewport(), QPoint(50, 20));
       
  3993         w.model()->setData(w.indexAt(QPoint(50, 20)), true);
       
  3994         QTest::mouseMove(w.viewport(), QPoint(50, 25));
       
  3995     }
       
  3996 }
       
  3997 
       
  3998 class TableView7774 : public QTableView
       
  3999 {
       
  4000 public:
       
  4001     QRegion visualRegionForSelection(const QItemSelection &selection) const
       
  4002     {
       
  4003         return QTableView::visualRegionForSelection(selection);
       
  4004     }
       
  4005 };
       
  4006 
       
  4007 void tst_QTableView::taskQTBUG_7774_RtoLVisualRegionForSelection()
       
  4008 {
       
  4009     TableView7774 view;
       
  4010     QStandardItemModel model(5,5);
       
  4011     view.setModel(&model);
       
  4012     view.setLayoutDirection(Qt::RightToLeft);
       
  4013     view.show();
       
  4014     QTest::qWaitForWindowShown(&view);
       
  4015 
       
  4016     QItemSelectionRange range(model.index(2, 0), model.index(2, model.columnCount() - 1));
       
  4017     QItemSelection selection;
       
  4018     selection << range;
       
  4019     QRegion region = view.visualRegionForSelection(selection);
       
  4020     QCOMPARE(region.rects().at(0), view.visualRect(range.topLeft()) | view.visualRect(range.bottomRight()));
       
  4021 }
       
  4022 
       
  4023 void tst_QTableView::taskQTBUG_8777_scrollToSpans()
       
  4024 {
       
  4025     QTableWidget table(75,5);
       
  4026     for (int i=0; i<50; i++)
       
  4027         table.setSpan(2+i, 0, 1, 5);
       
  4028     table.setCurrentCell(0,2);
       
  4029     table.show();
       
  4030 
       
  4031     for (int i = 0; i < 45; ++i)
       
  4032         QTest::keyClick(&table, Qt::Key_Down);
       
  4033 
       
  4034     QVERIFY(table.verticalScrollBar()->value() > 10);
       
  4035 }
       
  4036 
  3943 QTEST_MAIN(tst_QTableView)
  4037 QTEST_MAIN(tst_QTableView)
  3944 #include "tst_qtableview.moc"
  4038 #include "tst_qtableview.moc"