qt 6.5.1 original

This commit is contained in:
kleuter
2023-10-29 23:33:08 +01:00
parent 71d22ab6b0
commit 85d238dfda
21202 changed files with 5499099 additions and 0 deletions

View File

@ -0,0 +1,9 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(delegate)
add_subdirectory(qconcatenatetablesproxymodel)
add_subdirectory(qheaderview)
add_subdirectory(qtreeview)
add_subdirectory(qtreewidget)
add_subdirectory(tableview-span-navigation)

View File

@ -0,0 +1,15 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## testtable1 Binary:
#####################################################################
qt_internal_add_manual_test(testtable1
GUI
SOURCES
testtable1.cpp
LIBRARIES
Qt::Gui
Qt::Widgets
)

View File

@ -0,0 +1,78 @@
// Copyright (C) 2012 Thorbjørn Lund Martsum - tmartsum[at]gmail.com
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtWidgets/QtWidgets>
const int rowCount = 2000;
class TableDialog : public QDialog
{
Q_OBJECT
public:
TableDialog() : model(rowCount, 3) { create(); }
void create()
{
resize(1000, 233);
gridLayout = new QGridLayout(this);
tableView = new QTableView(this);
gridLayout->addWidget(tableView, 0, 0, 2, 1);
spinPrecision = new QSpinBox(this);
gridLayout->addWidget(spinPrecision, 0, 1, 1, 1);
verticalSpacer = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
gridLayout->addItem(verticalSpacer, 1, 1, 1, 1);
QString ii = QString::fromLatin1("ii");
QStringList is;
spinPrecision->setMinimum(-1);
spinPrecision->setMaximum(rowCount + 2);
for (int u = 0; u < rowCount; ++u) {
if (u % 25 == 0)
ii += QString::fromLatin1("i");
else
ii[ii.length() - 1] = QChar::fromLatin1('a' + (u % 25));
ii[ii.length() - 2] = QChar::fromLatin1('i');
is.append(ii);
}
for (int u = 0; u < rowCount; ++u) {
QString col1;
col1 = QString::fromLatin1("Row: %1").arg(u);
model.setData(model.index(u, 0), col1);
model.setData(model.index(u, 1), is[u]);
model.setData(model.index(u, 2), is[rowCount - u -1]);
}
tableView->setModel(&model);
tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
tableView->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
tableView->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
spinPrecision->setValue(tableView->horizontalHeader()->resizeContentsPrecision());
connect(spinPrecision, SIGNAL(valueChanged(int)), this, SLOT(slotValueChanged(int)));
} // setupUi
protected slots:
void slotValueChanged(int newval);
protected:
QGridLayout *gridLayout;
QTableView *tableView;
QSpinBox *spinPrecision;
QSpacerItem *verticalSpacer;
QStandardItemModel model;
};
void TableDialog::slotValueChanged(int newval)
{
tableView->horizontalHeader()->setResizeContentsPrecision(newval);
tableView->resizeColumnsToContents();
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
TableDialog d1;
d1.show();
app.exec();
}
#include "testtable1.moc"

View File

@ -0,0 +1,2 @@
SOURCES = testtable1.cpp
QT += widgets

View File

@ -0,0 +1,15 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## testtable2 Binary:
#####################################################################
qt_internal_add_manual_test(testtable2
GUI
SOURCES
testtable2.cpp
LIBRARIES
Qt::Gui
Qt::Widgets
)

View File

