Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
testWrappingTabWidget.cpp
Go to the documentation of this file.
1#include <WrappingTabWidget.h>
2#include <DDqtControls.h>
3#include <QLineEdit>
4#include <QApplication>
5#include <set>
6#include <stdexcept>
7#include <iostream>
8
9int main(int argc, char **argv)
10{
11 QApplication app(argc, argv);
12 try
13 {
14 QWidget panel;
15 QCheckBox visibility(&panel);
16 auto *group = model::controls::box("Test", &panel, "Group help", &visibility);
17 auto *edit = new QLineEdit();
18 model::controls::field(model::controls::grid(group), 0, "Value", edit, "Detailed field help");
19 if(group->isChecked() || edit->isEnabled() || !visibility.isHidden())
20 {
21 throw std::runtime_error("Initial group state is incorrect");
22 }
23 group->setChecked(true);
24 if(!visibility.isChecked() || !edit->isEnabled())
25 {
26 throw std::runtime_error("Group checkbox did not enable its controls");
27 }
28 visibility.setChecked(false);
29 if(group->isChecked() || edit->isEnabled())
30 {
31 throw std::runtime_error("Programmatic visibility did not synchronize the group");
32 }
33 const auto *label = group->findChild<QLabel *>();
34 if(!label || label->buddy() != edit || edit->toolTip().isEmpty() || label->toolTip().isEmpty())
35 {
36 throw std::runtime_error("Missing field label or tooltip");
37 }
38 auto *panelLayout = new QVBoxLayout(&panel);
39 panelLayout->addWidget(group);
40 auto *nested = new model::controls::GroupBox("Nested", group);
41 nested->setCheckable(true);
42 nested->setChecked(false);
43 auto *nestedLayout = new QVBoxLayout(nested);
44 auto *nestedEdit = new QLineEdit("kept value");
45 nestedLayout->addWidget(nestedEdit);
46 model::controls::grid(group)->addWidget(nested, 1, 0, 1, 2);
47 auto *intentionallyHidden = new QLabel("Hidden option", group);
48 model::controls::grid(group)->addWidget(intentionallyHidden, 2, 0);
49 intentionallyHidden->hide();
50 panel.show();
51 app.processEvents();
52 const int collapsedHeight = group->sizeHint().height();
53 if(edit->isVisible())
54 {
55 throw std::runtime_error("Unchecked group contents are visible");
56 }
57 group->setChecked(true);
58 app.processEvents();
59 if(!edit->isVisible() || group->sizeHint().height() <= collapsedHeight || nestedEdit->isVisible())
60 {
61 throw std::runtime_error("Expansion failed or expanded an unchecked nested group");
62 }
63 nested->setChecked(true);
64 group->setChecked(false);
65 app.processEvents();
66 if(edit->isVisible() || nestedEdit->isVisible() || group->sizeHint().height() != collapsedHeight)
67 {
68 throw std::runtime_error("Collapse did not reclaim space");
69 }
70 group->setChecked(true);
71 app.processEvents();
72 if(!nestedEdit->isVisible() || nestedEdit->text() != "kept value" || !intentionallyHidden->isHidden())
73 {
74 throw std::runtime_error("Collapse lost nested state, values or intentional visibility");
75 }
77 for(const auto *name : {"Nodes", "Segments", "Loops", "Inclusions", "GlidePlanes", "Quadrature", "Chart",
78 "Fields", "SurfaceMesh", "SlipSystems"})
79 {
80 tabs.addTab(new QWidget(), name);
81 }
82 tabs.resize(340, 500);
83 tabs.show();
84 app.processEvents();
85 auto buttons = tabs.findChildren<QPushButton *>();
86 const auto checkLayout = [&]()
87 {
88 std::set<int> rows;
89 for(const auto *button : buttons)
90 {
91 rows.insert(button->y());
92 if(button->width() < button->sizeHint().width() ||
93 !button->parentWidget()->rect().contains(button->geometry()))
94 {
95 throw std::runtime_error("Actor tab label is clipped");
96 }
97 for(const auto *other : buttons)
98 {
99 if(button != other && button->geometry().intersects(other->geometry()))
100 {
101 throw std::runtime_error("Actor tab buttons overlap");
102 }
103 }
104 }
105 return rows.size();
106 };
107 const auto narrowRows = checkLayout();
108 if(narrowRows < 2)
109 {
110 throw std::runtime_error("Actor tabs did not wrap");
111 }
112 buttons[8]->click();
113 if(tabs.currentIndex() != 8 || !buttons[8]->isChecked() || buttons[0]->isChecked())
114 {
115 throw std::runtime_error("Actor tab selection failed");
116 }
117 tabs.resize(1000, 500);
118 app.processEvents();
119 if(checkLayout() >= narrowRows || tabs.currentIndex() != 8)
120 {
121 throw std::runtime_error("Resize lost selection or failed to reflow");
122 }
123 tabs.resize(240, 500);
124 app.processEvents();
125 checkLayout();
126 std::cout << "PASS: actor tab wrapping, full labels, selection and resize\n";
127 return 0;
128 }
129 catch(const std::exception &error)
130 {
131 std::cerr << error.what() << '\n';
132 return 1;
133 }
134}
int addTab(QWidget *page, const QString &label)
QGridLayout * grid(QGroupBox *group)
QGroupBox * box(const QString &title, QWidget *parent, const QString &description, QCheckBox *toggle=nullptr)
void field(QGridLayout *layout, int row, const QString &title, QWidget *input, const QString &description)
void argv
void b int argc