mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-03 15:55:27 +08:00
6.5.3 clean
This commit is contained in:
@ -225,7 +225,7 @@ void tst_QAbstractProxyModel::headerDataInBounds()
|
||||
|
||||
QCOMPARE(proxy.rowCount(), 1);
|
||||
QCOMPARE(proxy.columnCount(), 5);
|
||||
QCOMPARE(headerDataChangedSpy.size(), 1);
|
||||
QTRY_COMPARE(headerDataChangedSpy.size(), 1);
|
||||
QCOMPARE(headerDataChangedSpy[0][0].value<Qt::Orientation>(), Qt::Horizontal);
|
||||
QCOMPARE(headerDataChangedSpy[0][1].value<int>(), 0);
|
||||
QCOMPARE(headerDataChangedSpy[0][2].value<int>(), 4);
|
||||
@ -266,7 +266,7 @@ void tst_QAbstractProxyModel::headerDataInBounds()
|
||||
|
||||
QCOMPARE(proxy.rowCount(), 0);
|
||||
QCOMPARE(proxy.columnCount(), 5);
|
||||
QCOMPARE(headerDataChangedSpy.size(), 2);
|
||||
QTRY_COMPARE(headerDataChangedSpy.size(), 2);
|
||||
QCOMPARE(headerDataChangedSpy[1][0].value<Qt::Orientation>(), Qt::Horizontal);
|
||||
QCOMPARE(headerDataChangedSpy[1][1].value<int>(), 0);
|
||||
QCOMPARE(headerDataChangedSpy[1][2].value<int>(), 4);
|
||||
@ -610,7 +610,7 @@ void tst_QAbstractProxyModel::sourceModelBinding()
|
||||
SubQAbstractProxyModel proxy;
|
||||
QStandardItemModel model1;
|
||||
QStandardItemModel model2;
|
||||
QTestPrivate::testReadWritePropertyBasics<QAbstractProxyModel, QAbstractItemModel *>(
|
||||
QTestPrivate::testReadWritePropertyBasics<SubQAbstractProxyModel, QAbstractItemModel *>(
|
||||
proxy, &model1, &model2, "sourceModel");
|
||||
if (QTest::currentTestFailed()) {
|
||||
qDebug("Failed model - model test");
|
||||
@ -618,7 +618,7 @@ void tst_QAbstractProxyModel::sourceModelBinding()
|
||||
}
|
||||
|
||||
proxy.setSourceModel(&model2);
|
||||
QTestPrivate::testReadWritePropertyBasics<QAbstractProxyModel, QAbstractItemModel *>(
|
||||
QTestPrivate::testReadWritePropertyBasics<SubQAbstractProxyModel, QAbstractItemModel *>(
|
||||
proxy, &model1, nullptr, "sourceModel");
|
||||
if (QTest::currentTestFailed()) {
|
||||
qDebug("Failed model - nullptr test");
|
||||
@ -626,7 +626,7 @@ void tst_QAbstractProxyModel::sourceModelBinding()
|
||||
}
|
||||
|
||||
proxy.setSourceModel(&model1);
|
||||
QTestPrivate::testReadWritePropertyBasics<QAbstractProxyModel, QAbstractItemModel *>(
|
||||
QTestPrivate::testReadWritePropertyBasics<SubQAbstractProxyModel, QAbstractItemModel *>(
|
||||
proxy, nullptr, &model2, "sourceModel");
|
||||
if (QTest::currentTestFailed()) {
|
||||
qDebug("Failed nullptr - model test");
|
||||
|
@ -80,7 +80,11 @@ private slots:
|
||||
|
||||
void QTBUG93305();
|
||||
|
||||
void testSignalsDisconnection();
|
||||
void destroyModel();
|
||||
|
||||
private:
|
||||
static void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
|
||||
QAbstractItemModel *model;
|
||||
QItemSelectionModel *selection;
|
||||
};
|
||||
@ -2917,5 +2921,53 @@ void tst_QItemSelectionModel::QTBUG93305()
|
||||
QCOMPARE(spy.size(), 4);
|
||||
}
|
||||
|
||||
static void (*oldMessageHandler)(QtMsgType, const QMessageLogContext&, const QString&);
|
||||
static bool signalError = false;
|
||||
|
||||
// detect disconnect warning:
|
||||
// qt.core.qobject.connect: QObject::disconnect: No such signal
|
||||
void tst_QItemSelectionModel::messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||
{
|
||||
Q_ASSERT(oldMessageHandler);
|
||||
|
||||
if (type == QtWarningMsg
|
||||
&& QString(context.category) == "qt.core.qobject.connect"
|
||||
&& msg.contains("No such")) {
|
||||
signalError = true;
|
||||
}
|
||||
|
||||
return oldMessageHandler(type, context, msg);
|
||||
}
|
||||
|
||||
void tst_QItemSelectionModel::testSignalsDisconnection()
|
||||
{
|
||||
oldMessageHandler = qInstallMessageHandler(messageHandler);
|
||||
auto resetMessageHandler = qScopeGuard([] { qInstallMessageHandler(oldMessageHandler); });
|
||||
auto *newModel = new QStandardItemModel(model);
|
||||
selection->setModel(newModel);
|
||||
QSignalSpy spy(newModel, &QObject::destroyed);
|
||||
delete newModel;
|
||||
QTRY_COMPARE(spy.count(), 1);
|
||||
qDebug() << spy;
|
||||
selection->setModel(nullptr);
|
||||
QVERIFY(!signalError);
|
||||
}
|
||||
|
||||
void tst_QItemSelectionModel::destroyModel()
|
||||
{
|
||||
auto itemModel = std::make_unique<QStandardItemModel>(5, 5);
|
||||
auto selectionModel = std::make_unique<QItemSelectionModel>();
|
||||
selectionModel->setModel(itemModel.get());
|
||||
selectionModel->select(itemModel->index(0, 0), QItemSelectionModel::Select);
|
||||
QVERIFY(!selectionModel->selection().isEmpty());
|
||||
selectionModel->setCurrentIndex(itemModel->index(1, 0), QItemSelectionModel::Select);
|
||||
QVERIFY(selectionModel->currentIndex().isValid());
|
||||
|
||||
QTest::failOnWarning(QRegularExpression(".*"));
|
||||
itemModel.reset();
|
||||
QVERIFY(!selectionModel->currentIndex().isValid());
|
||||
QVERIFY(selectionModel->selection().isEmpty());
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QItemSelectionModel)
|
||||
#include "tst_qitemselectionmodel.moc"
|
||||
|
@ -62,6 +62,7 @@ void tst_QSortFilterProxyModel::cleanup()
|
||||
m_proxy->sort(-1, Qt::AscendingOrder);
|
||||
m_model->clear();
|
||||
m_model->insertColumns(0, 1);
|
||||
QCoreApplication::processEvents(); // cleanup possibly queued events
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1100,7 +1101,6 @@ void tst_QSortFilterProxyModel::filterColumns_data()
|
||||
<< "bravo"
|
||||
<< "lima")
|
||||
<< true;
|
||||
|
||||
QTest::newRow("some") << "lie"
|
||||
<< (QStringList()
|
||||
<< "charlie"
|
||||
@ -1126,6 +1126,7 @@ void tst_QSortFilterProxyModel::filterColumns()
|
||||
// prepare model
|
||||
m_model->setColumnCount(initial.size());
|
||||
m_model->setRowCount(1);
|
||||
QCoreApplication::processEvents(); // QAbstractProxyModel queues the headerDataChanged() signal
|
||||
QCOMPARE(m_model->columnCount(QModelIndex()), initial.size());
|
||||
QCOMPARE(m_model->rowCount(QModelIndex()), 1);
|
||||
// set data
|
||||
@ -2805,7 +2806,7 @@ void tst_QSortFilterProxyModel::sortColumnTracking2()
|
||||
|
||||
void tst_QSortFilterProxyModel::sortStable()
|
||||
{
|
||||
QStandardItemModel* model = new QStandardItemModel(5, 2);
|
||||
QStandardItemModel model(5, 2);
|
||||
for (int r = 0; r < 5; r++) {
|
||||
const QString prefix = QLatin1String("Row:") + QString::number(r) + QLatin1String(", Column:");
|
||||
for (int c = 0; c < 2; c++) {
|
||||
@ -2814,24 +2815,24 @@ void tst_QSortFilterProxyModel::sortStable()
|
||||
QStandardItem* child = new QStandardItem(QLatin1String("Item ") + QString::number(i));
|
||||
item->appendRow( child );
|
||||
}
|
||||
model->setItem(r, c, item);
|
||||
model.setItem(r, c, item);
|
||||
}
|
||||
}
|
||||
model->setHorizontalHeaderItem( 0, new QStandardItem( "Name" ));
|
||||
model->setHorizontalHeaderItem( 1, new QStandardItem( "Value" ));
|
||||
model.setHorizontalHeaderItem( 0, new QStandardItem( "Name" ));
|
||||
model.setHorizontalHeaderItem( 1, new QStandardItem( "Value" ));
|
||||
|
||||
QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(model);
|
||||
filterModel->setSourceModel(model);
|
||||
QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(&model);
|
||||
filterModel->setSourceModel(&model);
|
||||
|
||||
QTreeView *view = new QTreeView;
|
||||
view->setModel(filterModel);
|
||||
QTreeView view;
|
||||
view.setModel(filterModel);
|
||||
QModelIndex firstRoot = filterModel->index(0,0);
|
||||
view->expand(firstRoot);
|
||||
view->setSortingEnabled(true);
|
||||
view.expand(firstRoot);
|
||||
view.setSortingEnabled(true);
|
||||
|
||||
view->model()->sort(1, Qt::DescendingOrder);
|
||||
view.model()->sort(1, Qt::DescendingOrder);
|
||||
QVariant lastItemData =filterModel->index(2,0, firstRoot).data();
|
||||
view->model()->sort(1, Qt::DescendingOrder);
|
||||
view.model()->sort(1, Qt::DescendingOrder);
|
||||
QCOMPARE(lastItemData, filterModel->index(2,0, firstRoot).data());
|
||||
}
|
||||
|
||||
@ -3234,36 +3235,36 @@ void tst_QSortFilterProxyModel::removeRowsRecursive()
|
||||
|
||||
void tst_QSortFilterProxyModel::doubleProxySelectionSetSourceModel()
|
||||
{
|
||||
QStandardItemModel *model1 = new QStandardItemModel;
|
||||
QStandardItem *parentItem = model1->invisibleRootItem();
|
||||
QStandardItemModel model1;
|
||||
QStandardItem *parentItem = model1.invisibleRootItem();
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
QStandardItem *item = new QStandardItem(QLatin1String("model1 item ") + QString::number(i));
|
||||
parentItem->appendRow(item);
|
||||
parentItem = item;
|
||||
}
|
||||
|
||||
QStandardItemModel *model2 = new QStandardItemModel;
|
||||
QStandardItem *parentItem2 = model2->invisibleRootItem();
|
||||
QStandardItemModel model2;
|
||||
QStandardItem *parentItem2 = model2.invisibleRootItem();
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
QStandardItem *item = new QStandardItem(QLatin1String("model2 item ") + QString::number(i));
|
||||
parentItem2->appendRow(item);
|
||||
parentItem2 = item;
|
||||
}
|
||||
|
||||
QSortFilterProxyModel *toggleProxy = new QSortFilterProxyModel;
|
||||
toggleProxy->setSourceModel(model1);
|
||||
QSortFilterProxyModel toggleProxy;
|
||||
toggleProxy.setSourceModel(&model1);
|
||||
|
||||
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel;
|
||||
proxyModel->setSourceModel(toggleProxy);
|
||||
QSortFilterProxyModel proxyModel;
|
||||
proxyModel.setSourceModel(&toggleProxy);
|
||||
|
||||
QModelIndex mi = proxyModel->index(0, 0, proxyModel->index(0, 0, proxyModel->index(0, 0)));
|
||||
QItemSelectionModel ism(proxyModel);
|
||||
QModelIndex mi = proxyModel.index(0, 0, proxyModel.index(0, 0, proxyModel.index(0, 0)));
|
||||
QItemSelectionModel ism(&proxyModel);
|
||||
ism.select(mi, QItemSelectionModel::Select);
|
||||
QModelIndexList mil = ism.selectedIndexes();
|
||||
QCOMPARE(mil.size(), 1);
|
||||
QCOMPARE(mil.first(), mi);
|
||||
|
||||
toggleProxy->setSourceModel(model2);
|
||||
toggleProxy.setSourceModel(&model2);
|
||||
// No crash, it's good news!
|
||||
QVERIFY(ism.selection().isEmpty());
|
||||
}
|
||||
|
Reference in New Issue
Block a user