@ -0,0 +1,88 @@
// Copyright (C) 2012 Thorbjørn Lund Martsum - tmartsum[at]gmail.com
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtWidgets/QtWidgets>
const int columnCount = 1500;
class TableDialog : public QDialog
{
Q_OBJECT
public:
TableDialog() : model(2, columnCount) { create(); }
void create()
{
resize(1200, 400);
gridLayout = new QGridLayout(this);
tableView = new QTableView(this);
gridLayout->addWidget(tableView, 0, 0, 2, 1);
spinPrecision = new QSpinBox(this);
gridLayout->addWidget(spinPrecision, 0, 1, 1, 1);
verticalSpacer = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
gridLayout->addItem(verticalSpacer, 1, 1, 1, 1);
QString ii = QString::fromLatin1("ii");
QStringList is;
spinPrecision->setMinimum(-1);
spinPrecision->setMaximum(columnCount + 2);
QFont f = QApplication::font();
for (int u = 0; u < columnCount; ++u) {
int size = 10 + (u % 63);
f.setPixelSize(size);
QString col;
if (u % 50 < 25)
col = QChar::fromLatin1('a' + (u % 25));
else
col = QChar::fromLatin1('A' + (u % 25));
int v = columnCount - u - 1;
model.setData(model.index(0, u), col);
model.setData(model.index(1, v), col);
model.setData(model.index(0, u), f, Qt::FontRole);
model.setData(model.index(1, v), f, Qt::FontRole);
}
tableView->setModel(&model);
for (int u = 0; u < columnCount; ++ u)
tableView->horizontalHeader()->resizeSection(u, 60);
// Make last index in first row a bit special
f.setPixelSize(96);
model.setData(model.index(0, columnCount - 1), f, Qt::FontRole);
model.setData(model.index(0, columnCount - 1), QString::fromLatin1("qI"));
tableView->horizontalHeader()->resizeSection(columnCount - 1, 140);
tableView->verticalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
tableView->verticalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
spinPrecision->setValue(tableView->verticalHeader()->resizeContentsPrecision());
connect(spinPrecision, SIGNAL(valueChanged(int)), this, SLOT(slotValueChanged(int)));
} // setupUi
protected slots:
void slotValueChanged(int newval);
protected:
QGridLayout *gridLayout;
QTableView *tableView;
QSpinBox *spinPrecision;
QSpacerItem *verticalSpacer;
QStandardItemModel model;
};
void TableDialog::slotValueChanged(int newval)
{
tableView->verticalHeader()->setResizeContentsPrecision(newval);
tableView->resizeRowsToContents();
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
TableDialog d1;
d1.show();
app.exec();
}
#include "testtable2.moc"

View File

@ -0,0 +1,2 @@
SOURCES = testtable2.cpp
QT += widgets

View File

@ -0,0 +1,15 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## testtree Binary:
#####################################################################
qt_internal_add_manual_test(testtree
GUI
SOURCES
testtree.cpp
LIBRARIES
Qt::Gui
Qt::Widgets
)

View File

@ -0,0 +1,96 @@
// Copyright (C) 2012 Thorbjørn Lund Martsum - tmartsum[at]gmail.com
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtWidgets/QtWidgets>
class TreeDialog : public QDialog
{
Q_OBJECT
public:
TreeDialog() { create(); }
protected:
void create()
{
resize(1000, 233);
gridLayout = new QGridLayout(this);
treeWidget = new QTreeWidget(this);
gridLayout->addWidget(treeWidget, 0, 0, 2, 1);
spinPrecision = new QSpinBox(this);
gridLayout->addWidget(spinPrecision, 0, 1, 1, 1);
verticalSpacer = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
gridLayout->addItem(verticalSpacer, 1, 1, 1, 1);
QStringList itemInfo("Col1");
itemInfo.append("Col2");
itemInfo.append("Col3");
itemInfo.append("Dummy");
// Developer no. could also have been social security number og some other id.
treeWidget->setHeaderLabels(itemInfo);
QStringList sl1("This is Root Item");
sl1.append("i");
QTreeWidgetItem *rootitem = new QTreeWidgetItem(treeWidget, sl1);
QStringList sl2("This is Child1 Item");
sl2.append("WW");
QTreeWidgetItem *child1 = new QTreeWidgetItem(rootitem, sl2);
QString ii = QString::fromLatin1("ii");
QStringList is;
const int rowCount = 3000;
spinPrecision->setMinimum(-1);
spinPrecision->setMaximum(rowCount + 5);
for (int u = 0; u < rowCount; ++u) {
if (u % 25 == 0)
ii += QString::fromLatin1("i");
else
ii[ii.length() - 1] = QChar::fromLatin1('a' + (u % 25));
ii[ii.length() - 2] = QChar::fromLatin1('i');
is.append(ii);
}
for (int u = 0; u < rowCount - 2; ++u) { // -2 since we have rootitem and child1
QString col1;
col1 = QString::fromLatin1("This is child item %1").arg(u + 2);
QStringList sl(col1);
sl.append(is[u]);
sl.append(is[rowCount - u - 1]);
if (u > 500)
new QTreeWidgetItem(rootitem, sl);
else
new QTreeWidgetItem(child1, sl);
}
treeWidget->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
treeWidget->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
treeWidget->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
spinPrecision->setValue(treeWidget->header()->resizeContentsPrecision());
connect(spinPrecision, SIGNAL(valueChanged(int)), this, SLOT(slotValueChanged(int)));
} // setupUi
protected slots:
void slotValueChanged(int newval);
protected:
QGridLayout *gridLayout;
QTreeWidget *treeWidget;
QSpinBox *spinPrecision;
QSpacerItem *verticalSpacer;
};
void TreeDialog::slotValueChanged(int newval)
{
treeWidget->header()->setResizeContentsPrecision(newval);
for (int u = 0; u < treeWidget->header()->count(); ++u)
treeWidget->resizeColumnToContents(u);
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
TreeDialog d1;
d1.show();
app.exec();
}
#include "testtree.moc"

