tests/auto/modeltest/tst_modeltest.cpp
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the test suite of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 
       
    43 #include <QtTest/QtTest>
       
    44 #include <QtGui/QtGui>
       
    45 
       
    46 #include "modeltest.h"
       
    47 
       
    48 
       
    49 class tst_ModelTest : public QObject
       
    50 {
       
    51     Q_OBJECT
       
    52 
       
    53 public:
       
    54     tst_ModelTest() {}
       
    55     virtual ~tst_ModelTest() {}
       
    56 
       
    57 public slots:
       
    58     void initTestCase();
       
    59     void cleanupTestCase();
       
    60     void init();
       
    61     void cleanup();
       
    62 
       
    63 private slots:
       
    64     void stringListModel();
       
    65     void treeWidgetModel();
       
    66     void standardItemModel();
       
    67 };
       
    68 
       
    69 
       
    70 
       
    71 void tst_ModelTest::initTestCase()
       
    72 {
       
    73 }
       
    74 
       
    75 void tst_ModelTest::cleanupTestCase()
       
    76 {
       
    77 }
       
    78 
       
    79 void tst_ModelTest::init()
       
    80 {
       
    81 
       
    82 }
       
    83 
       
    84 void tst_ModelTest::cleanup()
       
    85 {
       
    86 }
       
    87 /*
       
    88   tests
       
    89 */
       
    90 
       
    91 void tst_ModelTest::stringListModel()
       
    92 {
       
    93     QStringListModel model;
       
    94     QSortFilterProxyModel proxy;
       
    95     
       
    96     ModelTest t1(&model);
       
    97     ModelTest t2(&proxy);
       
    98     
       
    99     proxy.setSourceModel(&model);
       
   100   
       
   101     model.setStringList(QStringList() << "2" << "3" << "1");
       
   102     model.setStringList(QStringList() << "a" << "e" << "plop" << "b" << "c" );
       
   103     
       
   104     proxy.setDynamicSortFilter(true);
       
   105     proxy.setFilterRegExp(QRegExp("[^b]"));
       
   106 }
       
   107 
       
   108 void tst_ModelTest::treeWidgetModel()
       
   109 {
       
   110     QTreeWidget widget;
       
   111 
       
   112     ModelTest t1(widget.model());
       
   113     
       
   114     QTreeWidgetItem *root = new QTreeWidgetItem(&widget, QStringList("root"));
       
   115     for (int i = 0; i < 20; ++i) {
       
   116         new QTreeWidgetItem(root, QStringList(QString::number(i)));
       
   117     }
       
   118     QTreeWidgetItem *remove = root->child(2);
       
   119     root->removeChild(remove);
       
   120     QTreeWidgetItem *parent = new QTreeWidgetItem(&widget, QStringList("parent"));
       
   121     new QTreeWidgetItem(parent, QStringList("child"));
       
   122     widget.setItemHidden(parent, true);
       
   123     
       
   124     widget.sortByColumn(0);
       
   125 }
       
   126 
       
   127 void tst_ModelTest::standardItemModel()
       
   128 {
       
   129     QStandardItemModel model(10,10);
       
   130     QSortFilterProxyModel proxy;
       
   131     
       
   132     
       
   133     ModelTest t1(&model);
       
   134     ModelTest t2(&proxy);
       
   135     
       
   136     proxy.setSourceModel(&model);
       
   137     
       
   138     model.insertRows(2, 5);
       
   139     model.removeRows(4, 5);
       
   140 
       
   141     model.insertColumns(2, 5);
       
   142     model.removeColumns(4, 5);
       
   143     
       
   144     model.insertRows(0,5, model.index(1,1));
       
   145     model.insertColumns(0,5, model.index(1,3));
       
   146     
       
   147 }
       
   148 
       
   149 QTEST_MAIN(tst_ModelTest)
       
   150 #include "tst_modeltest.moc"