Use a fake directory model instead of QDirModel in item view tests.
The tests then have a predictable, stable environment and do not depend on file system operations. Task-number: QTBUG-23697 Change-Id: Ibbd356f8bd7419ec4a3a88d2c0b5cd0830049790 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
This commit is contained in:
parent
9ac20dc44c
commit
b7de9e7353
@ -4,4 +4,5 @@ QT += widgets widgets-private
|
|||||||
QT += gui-private core-private testlib
|
QT += gui-private core-private testlib
|
||||||
|
|
||||||
SOURCES += tst_qcolumnview.cpp
|
SOURCES += tst_qcolumnview.cpp
|
||||||
|
HEADERS += ../../../../shared/fakedirmodel.h
|
||||||
TARGET = tst_qcolumnview
|
TARGET = tst_qcolumnview
|
||||||
|
@ -39,14 +39,12 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "../../../../shared/fakedirmodel.h"
|
||||||
#include <QtTest/QtTest>
|
#include <QtTest/QtTest>
|
||||||
#include <qstandarditemmodel.h>
|
|
||||||
#include <qitemdelegate.h>
|
#include <qitemdelegate.h>
|
||||||
#include <qcolumnview.h>
|
#include <qcolumnview.h>
|
||||||
#include <private/qcolumnviewgrip_p.h>
|
#include <private/qcolumnviewgrip_p.h>
|
||||||
#include <private/qfilesystemmodel_p.h>
|
#include <private/qfilesystemmodel_p.h>
|
||||||
#include <qdirmodel.h>
|
|
||||||
#include <qstringlistmodel.h>
|
#include <qstringlistmodel.h>
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
#include <qitemdelegate.h>
|
#include <qitemdelegate.h>
|
||||||
@ -64,6 +62,7 @@ public:
|
|||||||
virtual ~tst_QColumnView();
|
virtual ~tst_QColumnView();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
|
void initTestCase();
|
||||||
void init();
|
void init();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
@ -107,6 +106,10 @@ private slots:
|
|||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void setPreviewWidget();
|
void setPreviewWidget();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QStandardItemModel m_fakeDirModel;
|
||||||
|
QModelIndex m_fakeDirHomeIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TreeModel : public QStandardItemModel
|
class TreeModel : public QStandardItemModel
|
||||||
@ -182,12 +185,20 @@ protected:
|
|||||||
|
|
||||||
tst_QColumnView::tst_QColumnView()
|
tst_QColumnView::tst_QColumnView()
|
||||||
{
|
{
|
||||||
|
QStandardItem *homeItem = populateFakeDirModel(&m_fakeDirModel);
|
||||||
|
m_fakeDirHomeIndex = m_fakeDirModel.indexFromItem(homeItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
tst_QColumnView::~tst_QColumnView()
|
tst_QColumnView::~tst_QColumnView()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QColumnView::initTestCase()
|
||||||
|
{
|
||||||
|
QVERIFY(m_fakeDirHomeIndex.isValid());
|
||||||
|
QVERIFY(m_fakeDirModel.rowCount(m_fakeDirHomeIndex) > 1); // Needs some entries in 'home'.
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QColumnView::init()
|
void tst_QColumnView::init()
|
||||||
{
|
{
|
||||||
qApp->setLayoutDirection(Qt::LeftToRight);
|
qApp->setLayoutDirection(Qt::LeftToRight);
|
||||||
@ -268,8 +279,7 @@ void tst_QColumnView::rootIndex()
|
|||||||
void tst_QColumnView::grips()
|
void tst_QColumnView::grips()
|
||||||
{
|
{
|
||||||
QColumnView view;
|
QColumnView view;
|
||||||
QDirModel model;
|
view.setModel(&m_fakeDirModel);
|
||||||
view.setModel(&model);
|
|
||||||
QCOMPARE(view.resizeGripsVisible(), true);
|
QCOMPARE(view.resizeGripsVisible(), true);
|
||||||
|
|
||||||
view.setResizeGripsVisible(true);
|
view.setResizeGripsVisible(true);
|
||||||
@ -304,8 +314,7 @@ void tst_QColumnView::isIndexHidden()
|
|||||||
ColumnView view;
|
ColumnView view;
|
||||||
QModelIndex idx;
|
QModelIndex idx;
|
||||||
QCOMPARE(view.IsIndexHidden(idx), false);
|
QCOMPARE(view.IsIndexHidden(idx), false);
|
||||||
QDirModel model;
|
view.setModel(&m_fakeDirModel);
|
||||||
view.setModel(&model);
|
|
||||||
QCOMPARE(view.IsIndexHidden(idx), false);
|
QCOMPARE(view.IsIndexHidden(idx), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,22 +322,20 @@ void tst_QColumnView::indexAt()
|
|||||||
{
|
{
|
||||||
QColumnView view;
|
QColumnView view;
|
||||||
QCOMPARE(view.indexAt(QPoint(0,0)), QModelIndex());
|
QCOMPARE(view.indexAt(QPoint(0,0)), QModelIndex());
|
||||||
QDirModel model;
|
view.setModel(&m_fakeDirModel);
|
||||||
view.setModel(&model);
|
|
||||||
|
|
||||||
QModelIndex home = model.index(QDir::homePath());
|
QModelIndex homeFile = m_fakeDirModel.index(0, 0, m_fakeDirHomeIndex);
|
||||||
QModelIndex homeFile = model.index(0, 0, home);
|
|
||||||
if (!homeFile.isValid())
|
if (!homeFile.isValid())
|
||||||
return;
|
return;
|
||||||
view.setRootIndex(home);
|
view.setRootIndex(m_fakeDirHomeIndex);
|
||||||
QRect rect = view.visualRect(QModelIndex());
|
QRect rect = view.visualRect(QModelIndex());
|
||||||
QVERIFY(!rect.isValid());
|
QVERIFY(!rect.isValid());
|
||||||
rect = view.visualRect(homeFile);
|
rect = view.visualRect(homeFile);
|
||||||
QVERIFY(rect.isValid());
|
QVERIFY(rect.isValid());
|
||||||
|
|
||||||
QModelIndex child;
|
QModelIndex child;
|
||||||
for (int i = 0; i < model.rowCount(home); ++i) {
|
for (int i = 0; i < m_fakeDirModel.rowCount(m_fakeDirHomeIndex); ++i) {
|
||||||
child = model.index(i, 0, home);
|
child = m_fakeDirModel.index(i, 0, m_fakeDirHomeIndex);
|
||||||
rect = view.visualRect(child);
|
rect = view.visualRect(child);
|
||||||
QVERIFY(rect.isValid());
|
QVERIFY(rect.isValid());
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
@ -341,8 +348,8 @@ void tst_QColumnView::indexAt()
|
|||||||
QTest::qWait(200);
|
QTest::qWait(200);
|
||||||
|
|
||||||
// test that the second row doesn't start at 0
|
// test that the second row doesn't start at 0
|
||||||
if (model.rowCount(child) > 0) {
|
if (m_fakeDirModel.rowCount(child) > 0) {
|
||||||
child = model.index(0, 0, child);
|
child = m_fakeDirModel.index(0, 0, child);
|
||||||
QVERIFY(child.isValid());
|
QVERIFY(child.isValid());
|
||||||
rect = view.visualRect(child);
|
rect = view.visualRect(child);
|
||||||
QVERIFY(rect.isValid());
|
QVERIFY(rect.isValid());
|
||||||
@ -517,47 +524,48 @@ void tst_QColumnView::moveCursor()
|
|||||||
// don't do anything
|
// don't do anything
|
||||||
QCOMPARE(view.MoveCursor(ColumnView::MoveEnd, Qt::NoModifier), QModelIndex());
|
QCOMPARE(view.MoveCursor(ColumnView::MoveEnd, Qt::NoModifier), QModelIndex());
|
||||||
|
|
||||||
QDirModel model;
|
view.setModel(&m_fakeDirModel);
|
||||||
view.setModel(&model);
|
|
||||||
QModelIndex home = model.index(QDir::homePath());
|
|
||||||
QModelIndex ci = view.currentIndex();
|
QModelIndex ci = view.currentIndex();
|
||||||
QCOMPARE(view.MoveCursor(ColumnView::MoveUp, Qt::NoModifier), QModelIndex());
|
QCOMPARE(view.MoveCursor(ColumnView::MoveUp, Qt::NoModifier), QModelIndex());
|
||||||
QCOMPARE(view.MoveCursor(ColumnView::MoveDown, Qt::NoModifier), QModelIndex());
|
QCOMPARE(view.MoveCursor(ColumnView::MoveDown, Qt::NoModifier), QModelIndex());
|
||||||
|
|
||||||
// left at root
|
// left at root
|
||||||
view.setCurrentIndex(model.index(0,0));
|
view.setCurrentIndex(m_fakeDirModel.index(0,0));
|
||||||
ColumnView::PublicCursorAction action = reverse ? ColumnView::MoveRight : ColumnView::MoveLeft;
|
ColumnView::PublicCursorAction action = reverse ? ColumnView::MoveRight : ColumnView::MoveLeft;
|
||||||
QCOMPARE(view.MoveCursor(action, Qt::NoModifier), model.index(0,0));
|
QCOMPARE(view.MoveCursor(action, Qt::NoModifier), m_fakeDirModel.index(0,0));
|
||||||
|
|
||||||
// left shouldn't move up
|
// left shouldn't move up
|
||||||
int i = 0;
|
int i = 0;
|
||||||
ci = model.index(0, 0);
|
ci = m_fakeDirModel.index(0, 0);
|
||||||
while (i < model.rowCount() - 1 && !model.hasChildren(ci))
|
while (i < m_fakeDirModel.rowCount() - 1 && !m_fakeDirModel.hasChildren(ci))
|
||||||
ci = model.index(++i, 0);
|
ci = m_fakeDirModel.index(++i, 0);
|
||||||
QVERIFY(model.hasChildren(ci));
|
QVERIFY(m_fakeDirModel.hasChildren(ci));
|
||||||
view.setCurrentIndex(ci);
|
view.setCurrentIndex(ci);
|
||||||
action = reverse ? ColumnView::MoveRight : ColumnView::MoveLeft;
|
action = reverse ? ColumnView::MoveRight : ColumnView::MoveLeft;
|
||||||
QCOMPARE(view.MoveCursor(action, Qt::NoModifier), ci);
|
QCOMPARE(view.MoveCursor(action, Qt::NoModifier), ci);
|
||||||
|
|
||||||
// now move to the left (i.e. move over one column)
|
// now move to the left (i.e. move over one column)
|
||||||
view.setCurrentIndex(home);
|
view.setCurrentIndex(m_fakeDirHomeIndex);
|
||||||
QCOMPARE(view.MoveCursor(action, Qt::NoModifier), home.parent());
|
QCOMPARE(view.MoveCursor(action, Qt::NoModifier), m_fakeDirHomeIndex.parent());
|
||||||
|
|
||||||
// right
|
// right
|
||||||
action = reverse ? ColumnView::MoveLeft : ColumnView::MoveRight;
|
action = reverse ? ColumnView::MoveLeft : ColumnView::MoveRight;
|
||||||
view.setCurrentIndex(ci);
|
view.setCurrentIndex(ci);
|
||||||
QModelIndex mc = view.MoveCursor(action, Qt::NoModifier);
|
QModelIndex mc = view.MoveCursor(action, Qt::NoModifier);
|
||||||
QCOMPARE(mc, model.index(0,0, ci));
|
QCOMPARE(mc, m_fakeDirModel.index(0,0, ci));
|
||||||
|
|
||||||
// next one should move down
|
// for empty directories (no way to go 'right'), next one should move down
|
||||||
QModelIndex idx = model.index(0, 0, ci);
|
QModelIndex idx = m_fakeDirModel.index(0, 0, ci);
|
||||||
while (model.hasChildren(idx) && model.rowCount(ci) > idx.row() + 1)
|
const int rowCount = m_fakeDirModel.rowCount(ci);
|
||||||
|
while (m_fakeDirModel.hasChildren(idx) && rowCount > idx.row() + 1) {
|
||||||
idx = idx.sibling(idx.row() + 1, idx.column());
|
idx = idx.sibling(idx.row() + 1, idx.column());
|
||||||
|
}
|
||||||
|
static const char error[] = "This test requires an empty directory followed by another directory.";
|
||||||
|
QVERIFY2(idx.isValid(), error);
|
||||||
|
QVERIFY2(!m_fakeDirModel.hasChildren(idx), error);
|
||||||
|
QVERIFY2(idx.row() + 1 < rowCount, error);
|
||||||
view.setCurrentIndex(idx);
|
view.setCurrentIndex(idx);
|
||||||
mc = view.MoveCursor(action, Qt::NoModifier);
|
mc = view.MoveCursor(action, Qt::NoModifier);
|
||||||
#ifdef Q_OS_MAC
|
|
||||||
QEXPECT_FAIL("", "QTBUG-23697", Continue);
|
|
||||||
#endif
|
|
||||||
QCOMPARE(mc, idx.sibling(idx.row() + 1, idx.column()));
|
QCOMPARE(mc, idx.sibling(idx.row() + 1, idx.column()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -566,20 +574,18 @@ void tst_QColumnView::selectAll()
|
|||||||
ColumnView view;
|
ColumnView view;
|
||||||
view.selectAll();
|
view.selectAll();
|
||||||
|
|
||||||
QDirModel model;
|
view.setModel(&m_fakeDirModel);
|
||||||
view.setModel(&model);
|
|
||||||
view.selectAll();
|
view.selectAll();
|
||||||
QVERIFY(view.selectionModel()->selectedIndexes().count() >= 0);
|
QVERIFY(view.selectionModel()->selectedIndexes().count() >= 0);
|
||||||
|
|
||||||
QModelIndex home = model.index(QDir::homePath());
|
view.setCurrentIndex(m_fakeDirHomeIndex);
|
||||||
view.setCurrentIndex(home);
|
|
||||||
view.selectAll();
|
view.selectAll();
|
||||||
QVERIFY(view.selectionModel()->selectedIndexes().count() > 0);
|
QVERIFY(view.selectionModel()->selectedIndexes().count() > 0);
|
||||||
|
|
||||||
QModelIndex file;
|
QModelIndex file;
|
||||||
for (int i = 0; i < model.rowCount(home); ++i)
|
for (int i = 0; i < m_fakeDirModel.rowCount(m_fakeDirHomeIndex); ++i)
|
||||||
if (!model.hasChildren(model.index(i, 0, home))) {
|
if (!m_fakeDirModel.hasChildren(m_fakeDirModel.index(i, 0, m_fakeDirHomeIndex))) {
|
||||||
file = model.index(i, 0, home);
|
file = m_fakeDirModel.index(i, 0, m_fakeDirHomeIndex);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
view.setCurrentIndex(file);
|
view.setCurrentIndex(file);
|
||||||
@ -594,22 +600,19 @@ void tst_QColumnView::clicked()
|
|||||||
{
|
{
|
||||||
ColumnView view;
|
ColumnView view;
|
||||||
|
|
||||||
QDirModel model;
|
view.setModel(&m_fakeDirModel);
|
||||||
view.setModel(&model);
|
|
||||||
view.resize(800,300);
|
view.resize(800,300);
|
||||||
view.show();
|
view.show();
|
||||||
|
|
||||||
QModelIndex home = model.index(QDir::homePath());
|
view.setCurrentIndex(m_fakeDirHomeIndex);
|
||||||
QVERIFY(home.isValid());
|
|
||||||
view.setCurrentIndex(home);
|
|
||||||
QTest::qWait(ANIMATION_DELAY);
|
QTest::qWait(ANIMATION_DELAY);
|
||||||
|
|
||||||
QModelIndex parent = home.parent();
|
QModelIndex parent = m_fakeDirHomeIndex.parent();
|
||||||
QVERIFY(parent.isValid());
|
QVERIFY(parent.isValid());
|
||||||
|
|
||||||
QSignalSpy clickedSpy(&view, SIGNAL(clicked(QModelIndex)));
|
QSignalSpy clickedSpy(&view, SIGNAL(clicked(QModelIndex)));
|
||||||
|
|
||||||
QPoint localPoint = view.visualRect(home).center();
|
QPoint localPoint = view.visualRect(m_fakeDirHomeIndex).center();
|
||||||
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, localPoint);
|
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, localPoint);
|
||||||
QCOMPARE(clickedSpy.count(), 1);
|
QCOMPARE(clickedSpy.count(), 1);
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
@ -619,7 +622,7 @@ void tst_QColumnView::clicked()
|
|||||||
|
|
||||||
for (int i = 0; i < view.createdColumns.count(); ++i) {
|
for (int i = 0; i < view.createdColumns.count(); ++i) {
|
||||||
QAbstractItemView *column = view.createdColumns.at(i);
|
QAbstractItemView *column = view.createdColumns.at(i);
|
||||||
if (column && column->selectionModel() && (column->rootIndex() == home))
|
if (column && column->selectionModel() && (column->rootIndex() == m_fakeDirHomeIndex))
|
||||||
QVERIFY(column->selectionModel()->selectedIndexes().isEmpty());
|
QVERIFY(column->selectionModel()->selectedIndexes().isEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -627,13 +630,11 @@ void tst_QColumnView::clicked()
|
|||||||
void tst_QColumnView::selectedColumns()
|
void tst_QColumnView::selectedColumns()
|
||||||
{
|
{
|
||||||
ColumnView view;
|
ColumnView view;
|
||||||
QDirModel model;
|
view.setModel(&m_fakeDirModel);
|
||||||
view.setModel(&model);
|
|
||||||
view.resize(800,300);
|
view.resize(800,300);
|
||||||
view.show();
|
view.show();
|
||||||
|
|
||||||
QModelIndex home = model.index(QDir::homePath());
|
view.setCurrentIndex(m_fakeDirHomeIndex);
|
||||||
view.setCurrentIndex(home);
|
|
||||||
|
|
||||||
QTest::qWait(ANIMATION_DELAY);
|
QTest::qWait(ANIMATION_DELAY);
|
||||||
|
|
||||||
@ -641,7 +642,7 @@ void tst_QColumnView::selectedColumns()
|
|||||||
QAbstractItemView *column = view.createdColumns.at(i);
|
QAbstractItemView *column = view.createdColumns.at(i);
|
||||||
if (!column)
|
if (!column)
|
||||||
continue;
|
continue;
|
||||||
if (!column->rootIndex().isValid() || column->rootIndex() == home)
|
if (!column->rootIndex().isValid() || column->rootIndex() == m_fakeDirHomeIndex)
|
||||||
continue;
|
continue;
|
||||||
QTRY_VERIFY(column->currentIndex().isValid());
|
QTRY_VERIFY(column->currentIndex().isValid());
|
||||||
}
|
}
|
||||||
@ -658,15 +659,13 @@ void tst_QColumnView::setSelection()
|
|||||||
void tst_QColumnView::setSelectionModel()
|
void tst_QColumnView::setSelectionModel()
|
||||||
{
|
{
|
||||||
ColumnView view;
|
ColumnView view;
|
||||||
QDirModel model;
|
view.setModel(&m_fakeDirModel);
|
||||||
view.setModel(&model);
|
|
||||||
view.show();
|
view.show();
|
||||||
|
|
||||||
QModelIndex home = model.index(QDir::homePath());
|
view.setCurrentIndex(m_fakeDirHomeIndex);
|
||||||
view.setCurrentIndex(home);
|
|
||||||
QTest::qWait(ANIMATION_DELAY);
|
QTest::qWait(ANIMATION_DELAY);
|
||||||
|
|
||||||
QItemSelectionModel *selectionModel = new QItemSelectionModel(&model);
|
QItemSelectionModel *selectionModel = new QItemSelectionModel(&m_fakeDirModel);
|
||||||
view.setSelectionModel(selectionModel);
|
view.setSelectionModel(selectionModel);
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
@ -686,19 +685,10 @@ void tst_QColumnView::visualRegionForSelection()
|
|||||||
QCOMPARE(QRegion(), view.getVisualRegionForSelection(emptyItemSelection));
|
QCOMPARE(QRegion(), view.getVisualRegionForSelection(emptyItemSelection));
|
||||||
|
|
||||||
// a region that isn't empty
|
// a region that isn't empty
|
||||||
QDirModel model;
|
view.setModel(&m_fakeDirModel);
|
||||||
view.setModel(&model);
|
|
||||||
|
|
||||||
// On Windows CE the home directory might actually be empty.
|
|
||||||
#ifndef Q_OS_WINCE
|
|
||||||
QString location = QDir::homePath();
|
|
||||||
#else
|
|
||||||
QString location = QLatin1String("/Windows");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QModelIndex home = model.index(location);
|
QItemSelection itemSelection(m_fakeDirModel.index(0, 0, m_fakeDirHomeIndex), m_fakeDirModel.index(m_fakeDirModel.rowCount(m_fakeDirHomeIndex) - 1, 0, m_fakeDirHomeIndex));
|
||||||
QVERIFY(model.rowCount(home) > 1);
|
|
||||||
QItemSelection itemSelection(model.index(0, 0, home), model.index(model.rowCount(home) - 1, 0, home));
|
|
||||||
QVERIFY(QRegion() != view.getVisualRegionForSelection(itemSelection));
|
QVERIFY(QRegion() != view.getVisualRegionForSelection(itemSelection));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -871,10 +861,8 @@ void tst_QColumnView::sizes()
|
|||||||
view.setColumnWidths(newSizes);
|
view.setColumnWidths(newSizes);
|
||||||
QCOMPARE(view.columnWidths(), visibleSizes);
|
QCOMPARE(view.columnWidths(), visibleSizes);
|
||||||
|
|
||||||
QDirModel model;
|
view.setModel(&m_fakeDirModel);
|
||||||
view.setModel(&model);
|
view.setCurrentIndex(m_fakeDirHomeIndex);
|
||||||
QModelIndex home = model.index(QDir::homePath());
|
|
||||||
view.setCurrentIndex(home);
|
|
||||||
|
|
||||||
QList<int> postSizes = view.columnWidths().mid(0, newSizes.count());
|
QList<int> postSizes = view.columnWidths().mid(0, newSizes.count());
|
||||||
QCOMPARE(postSizes, newSizes.mid(0, postSizes.count()));
|
QCOMPARE(postSizes, newSizes.mid(0, postSizes.count()));
|
||||||
@ -895,8 +883,7 @@ void tst_QColumnView::rowDelegate()
|
|||||||
QItemDelegate *d = new QItemDelegate;
|
QItemDelegate *d = new QItemDelegate;
|
||||||
view.setItemDelegateForRow(3, d);
|
view.setItemDelegateForRow(3, d);
|
||||||
|
|
||||||
QDirModel model;
|
view.setModel(&m_fakeDirModel);
|
||||||
view.setModel(&model);
|
|
||||||
for (int i = 0; i < view.createdColumns.count(); ++i) {
|
for (int i = 0; i < view.createdColumns.count(); ++i) {
|
||||||
QAbstractItemView *column = view.createdColumns.at(i);
|
QAbstractItemView *column = view.createdColumns.at(i);
|
||||||
QCOMPARE(column->itemDelegateForRow(3), (QAbstractItemDelegate*)d);
|
QCOMPARE(column->itemDelegateForRow(3), (QAbstractItemDelegate*)d);
|
||||||
@ -908,13 +895,11 @@ void tst_QColumnView::resize()
|
|||||||
{
|
{
|
||||||
QWidget topLevel;
|
QWidget topLevel;
|
||||||
ColumnView view(&topLevel);
|
ColumnView view(&topLevel);
|
||||||
QDirModel model;
|
view.setModel(&m_fakeDirModel);
|
||||||
view.setModel(&model);
|
|
||||||
view.resize(200, 200);
|
view.resize(200, 200);
|
||||||
|
|
||||||
topLevel.show();
|
topLevel.show();
|
||||||
QModelIndex home = model.index(QDir::homePath()).parent();
|
view.setCurrentIndex(m_fakeDirHomeIndex);
|
||||||
view.setCurrentIndex(home);
|
|
||||||
QTest::qWait(ANIMATION_DELAY);
|
QTest::qWait(ANIMATION_DELAY);
|
||||||
view.resize(200, 300);
|
view.resize(200, 300);
|
||||||
QTest::qWait(ANIMATION_DELAY);
|
QTest::qWait(ANIMATION_DELAY);
|
||||||
|
@ -3,4 +3,4 @@ TARGET = tst_qtreeview
|
|||||||
QT += widgets testlib
|
QT += widgets testlib
|
||||||
QT += widgets-private gui-private core-private
|
QT += widgets-private gui-private core-private
|
||||||
SOURCES += tst_qtreeview.cpp
|
SOURCES += tst_qtreeview.cpp
|
||||||
|
HEADERS += ../../../../shared/fakedirmodel.h
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "../../../../shared/fakedirmodel.h"
|
||||||
#include <qabstractitemview.h>
|
#include <qabstractitemview.h>
|
||||||
#include <QtTest/QtTest>
|
#include <QtTest/QtTest>
|
||||||
#include <QtGui/QtGui>
|
#include <QtGui/QtGui>
|
||||||
@ -3719,7 +3720,9 @@ void tst_QTreeView::task246536_scrollbarsNotWorking()
|
|||||||
|
|
||||||
void tst_QTreeView::task250683_wrongSectionSize()
|
void tst_QTreeView::task250683_wrongSectionSize()
|
||||||
{
|
{
|
||||||
QDirModel model;
|
QStandardItemModel model;
|
||||||
|
populateFakeDirModel(&model);
|
||||||
|
|
||||||
QTreeView treeView;
|
QTreeView treeView;
|
||||||
treeView.header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
treeView.header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||||
treeView.setModel(&model);
|
treeView.setModel(&model);
|
||||||
|
130
tests/shared/fakedirmodel.h
Normal file
130
tests/shared/fakedirmodel.h
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||||
|
** Contact: http://www.qt-project.org/legal
|
||||||
|
**
|
||||||
|
** This file is part of the test suite of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Digia. For licensing terms and
|
||||||
|
** conditions see http://qt.digia.com/licensing. For further information
|
||||||
|
** use the contact form at http://qt.digia.com/contact-us.
|
||||||
|
**
|
||||||
|
** 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, Digia gives you certain additional
|
||||||
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||||
|
** version 1.1, 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.
|
||||||
|
**
|
||||||
|
**
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef FAKEDIRMODEL_H
|
||||||
|
#define FAKEDIRMODEL_H
|
||||||
|
|
||||||
|
#include <QtGui/QStandardItemModel>
|
||||||
|
#include <QtGui/QStandardItem>
|
||||||
|
#include <QtGui/QIcon>
|
||||||
|
#include <QtGui/QPixmap>
|
||||||
|
#include <QtGui/QImage>
|
||||||
|
#include <QtCore/QStringList>
|
||||||
|
|
||||||
|
typedef QList<QStandardItem *> StandardItemList;
|
||||||
|
|
||||||
|
static inline QIcon coloredIcon(Qt::GlobalColor color)
|
||||||
|
{
|
||||||
|
QImage image(22, 22, QImage::Format_ARGB32);
|
||||||
|
image.fill(color);
|
||||||
|
return QPixmap::fromImage(image);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void addFileEntry(const StandardItemList &directory, const QString &name, const QString &size)
|
||||||
|
{
|
||||||
|
static const QIcon fileIcon = coloredIcon(Qt::blue);
|
||||||
|
directory.front()->appendRow(StandardItemList() << new QStandardItem(fileIcon, name) << new QStandardItem(size));
|
||||||
|
}
|
||||||
|
|
||||||
|
static StandardItemList createDirEntry(const QString &name)
|
||||||
|
{
|
||||||
|
static const QIcon dirIcon = coloredIcon(Qt::red);
|
||||||
|
StandardItemList result;
|
||||||
|
result << new QStandardItem(dirIcon, name) << new QStandardItem;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline StandardItemList addDirEntry(const StandardItemList &directory, const QString &name)
|
||||||
|
{
|
||||||
|
const StandardItemList entry = createDirEntry(name);
|
||||||
|
directory.front()->appendRow(entry);
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
static QStandardItem *populateFakeDirModel(QStandardItemModel *model)
|
||||||
|
{
|
||||||
|
enum Columns { NameColumn, SizeColumn, ColumnCount };
|
||||||
|
|
||||||
|
model->setColumnCount(ColumnCount);
|
||||||
|
model->setHorizontalHeaderLabels(QStringList() << QStringLiteral("Name") << QStringLiteral("Size"));
|
||||||
|
|
||||||
|
const StandardItemList root = createDirEntry(QStringLiteral("/"));
|
||||||
|
model->appendRow(root);
|
||||||
|
|
||||||
|
const StandardItemList binDir = addDirEntry(root, QStringLiteral("bin"));
|
||||||
|
addFileEntry(binDir, QStringLiteral("ls"), QStringLiteral("100 KB"));
|
||||||
|
addFileEntry(binDir, QStringLiteral("bash"), QStringLiteral("200 KB"));
|
||||||
|
|
||||||
|
const StandardItemList devDir = addDirEntry(root, QStringLiteral("dev"));
|
||||||
|
addFileEntry(devDir, QStringLiteral("tty1"), QStringLiteral("0 B"));
|
||||||
|
addDirEntry(devDir, QStringLiteral("proc"));
|
||||||
|
|
||||||
|
const StandardItemList etcDir = addDirEntry(root, QStringLiteral("etc"));
|
||||||
|
addFileEntry(etcDir, QStringLiteral("foo1.config"), QStringLiteral("1 KB"));
|
||||||
|
addFileEntry(etcDir, QStringLiteral("foo2.conf"), QStringLiteral("654 B"));
|
||||||
|
|
||||||
|
const StandardItemList homeDir = addDirEntry(root, QStringLiteral("home"));
|
||||||
|
addFileEntry(homeDir, QStringLiteral("file1"), QStringLiteral("1 KB"));
|
||||||
|
|
||||||
|
const StandardItemList documentsDir = addDirEntry(homeDir, QStringLiteral("Documents"));
|
||||||
|
addFileEntry(documentsDir, QStringLiteral("txt1.odt"), QStringLiteral("2 MB"));
|
||||||
|
addFileEntry(documentsDir, QStringLiteral("sheet1.xls"), QStringLiteral("32 KB"));
|
||||||
|
addFileEntry(documentsDir, QStringLiteral("foo.doc"), QStringLiteral("214 KB"));
|
||||||
|
|
||||||
|
const StandardItemList downloadsDir = addDirEntry(homeDir, QStringLiteral("Downloads"));
|
||||||
|
addFileEntry(downloadsDir, QStringLiteral("package1.zip"), QStringLiteral("34 MB"));
|
||||||
|
addFileEntry(downloadsDir, QStringLiteral("package2.zip"), QStringLiteral("623 KB"));
|
||||||
|
|
||||||
|
const StandardItemList picturesDir = addDirEntry(homeDir, QStringLiteral("Pictures"));
|
||||||
|
addFileEntry(picturesDir, QStringLiteral("img0001.jpg"), QStringLiteral("4 MB"));
|
||||||
|
addFileEntry(picturesDir, QStringLiteral("img0002.png"), QStringLiteral("10 MB"));
|
||||||
|
|
||||||
|
// qcolumnview::moveCursor() requires an empty directory followed by another one.
|
||||||
|
addDirEntry(root, QStringLiteral("lost+found"));
|
||||||
|
|
||||||
|
const StandardItemList tmpDir = addDirEntry(root, QStringLiteral("tmp"));
|
||||||
|
addFileEntry(tmpDir, "asdujhsdjys", "435 B");
|
||||||
|
addFileEntry(tmpDir, "krtbldfhd", "5557 B");
|
||||||
|
|
||||||
|
return homeDir.front();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // FAKEDIRMODEL_H
|
Loading…
x
Reference in New Issue
Block a user