View File

@ -0,0 +1,2 @@
SOURCES = testtree.cpp
QT += widgets

View File

@ -0,0 +1,15 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## delegate Binary:
#####################################################################
qt_internal_add_manual_test(delegate
GUI
SOURCES
example.cpp
LIBRARIES
Qt::Gui
Qt::Widgets
)

View File

@ -0,0 +1,3 @@
TEMPLATE = app
QT += widgets
SOURCES=example.cpp

View File

@ -0,0 +1,82 @@
// Copyright (C) 2012 Thorbjørn Lund Martsum - tmartsum[at]gmail.com
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QLineEdit>
#include <QApplication>
#include <QTableView>
#include <QStandardItemModel>
#include <QItemDelegate>
#include <QDebug>
#include <QComboBox>
class ExampleEditor : public QLineEdit
{
public:
ExampleEditor(QWidget *parent = nullptr):QLineEdit(parent) { qDebug() << "ctor"; }
~ExampleEditor() { QApplication::instance()->quit(); }
};
class ExampleDelegate : public QItemDelegate
{
public:
ExampleDelegate() : QItemDelegate()
{
m_editor = new ExampleEditor(0);
m_combobox = new QComboBox(0);
m_combobox->addItem(QString::fromUtf8("item1"));
m_combobox->addItem(QString::fromUtf8("item2"));
}
protected:
QWidget* createEditor(QWidget *p, const QStyleOptionViewItem &o, const QModelIndex &i) const
{
// doubleclick rownumber 3 (last row) to see the difference.
if (i.row() == 3) {
m_combobox->setParent(p);
m_combobox->setGeometry(o.rect);
return m_combobox;
} else {
m_editor->setParent(p);
m_editor->setGeometry(o.rect);
return m_editor;
}
}
void destroyEditor(QWidget *editor, const QModelIndex &) const
{
editor->setParent(0);
qDebug() << "intercepted destroy :)";
}
// Avoid setting data - and therefore show that the editor keeps its state.
void setEditorData(QWidget* w, const QModelIndex &) const
{
QComboBox *combobox = qobject_cast<QComboBox*>(w);
if (combobox) {
qDebug() << "Try to show popup at once";
// Now we could try to make a call to
// QCoreApplication::processEvents();
// But it does not matter. The fix:
// https://codereview.qt-project.org/40608
// is blocking QComboBox from reacting to this doubleclick edit event
// and we need to do that since the mouseReleaseEvent has not yet happened,
// and therefore cannot be processed.
combobox->showPopup();
}
}
~ExampleDelegate() { delete m_editor; }
mutable ExampleEditor *m_editor;
mutable QComboBox *m_combobox;
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTableView tv;
QStandardItemModel m;
m.setRowCount(4);
m.setColumnCount(2);
tv.setModel(&m);
tv.show();
tv.setItemDelegate(new ExampleDelegate());
app.exec();
}

View File

@ -0,0 +1,8 @@
TEMPLATE = subdirs
SUBDIRS = delegate \
qconcatenatetablesproxymodel \
qheaderview \
qtreeview \
qtreewidget \
tableview-span-navigation \

View File

@ -0,0 +1,17 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## qconcatenatetablesproxymodel Binary:
#####################################################################
qt_internal_add_manual_test(qconcatenatetablesproxymodel
GUI
SOURCES
main.cpp
INCLUDE_DIRECTORIES
.
LIBRARIES
Qt::Gui
Qt::Widgets
)

View File

