summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-06-26 14:26:30 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-06-28 09:56:40 +0200
commit95595d68bee7ef9e58100e4230f71d7f065eacb7 (patch)
tree3147bd753703331963b749a4050813b22da9505a /examples/widgets
parent532e1c9bf674f44da2b60fbc81bf3bc921641b7b (diff)
Move graphis view flow layout example to manual test
Pick-to: 6.5 6.6 Change-Id: I713816114b87def9eab79b893d13554f1c37c6a5 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/doc/images/graphicsflowlayout-example.pngbin18988 -> 0 bytes
-rw-r--r--examples/widgets/doc/src/graphicsview-flowlayout.qdoc28
-rw-r--r--examples/widgets/graphicsview/CMakeLists.txt1
-rw-r--r--examples/widgets/graphicsview/flowlayout/CMakeLists.txt38
-rw-r--r--examples/widgets/graphicsview/flowlayout/flowlayout.cpp170
-rw-r--r--examples/widgets/graphicsview/flowlayout/flowlayout.h44
-rw-r--r--examples/widgets/graphicsview/flowlayout/flowlayout.pro10
-rw-r--r--examples/widgets/graphicsview/flowlayout/main.cpp24
-rw-r--r--examples/widgets/graphicsview/flowlayout/window.cpp24
-rw-r--r--examples/widgets/graphicsview/flowlayout/window.h16
-rw-r--r--examples/widgets/graphicsview/graphicsview.pro1
11 files changed, 0 insertions, 356 deletions
diff --git a/examples/widgets/doc/images/graphicsflowlayout-example.png b/examples/widgets/doc/images/graphicsflowlayout-example.png
deleted file mode 100644
index 953d54086a..0000000000
--- a/examples/widgets/doc/images/graphicsflowlayout-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/widgets/doc/src/graphicsview-flowlayout.qdoc b/examples/widgets/doc/src/graphicsview-flowlayout.qdoc
deleted file mode 100644
index 179f3501df..0000000000
--- a/examples/widgets/doc/src/graphicsview-flowlayout.qdoc
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example graphicsview/flowlayout
- \title Graphics View Flow Layout Example
- \ingroup examples-graphicsview-layout
- \brief Demonstrates flow layout on a graphics view scene.
-
- The Graphics View Flow Layout example shows the use of a flow layout
- in a Graphics View widget.
-
- \image graphicsflowlayout-example.png
-
- This example uses a Graphics View to display the widget, which is a more
- customizable approach than displaying the flow layout in the application
- window (See \l {Flow Layout Example}).
-
- Graphics View Flow Layout snippet:
-
- \snippet graphicsview/flowlayout/main.cpp 1
-
- Flow Layout Example snippet:
-
- \snippet layouts/flowlayout/main.cpp 1
-
-
-*/
diff --git a/examples/widgets/graphicsview/CMakeLists.txt b/examples/widgets/graphicsview/CMakeLists.txt
index f3974f99c5..4eddec0c24 100644
--- a/examples/widgets/graphicsview/CMakeLists.txt
+++ b/examples/widgets/graphicsview/CMakeLists.txt
@@ -6,7 +6,6 @@ qt_internal_add_example(elasticnodes)
qt_internal_add_example(collidingmice)
qt_internal_add_example(basicgraphicslayouts)
qt_internal_add_example(diagramscene)
-qt_internal_add_example(flowlayout)
qt_internal_add_example(simpleanchorlayout)
if(QT_FEATURE_cursor AND QT_FEATURE_draganddrop)
qt_internal_add_example(dragdroprobot)
diff --git a/examples/widgets/graphicsview/flowlayout/CMakeLists.txt b/examples/widgets/graphicsview/flowlayout/CMakeLists.txt
deleted file mode 100644
index b15af3d02d..0000000000
--- a/examples/widgets/graphicsview/flowlayout/CMakeLists.txt
+++ /dev/null
@@ -1,38 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(flowlayout LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/graphicsview_flowlayout")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
-
-qt_standard_project_setup()
-
-qt_add_executable(graphicsview_flowlayout
- flowlayout.cpp flowlayout.h
- main.cpp
- window.cpp window.h
-)
-
-set_target_properties(graphicsview_flowlayout PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(graphicsview_flowlayout PRIVATE
- Qt6::Core
- Qt6::Gui
- Qt6::Widgets
-)
-
-install(TARGETS graphicsview_flowlayout
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/graphicsview/flowlayout/flowlayout.cpp b/examples/widgets/graphicsview/flowlayout/flowlayout.cpp
deleted file mode 100644
index ab5f4717b3..0000000000
--- a/examples/widgets/graphicsview/flowlayout/flowlayout.cpp
+++ /dev/null
@@ -1,170 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "flowlayout.h"
-
-#include <QtMath>
-
-FlowLayout::FlowLayout(QGraphicsLayoutItem *parent) : QGraphicsLayout(parent)
-{
- QSizePolicy sp = sizePolicy();
- sp.setHeightForWidth(true);
- setSizePolicy(sp);
-}
-
-void FlowLayout::insertItem(int index, QGraphicsLayoutItem *item)
-{
- item->setParentLayoutItem(this);
- if (index > m_items.count() || index < 0)
- index = m_items.count();
- m_items.insert(index, item);
- invalidate();
-}
-
-int FlowLayout::count() const
-{
- return m_items.count();
-}
-
-QGraphicsLayoutItem *FlowLayout::itemAt(int index) const
-{
- return m_items.value(index);
-}
-
-void FlowLayout::removeAt(int index)
-{
- m_items.removeAt(index);
- invalidate();
-}
-
-qreal FlowLayout::spacing(Qt::Orientation o) const
-{
- return m_spacing[int(o) - 1];
-}
-
-void FlowLayout::setSpacing(Qt::Orientations o, qreal spacing)
-{
- if (o & Qt::Horizontal)
- m_spacing[0] = spacing;
- if (o & Qt::Vertical)
- m_spacing[1] = spacing;
-}
-
-void FlowLayout::setGeometry(const QRectF &geom)
-{
- QGraphicsLayout::setGeometry(geom);
- doLayout(geom, true);
-}
-
-qreal FlowLayout::doLayout(const QRectF &geom, bool applyNewGeometry) const
-{
- qreal left, top, right, bottom;
- getContentsMargins(&left, &top, &right, &bottom);
- const qreal maxw = geom.width() - left - right;
-
- qreal x = 0;
- qreal y = 0;
- qreal maxRowHeight = 0;
- QSizeF pref;
- for (QGraphicsLayoutItem *item : m_items) {
- pref = item->effectiveSizeHint(Qt::PreferredSize);
- maxRowHeight = qMax(maxRowHeight, pref.height());
-
- qreal next_x;
- next_x = x + pref.width();
- if (next_x > maxw) {
- if (qFuzzyIsNull(x)) {
- pref.setWidth(maxw);
- } else {
- x = 0;
- next_x = pref.width();
- }
- y += maxRowHeight + spacing(Qt::Vertical);
- maxRowHeight = 0;
- }
-
- if (applyNewGeometry)
- item->setGeometry(QRectF(QPointF(left + x, top + y), pref));
- x = next_x + spacing(Qt::Horizontal);
- }
- maxRowHeight = qMax(maxRowHeight, pref.height());
- return top + y + maxRowHeight + bottom;
-}
-
-QSizeF FlowLayout::minSize(const QSizeF &constraint) const
-{
- QSizeF size(0, 0);
- qreal left, top, right, bottom;
- getContentsMargins(&left, &top, &right, &bottom);
- if (constraint.width() >= 0) { // height for width
- const qreal height = doLayout(QRectF(QPointF(0,0), constraint), false);
- size = QSizeF(constraint.width(), height);
- } else if (constraint.height() >= 0) { // width for height?
- // not supported
- } else {
- for (const QGraphicsLayoutItem *item : std::as_const(m_items))
- size = size.expandedTo(item->effectiveSizeHint(Qt::MinimumSize));
- size += QSizeF(left + right, top + bottom);
- }
- return size;
-}
-
-QSizeF FlowLayout::prefSize() const
-{
- qreal left, right;
- getContentsMargins(&left, nullptr, &right, nullptr);
-
- qreal maxh = 0;
- qreal totalWidth = 0;
- for (const QGraphicsLayoutItem *item : std::as_const(m_items)) {
- if (totalWidth > 0)
- totalWidth += spacing(Qt::Horizontal);
- QSizeF pref = item->effectiveSizeHint(Qt::PreferredSize);
- totalWidth += pref.width();
- maxh = qMax(maxh, pref.height());
- }
- maxh += spacing(Qt::Vertical);
-
- const qreal goldenAspectRatio = 1.61803399;
- qreal w = qSqrt(totalWidth * maxh * goldenAspectRatio) + left + right;
-
- return minSize(QSizeF(w, -1));
-}
-
-QSizeF FlowLayout::maxSize() const
-{
- qreal totalWidth = 0;
- qreal totalHeight = 0;
- for (const QGraphicsLayoutItem *item : std::as_const(m_items)) {
- if (totalWidth > 0)
- totalWidth += spacing(Qt::Horizontal);
- if (totalHeight > 0)
- totalHeight += spacing(Qt::Vertical);
- QSizeF pref = item->effectiveSizeHint(Qt::PreferredSize);
- totalWidth += pref.width();
- totalHeight += pref.height();
- }
-
- qreal left, top, right, bottom;
- getContentsMargins(&left, &top, &right, &bottom);
- return QSizeF(left + totalWidth + right, top + totalHeight + bottom);
-}
-
-QSizeF FlowLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
-{
- QSizeF sh = constraint;
- switch (which) {
- case Qt::PreferredSize:
- sh = prefSize();
- break;
- case Qt::MinimumSize:
- sh = minSize(constraint);
- break;
- case Qt::MaximumSize:
- sh = maxSize();
- break;
- default:
- break;
- }
- return sh;
-}
diff --git a/examples/widgets/graphicsview/flowlayout/flowlayout.h b/examples/widgets/graphicsview/flowlayout/flowlayout.h
deleted file mode 100644
index 028394827a..0000000000
--- a/examples/widgets/graphicsview/flowlayout/flowlayout.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef FLOWLAYOUT_H
-#define FLOWLAYOUT_H
-
-#include <QGraphicsLayout>
-
-class FlowLayout : public QGraphicsLayout
-{
-public:
- FlowLayout(QGraphicsLayoutItem *parent = nullptr);
- inline void addItem(QGraphicsLayoutItem *item);
- void insertItem(int index, QGraphicsLayoutItem *item);
- void setSpacing(Qt::Orientations o, qreal spacing);
- qreal spacing(Qt::Orientation o) const;
-
- // inherited functions
- void setGeometry(const QRectF &geom) override;
-
- int count() const override;
- QGraphicsLayoutItem *itemAt(int index) const override;
- void removeAt(int index) override;
-
-protected:
- QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override;
-
-private:
- qreal doLayout(const QRectF &geom, bool applyNewGeometry) const;
- QSizeF minSize(const QSizeF &constraint) const;
- QSizeF prefSize() const;
- QSizeF maxSize() const;
-
- QList<QGraphicsLayoutItem *> m_items;
- qreal m_spacing[2] = {6, 6};
-};
-
-
-inline void FlowLayout::addItem(QGraphicsLayoutItem *item)
-{
- insertItem(-1, item);
-}
-
-#endif // FLOWLAYOUT_H
diff --git a/examples/widgets/graphicsview/flowlayout/flowlayout.pro b/examples/widgets/graphicsview/flowlayout/flowlayout.pro
deleted file mode 100644
index 7830e3a008..0000000000
--- a/examples/widgets/graphicsview/flowlayout/flowlayout.pro
+++ /dev/null
@@ -1,10 +0,0 @@
-QT += widgets
-
-QMAKE_PROJECT_NAME = flowlayout_graphicsview
-
-HEADERS += flowlayout.h window.h
-SOURCES += flowlayout.cpp main.cpp window.cpp
-
-# install
-target.path = $$[QT_INSTALL_EXAMPLES]/widgets/graphicsview/flowlayout
-INSTALLS += target
diff --git a/examples/widgets/graphicsview/flowlayout/main.cpp b/examples/widgets/graphicsview/flowlayout/main.cpp
deleted file mode 100644
index 118b404870..0000000000
--- a/examples/widgets/graphicsview/flowlayout/main.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-//! [1]
-#include "window.h"
-
-#include <QApplication>
-#include <QGraphicsView>
-
-
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
-
- QGraphicsScene scene;
- QGraphicsView view(&scene);
- Window *w = new Window;
- scene.addItem(w);
-
- view.resize(400, 300);
- view.show();
-
- return app.exec();
-}
-//! [1]
diff --git a/examples/widgets/graphicsview/flowlayout/window.cpp b/examples/widgets/graphicsview/flowlayout/window.cpp
deleted file mode 100644
index ed9a5720d3..0000000000
--- a/examples/widgets/graphicsview/flowlayout/window.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#include "window.h"
-#include "flowlayout.h"
-
-#include <QGraphicsProxyWidget>
-#include <QLabel>
-
-Window::Window(QGraphicsItem *parent) : QGraphicsWidget(parent, Qt::Window)
-{
- FlowLayout *lay = new FlowLayout;
- const QString sentence(QLatin1String("I am not bothered by the fact that I am unknown."
- " I am bothered when I do not know others. (Confucius)"));
- const QList<QStringView> words = QStringView{ sentence }.split(QLatin1Char(' '), Qt::SkipEmptyParts);
- for (const QStringView &word : words) {
- QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(this);
- QLabel *label = new QLabel(word.toString());
- label->setFrameStyle(QFrame::Box | QFrame::Plain);
- proxy->setWidget(label);
- lay->addItem(proxy);
- }
- setLayout(lay);
-}
diff --git a/examples/widgets/graphicsview/flowlayout/window.h b/examples/widgets/graphicsview/flowlayout/window.h
deleted file mode 100644
index 2fc5570406..0000000000
--- a/examples/widgets/graphicsview/flowlayout/window.h
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-#ifndef WINDOW_H
-#define WINDOW_H
-
-#include <QGraphicsWidget>
-
-class Window : public QGraphicsWidget
-{
- Q_OBJECT
-public:
- Window(QGraphicsItem *parent = nullptr);
-};
-
-#endif // WINDOW_H
diff --git a/examples/widgets/graphicsview/graphicsview.pro b/examples/widgets/graphicsview/graphicsview.pro
index 32fb980eaf..d50f0b1adc 100644
--- a/examples/widgets/graphicsview/graphicsview.pro
+++ b/examples/widgets/graphicsview/graphicsview.pro
@@ -6,7 +6,6 @@ SUBDIRS = \
basicgraphicslayouts \
diagramscene \
dragdroprobot \
- flowlayout \
simpleanchorlayout
contains(DEFINES, QT_NO_CURSOR)|!qtConfig(draganddrop): SUBDIRS -= dragdroprobot