hgcacheproxymodel/tsrc/unit/cacheproxyhelper.cpp
changeset 8 15f034b8a3b5
parent 1 e48454f237ca
equal deleted inserted replaced
5:4fa04caf0f43 8:15f034b8a3b5
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 *  Version     : %version: 1 %
    16 *  Version     : %version: 3 %
    17 */
    17 */
    18 #include "cacheproxyhelper.h"
    18 #include "cacheproxyhelper.h"
       
    19 #include <QtTest/QtTest>
       
    20 
    19 
    21 
    20 CacheProxyHelper::CacheProxyHelper(HgCacheProxyModel *model, QObject *parent):
    22 CacheProxyHelper::CacheProxyHelper(HgCacheProxyModel *model, QObject *parent):
    21 QObject(parent),
    23 QObject(parent),
    22 mModel(model)
    24 mModel(model)
    23 {
    25 {
    24     ASSERT(mModel!=0);
    26     ASSERT(mModel!=0);
       
    27     bool res;
    25     
    28     
    26     connect(mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
    29     res = connect(mModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
    27             this, SLOT(slotDataChanged(QModelIndex,QModelIndex)));
    30             this, SLOT(slotDataChanged(QModelIndex,QModelIndex)));
    28     
    31     QCOMPARE(res, true);
    29     connect(mModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
    32 
       
    33     res = connect(mModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
    30             this, SLOT(slotHeaderDataChanged(Qt::Orientation,int,int)));
    34             this, SLOT(slotHeaderDataChanged(Qt::Orientation,int,int)));
    31 
    35     QCOMPARE(res, true);
    32     connect(mModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
    36 
       
    37     res = connect(mModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
    33             this, SLOT(slotRowsAboutToBeInserted(QModelIndex,int,int)));
    38             this, SLOT(slotRowsAboutToBeInserted(QModelIndex,int,int)));
    34 
    39     QCOMPARE(res, true);
    35     connect(mModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
    40 
       
    41     res = connect(mModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
    36             this, SLOT(slotRowsInserted(QModelIndex,int,int)));
    42             this, SLOT(slotRowsInserted(QModelIndex,int,int)));
    37 
    43     QCOMPARE(res, true);
    38     connect(mModel, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
    44 
       
    45     res = connect(mModel, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
    39             this, SLOT(slotColumnsAboutToBeInserted(QModelIndex,int,int)));
    46             this, SLOT(slotColumnsAboutToBeInserted(QModelIndex,int,int)));
    40 
    47     QCOMPARE(res, true);
    41     connect(mModel, SIGNAL(columnsInserted(QModelIndex,int,int)),
    48 
       
    49     res = connect(mModel, SIGNAL(columnsInserted(QModelIndex,int,int)),
    42             this, SLOT(slotColumnsInserted(QModelIndex,int,int)));
    50             this, SLOT(slotColumnsInserted(QModelIndex,int,int)));
    43 
    51     QCOMPARE(res, true);
    44     connect(mModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
    52 
       
    53     res = connect(mModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
    45             this, SLOT(slotRowsAboutToBeRemoved(QModelIndex,int,int)));
    54             this, SLOT(slotRowsAboutToBeRemoved(QModelIndex,int,int)));
    46 
    55     QCOMPARE(res, true);
    47     connect(mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
    56 
       
    57     res = connect(mModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
    48             this, SLOT(slotRowsRemoved(QModelIndex,int,int)));
    58             this, SLOT(slotRowsRemoved(QModelIndex,int,int)));
    49 
    59     QCOMPARE(res, true);
    50     connect(mModel, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
    60 
       
    61     res = connect(mModel, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
    51             this, SLOT(slotColumnsAboutToBeRemoved(QModelIndex,int,int)));
    62             this, SLOT(slotColumnsAboutToBeRemoved(QModelIndex,int,int)));
    52 
    63     QCOMPARE(res, true);
    53     connect(mModel, SIGNAL(columnsRemoved(QModelIndex,int,int)),
    64 
       
    65     res = connect(mModel, SIGNAL(columnsRemoved(QModelIndex,int,int)),
    54             this, SLOT(slotColumnsRemoved(QModelIndex,int,int)));
    66             this, SLOT(slotColumnsRemoved(QModelIndex,int,int)));
    55 
    67     QCOMPARE(res, true);
    56     connect(mModel, SIGNAL(layoutAboutToBeChanged()),
    68 
       
    69     res = connect(mModel, SIGNAL(layoutAboutToBeChanged()),
    57             this, SLOT(slotLayoutAboutToBeChanged()));
    70             this, SLOT(slotLayoutAboutToBeChanged()));
    58 
    71     QCOMPARE(res, true);
    59     connect(mModel, SIGNAL(layoutChanged()), 
    72 
       
    73     res = connect(mModel, SIGNAL(layoutChanged()), 
    60             this, SLOT(slotLayoutChanged()));
    74             this, SLOT(slotLayoutChanged()));
    61 
    75     QCOMPARE(res, true);
    62     connect(mModel, SIGNAL(modelAboutToBeReset()), 
    76 
       
    77     res = connect(mModel, SIGNAL(modelAboutToBeReset()), 
    63             this, SLOT(slotModelAboutToBeReset()));
    78             this, SLOT(slotModelAboutToBeReset()));
    64     
    79     QCOMPARE(res, true);
    65     connect(mModel, SIGNAL(modelReset()), 
    80 
       
    81     res = connect(mModel, SIGNAL(modelReset()), 
    66             this, SLOT(slotModelReset()));	
    82             this, SLOT(slotModelReset()));	
    67     
    83     QCOMPARE(res, true);
       
    84 
       
    85     res = connect(mModel, SIGNAL(rowsAboutToBeMoved(const QModelIndex&, int, int, const QModelIndex&, int)),
       
    86             this, SLOT(slotRowsAboutToBeMoved(const QModelIndex&, int, int, const QModelIndex&, int)));
       
    87     QCOMPARE(res, true);
       
    88 
       
    89     res = connect(mModel, SIGNAL(rowsMoved(const QModelIndex&, int, int, const QModelIndex&, int)),
       
    90             this, SLOT(slotRowsMoved(const QModelIndex&, int, int, const QModelIndex&, int)));
       
    91     QCOMPARE(res, true);
       
    92 
       
    93     res = connect(mModel, SIGNAL(columnsAboutToBeMoved(const QModelIndex&, int, int, const QModelIndex&, int)),
       
    94             this, SLOT(slotColumnsAboutToBeMoved(const QModelIndex&, int, int, const QModelIndex&, int)));
       
    95     QCOMPARE(res, true);
       
    96 
       
    97     res = connect(mModel, SIGNAL(columnsMoved(const QModelIndex&, int, int, const QModelIndex&, int)),
       
    98             this, SLOT(slotColumnsMoved(const QModelIndex&, int, int, const QModelIndex&, int)));
       
    99     QCOMPARE(res, true);
       
   100 
    68 }
   101 }
    69 
   102 
    70 CacheProxyHelper::~CacheProxyHelper()
   103 CacheProxyHelper::~CacheProxyHelper()
    71 {
   104 {
    72     disconnect(mModel);
   105     disconnect(mModel);
   179 void CacheProxyHelper::slotModelReset()
   212 void CacheProxyHelper::slotModelReset()
   180 {
   213 {
   181     mSignalModelReset = true;
   214     mSignalModelReset = true;
   182 }
   215 }
   183 
   216 
       
   217 
       
   218 void CacheProxyHelper::slotRowsAboutToBeMoved(const QModelIndex&, int from, int to, const QModelIndex&, int)
       
   219 {
       
   220     QPair< int, int > p;
       
   221     p.first = from;
       
   222     p.second = to;      
       
   223     mSignalRowsAboutToBeMoved.append(p);
       
   224 }
       
   225 
       
   226 void CacheProxyHelper::slotRowsMoved(const QModelIndex&, int from, int to, const QModelIndex&, int)
       
   227 {
       
   228     QPair< int, int > p;
       
   229     p.first = from;
       
   230     p.second = to;       
       
   231     mSignalRowsMoved.append(p);
       
   232 }
       
   233 
       
   234 void CacheProxyHelper::slotColumnsAboutToBeMoved(const QModelIndex&, int from, int to, const QModelIndex&, int)
       
   235 {
       
   236     QPair< int, int > p;
       
   237     p.first = from;
       
   238     p.second = to;       
       
   239     mSignalColumnsAboutToBeMoved.append(p);
       
   240 }
       
   241 
       
   242 void CacheProxyHelper::slotColumnsMoved(const QModelIndex&, int from, int to, const QModelIndex&, int)
       
   243 {
       
   244     QPair< int, int > p;
       
   245     p.first = from;
       
   246     p.second = to;       
       
   247     mSignalColumnsMoved.append(p);
       
   248 }
       
   249 
   184 QList< QPair< int, int > > CacheProxyHelper::getSignalDataChanged()
   250 QList< QPair< int, int > > CacheProxyHelper::getSignalDataChanged()
   185 {
   251 {
   186     QList< QPair< int, int > > res = mSignalDataChanged;
   252     QList< QPair< int, int > > res = mSignalDataChanged;
   187     mSignalDataChanged.clear();
   253     mSignalDataChanged.clear();
   188     return res;
   254     return res;
   277     bool res = mSignalModelReset;
   343     bool res = mSignalModelReset;
   278     mSignalModelReset = false;
   344     mSignalModelReset = false;
   279     return res;
   345     return res;
   280 }
   346 }
   281 
   347 
   282 
   348 QList< QPair< int, int > > CacheProxyHelper::getSignalRowsAboutToBeMoved()
   283 
   349 {
   284 
   350     QList< QPair< int, int > > res = mSignalRowsAboutToBeMoved;
       
   351     mSignalRowsAboutToBeMoved.clear();
       
   352     return res;
       
   353 }
       
   354 
       
   355 QList< QPair< int, int > > CacheProxyHelper::getSignalRowsMoved()
       
   356 {
       
   357     QList< QPair< int, int > > res = mSignalRowsMoved;
       
   358     mSignalRowsMoved.clear();
       
   359     return res;
       
   360 }
       
   361 
       
   362 QList< QPair< int, int > > CacheProxyHelper::getSignalColumnsAboutToBeMoved()
       
   363 {
       
   364     QList< QPair< int, int > > res = mSignalColumnsAboutToBeMoved;
       
   365     mSignalColumnsAboutToBeMoved.clear();
       
   366     return res;
       
   367 }
       
   368 
       
   369 QList< QPair< int, int > > CacheProxyHelper::getSignalColumnsMoved()
       
   370 {
       
   371     QList< QPair< int, int > > res = mSignalColumnsMoved;
       
   372     mSignalColumnsMoved.clear();
       
   373     return res;
       
   374 }
       
   375 
       
   376