@ -0,0 +1,63 @@
// Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure <david.faure@kdab.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QApplication>
#include <QConcatenateTablesProxyModel>
#include <QStandardItemModel>
#include <QTableView>
#include <QTreeView>
static void prepareModel(const QString &prefix, QStandardItemModel *model)
{
for (int row = 0; row < model->rowCount(); ++row) {
for (int column = 0; column < model->columnCount(); ++column) {
QStandardItem *item = new QStandardItem(prefix + QString(" %1,%2").arg(row).arg(column));
item->setDragEnabled(true);
item->setDropEnabled(true);
model->setItem(row, column, item);
}
}
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QStandardItemModel firstModel(4, 4);
prepareModel("First", &firstModel);
QStandardItemModel secondModel(2, 2);
QConcatenateTablesProxyModel proxy;
proxy.addSourceModel(&firstModel);
proxy.addSourceModel(&secondModel);
prepareModel("Second", &secondModel);
QTableView tableView;
tableView.setWindowTitle("concat proxy, in QTableView");
tableView.setDragDropMode(QAbstractItemView::DragDrop);
tableView.setModel(&proxy);
tableView.show();
QTreeView treeView;
treeView.setWindowTitle("concat proxy, in QTreeView");
treeView.setDragDropMode(QAbstractItemView::DragDrop);
treeView.setModel(&proxy);
treeView.show();
// For comparison, views on top on QStandardItemModel
QTableView tableViewTest;
tableViewTest.setWindowTitle("first model, in QTableView");
tableViewTest.setDragDropMode(QAbstractItemView::DragDrop);
tableViewTest.setModel(&firstModel);
tableViewTest.show();
QTreeView treeViewTest;
treeViewTest.setWindowTitle("first model, in QTreeView");
treeViewTest.setDragDropMode(QAbstractItemView::DragDrop);
treeViewTest.setModel(&firstModel);
treeViewTest.show();
return app.exec();
}

View File

@ -0,0 +1,8 @@
TEMPLATE = app
TARGET = qconcatenatetablesproxymodel
INCLUDEPATH += .
QT += widgets
SOURCES += main.cpp

View File

@ -0,0 +1,15 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## qheaderview Binary:
#####################################################################
qt_internal_add_manual_test(qheaderview
GUI
SOURCES
qheaderviewtest1.cpp
LIBRARIES
Qt::Gui
Qt::Widgets
)

View File

@ -0,0 +1,3 @@
TEMPLATE = app
SOURCES = qheaderviewtest1.cpp
QT += widgets

View File

@ -0,0 +1,217 @@
// Copyright (C) 2012 Thorbjørn Lund Martsum - tmartsum[at]gmail.com
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtWidgets/QtWidgets>
struct ManualTask {
const char *title;
const char *instructions;
unsigned sectionsMovable : 1;
unsigned selectionMode : 3;
};
ManualTask tasks[] = {
{ QT_TR_NOOP("0. Default"),
"Please provide instructions",
true, QAbstractItemView::SingleSelection
},
{ QT_TR_NOOP("1. Autoscroll"),
"<ol>"
"<li>Press and hold on section 9 of vertical header.<br/>"
"<em>(all cells in the row will be selected)</em>"
"</li>"
"<li>Extend the selection by moving the mouse down.<br/>"
"<em>(selection will extend to the next rows)</em>"
"</li>"
"<li>Continue to move the mouse down and outside the window geometry.<br/>"
"<em>(The view should scroll automatically and the selection should still extend)</em>"
"</li>"
"<li>While still holding the button, do the same in the opposite direction, i.e. move mouse up and outside the window geometry.<br/>"
"<em>(Verify that the view scrolls automatically and the selection changes)</em>"
"</li>"
"<li>Verify that it works in the other dimension, i.e Press and hold section 9 of the horizontal header.<br/>"
"<em>All cells in the column will be selected</em>"
"</li>"
"<li>Extend the selection by moving the mouse to the far right and outside the window geometry.<br/>"
"<em>(selection will extend to the next columns)</em>"
"</li>"
"<li>Verify that it works in the opposite direction (i.e. move mouse to the left of the window geometry).<br/>"
"<em>(Verify that the view scrolls automatically and the selection changes)</em>"
"</li>"
"</ol>",
false, QAbstractItemView::ExtendedSelection
}
};
class Window : public QWidget
{
Q_OBJECT
public:
Window(QWidget *parent = nullptr): QWidget(parent), ckMovable(0), tableView(0), cbSelectionMode(0), m_taskInstructions(0)
{
m_taskInstructions = new QLabel();
if (sizeof(tasks) > 0)
m_taskInstructions->setText(tr(tasks[0].instructions));
QVBoxLayout *vbox = new QVBoxLayout(this);
vbox->addLayout(setupComboBox());
vbox->addWidget(setupGroupBox());
vbox->addWidget(setupTableView());
vbox->addWidget(m_taskInstructions);
}
void updateControls()
{
ckMovable->setChecked(tableView->verticalHeader()->sectionsMovable());
QAbstractItemView::SelectionMode sMode = tableView->selectionMode();
cbSelectionMode->setCurrentIndex((int)sMode);
}
private:
QFormLayout *setupComboBox()
{
QComboBox *combo = new QComboBox;
for (size_t i = 0; i < sizeof(tasks) / sizeof(tasks[0]); ++i) {
combo->addItem(tr(tasks[i].title));
}
connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(on_taskCombo_currentIndexChanged(int)));
QFormLayout *form = new QFormLayout;
form->addRow(tr("Choose task:"), combo);
return form;
}
QGroupBox *setupGroupBox()
{
QGroupBox *grp = new QGroupBox(tr("Properties"));
QFormLayout *form = new QFormLayout;
grp->setLayout(form);
ckMovable = new QCheckBox;
ckMovable->setObjectName(QLatin1String("ckMovable"));
connect(ckMovable, SIGNAL(toggled(bool)), this, SLOT(on_ckMovable_toggled(bool)));
form->addRow(tr("SectionsMovable"), ckMovable);
cbSelectionMode = new QComboBox;
cbSelectionMode->setObjectName(QLatin1String("cbSelectionMode"));
cbSelectionMode->addItems(QStringList() << QLatin1String("NoSelection")
<< QLatin1String("SingleSelection")
<< QLatin1String("MultiSelection")
<< QLatin1String("ExtendedSelection")
<< QLatin1String("ContiguousSelection")
);
connect(cbSelectionMode, SIGNAL(currentIndexChanged(int)), this, SLOT(on_cbSelectionMode_currentIndexChanged(int)));
form->addRow(tr("SelectionMode"), cbSelectionMode);
return grp;
}
QTableView *setupTableView()
{
tableView = new QTableView;
const int rowCount = 200;
m.setRowCount(rowCount);
m.setColumnCount(250);
tableView->setSelectionMode(QAbstractItemView::SingleSelection);
tableView->setModel(&m);
tableView->verticalHeader()->swapSections(rowCount - 1, 5);
return tableView;
}
private Q_SLOTS:
void on_ckMovable_toggled(bool arg)
{
tableView->verticalHeader()->setSectionsMovable(arg);
tableView->horizontalHeader()->setSectionsMovable(arg);
}
void on_cbSelectionMode_currentIndexChanged(int idx)
{
tableView->setSelectionMode((QAbstractItemView::SelectionMode)idx);
}
void on_taskCombo_currentIndexChanged(int idx)
{
ManualTask &task = tasks[idx];
m_taskInstructions->setText(tr(task.instructions));
ckMovable->setChecked(task.sectionsMovable);
cbSelectionMode->setCurrentIndex((QAbstractItemView::SelectionMode)task.selectionMode);
}
public:
QCheckBox *ckMovable;
QTableView *tableView;
QStandardItemModel m;
QComboBox *cbSelectionMode;
QLabel *m_taskInstructions;
};
class SomeHandler : public QObject
{
Q_OBJECT
QHeaderView *m_hv;
QTableView *m_tv;
public:
SomeHandler(QHeaderView *hv, QTableView *tv);
public slots:
void slotSectionResized(int, int, int);
};
SomeHandler::SomeHandler(QHeaderView *hv, QTableView *tv)
{
m_hv = hv;
m_tv = tv;
m_tv->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
connect(hv, SIGNAL(sectionResized(int,int,int)), this, SLOT(slotSectionResized(int,int,int)));
}
void SomeHandler::slotSectionResized(int logsection, int oldsize, int newsize)
{
int offset = m_hv->offset();
m_tv->setUpdatesEnabled(false);
// Do some manual resizing - lets make every section having the new size.
m_hv->blockSignals(true);
m_hv->setDefaultSectionSize(newsize);
m_hv->blockSignals(false);
// Adjust offset and scrollbar. Maybe it isn't 100% perfect
// but proof of concept
// The test has sense without the define, too.
#define DO_CORRECT_OFFSET_AND_SB
#ifdef DO_CORRECT_OFFSET_AND_SB
int leftRemoved = (m_hv->visualIndex(logsection)) * (oldsize - newsize);
int newoffset = offset - leftRemoved;
if (newoffset < 0)
newoffset = 0;
if (newoffset > 0 && newoffset >= m_hv->count() * newsize - m_tv->viewport()->width())
m_hv->setOffsetToLastSection();
else
m_hv->setOffset(newoffset);
m_tv->horizontalScrollBar()->blockSignals(true);
m_tv->horizontalScrollBar()->setRange(0, m_hv->count() * newsize - m_tv->viewport()->width() );
m_tv->horizontalScrollBar()->setValue(newoffset);
m_tv->horizontalScrollBar()->blockSignals(false);
#endif
m_tv->setUpdatesEnabled(true);
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Window window;
// Comment in the line below to test selection with keyboard (space)
// tv.setEditTriggers(QAbstractItemView::NoEditTriggers);
QHeaderView *hHeader = window.tableView->horizontalHeader();
QHeaderView *vHeader = window.tableView->verticalHeader();
SomeHandler handler(hHeader, window.tableView);
hHeader->setDefaultSectionSize(30);
window.resize(600, 600);
window.show();
hHeader->setSectionsMovable(true);
vHeader->setSectionsMovable(true);
window.updateControls();
app.exec();
}
#include "qheaderviewtest1.moc"

View File

@ -0,0 +1,15 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## qtreeview Binary:
#####################################################################
qt_internal_add_manual_test(qtreeview
GUI
SOURCES
main.cpp
LIBRARIES
Qt::Gui
Qt::Widgets
)

View File

@ -0,0 +1,34 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtWidgets>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QFileSystemModel model;
QWidget window;
QTreeView *tree = new QTreeView(&window);
tree->setMaximumSize(1000, 600);
QHBoxLayout *layout = new QHBoxLayout;
layout->setSizeConstraint(QLayout::SetFixedSize);
layout->addWidget(tree);
window.setLayout(layout);
model.setRootPath("");
tree->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
tree->setModel(&model);
tree->setAnimated(false);
tree->setIndentation(20);
tree->setSortingEnabled(true);
tree->header()->setStretchLastSection(false);
window.setWindowTitle(QObject::tr("Dir View"));
tree->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
window.show();
return app.exec();
}

View File

@ -0,0 +1,3 @@
TEMPLATE = app
SOURCES = main.cpp
QT += widgets

View File

@ -0,0 +1,16 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## qtreewidget Binary:
#####################################################################
qt_internal_add_manual_test(qtreewidget
GUI
SOURCES
main.cpp
LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::Widgets
)

View File

@ -0,0 +1,128 @@
// Copyright (C) 2012 Thorbjørn Lund Martsum - tmartsum[at]gmail.com
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QVBoxLayout>
#include <QTreeWidget>
#include <QGroupBox>
#include <QRadioButton>
#include <QDialog>
#include <QApplication>
#include <QHeaderView>
class ExampleDlg : public QDialog
{
Q_OBJECT
public:
QVBoxLayout *groupLayout;
QVBoxLayout *dialogLayout;
QTreeWidget *treeWidget;
QGroupBox *groupBox;
QRadioButton *radioFirstName;
QRadioButton *radioLastName;
QRadioButton *radioDeveloperNo;
QRadioButton *radioTitle;
ExampleDlg() : QDialog(0)
{
dialogLayout = new QVBoxLayout(this);
treeWidget = new QTreeWidget(this);
dialogLayout->addWidget(treeWidget);
groupBox = new QGroupBox(this);
groupLayout = new QVBoxLayout(groupBox);
radioFirstName = new QRadioButton("First Name", groupBox);
groupLayout->addWidget(radioFirstName);
radioLastName = new QRadioButton("Last Name", groupBox);
groupLayout->addWidget(radioLastName);
radioDeveloperNo = new QRadioButton("Developer No.", groupBox);
groupLayout->addWidget(radioDeveloperNo);
radioTitle = new QRadioButton("Title", groupBox);
groupLayout->addWidget(radioTitle);
dialogLayout->addWidget(groupBox);
QStringList item1sl("Barry");
item1sl.append("Butter");
item1sl.append("12199");
item1sl.append("Key Maintainer");
QTreeWidgetItem *item1 = new QTreeWidgetItem(treeWidget, item1sl);
QStringList item2sl("Cordon");
item2sl.append("Rampsey");
item2sl.append("59299");
item2sl.append("Maintainer");
QTreeWidgetItem *item2 = new QTreeWidgetItem(item1, item2sl);
QStringList item3sl("Samuel le");
item3sl.append("Smackson");
item3sl.append("708");
item3sl.append("Contributer");
/* QTreeWidgetItem *item3 = */ new QTreeWidgetItem(item2, item3sl);
QStringList item4sl("Georg");
item4sl.append("Ambush");
item4sl.append("86999");
item4sl.append("Area Maintainer");
QTreeWidgetItem *item4 = new QTreeWidgetItem(item1, item4sl);
QStringList item5sl("Arne");
item5sl.append("Strassenleger");
item5sl.append("338999");
item5sl.append("Approver");
/* QTreeWidgetItem *item4 =*/ new QTreeWidgetItem(item4, item5sl);
treeWidget->setDragEnabled(true);
treeWidget->viewport()->setAcceptDrops(true);
treeWidget->setDragDropMode(QAbstractItemView::InternalMove);
for (int u = 0; u < 12; ++u) {
const QString username = QString("Anonymous User %1").arg(u + 1);
QStringList info;
info << username << username << QString::number(u + 1) << QStringLiteral("Test user");
new QTreeWidgetItem(item4, info);
}
treeWidget->expandAll();
treeWidget->setColumnCount(item2sl.size());
QStringList itemInfo("First Name");
itemInfo.append("Last Name");
itemInfo.append("Developer No.");
// Developer no. could also have been social security number og some other id.
itemInfo.append("Title");
treeWidget->setHeaderLabels(itemInfo);
radioLastName->setChecked(true);
connect(radioFirstName, SIGNAL(toggled(bool)), this, SLOT(fixDataInTree(bool)));
connect(radioLastName, SIGNAL(toggled(bool)), this, SLOT(fixDataInTree(bool)));
connect(radioDeveloperNo, SIGNAL(toggled(bool)), this, SLOT(fixDataInTree(bool)));
connect(radioTitle, SIGNAL(toggled(bool)), this, SLOT(fixDataInTree(bool)));
treeWidget->setTreePosition(-1);
treeWidget->header()->swapSections(0, 1);
}
protected slots:
void fixDataInTree(bool checked)
{
if (!checked)
return;
int colInTree = 0; // first Name
if (radioLastName->isChecked())
colInTree = 1;
if (radioDeveloperNo->isChecked())
colInTree = 2;
if (radioTitle->isChecked())
colInTree = 3;
treeWidget->header()->swapSections(0, treeWidget->header()->visualIndex(colInTree));
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
ExampleDlg d;
d.resize(d.sizeHint() * 3);
d.show();
app.exec();
}
#include "main.moc"

View File

@ -0,0 +1,3 @@
TEMPLATE = app
SOURCES = main.cpp
QT += widgets core-private

View File

@ -0,0 +1,17 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tableview-span-navigation Binary:
#####################################################################
qt_internal_add_manual_test(tableview-span-navigation
GUI
SOURCES
main.cpp
INCLUDE_DIRECTORIES
.
LIBRARIES
Qt::Gui
Qt::Widgets
)

View File

@ -0,0 +1,29 @@
// Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QApplication>
#include <QStandardItemModel>
#include <QTableView>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QStandardItemModel model(4, 4);
QTableView tableView;
tableView.setSizeAdjustPolicy(QTableView::AdjustToContents);
tableView.setModel(&model);
for (int row = 0; row < model.rowCount(); ++row) {
for (int column = 0; column < model.columnCount(); ++column) {
QModelIndex index = model.index(row, column, QModelIndex());
model.setData(index, QVariant(QString("%1,%2").arg(row).arg(column)));
}
}
tableView.setSpan(1, 1, 2, 2);
tableView.show();
return app.exec();
}

View File

@ -0,0 +1,8 @@
TEMPLATE = app
TARGET = tableview-span-navigation
INCLUDEPATH += .
QT += widgets
SOURCES += main.cpp