Automated with clang-tidy readability-identifier-naming (config added to .clang-tidy) plus scripted passes, per the updated rules now documented in CONTRIBUTING.md: - types (class/struct/enum/alias/template params): PascalCase - functions, variables, members: snake_case (incl. rational -> Rational) - private/protected members: trailing underscore; static member variables likewise (instance_, available_themes_) - constants and enum values: snake_case (kLinear -> k_linear, F32P -> f32p); ALL_CAPS reserved for macros - macros: OAK_ prefix (OLIVE_ADD_TEST/OLIVE_ASSERT/OLIVE_CONFIG -> OAK_ADD_TEST/OAK_ASSERT/OAK_CONFIG, GL_PREAMBLE -> OAK_GL_PREAMBLE, include guards -> OAK_*) - file names: all lowercase (Current/Plugin/OliveHost/OliveClip/ OlivePluginInstance -> current/plugin/olivehost/oliveclip/ oliveplugininstance) - getters share the member name sans underscore, setters set_foo() - Qt and third-party (OpenFX) virtual overrides and framework callbacks keep their original names (exempt in .clang-tidy) Manual follow-ups required where automation could not reach: - string-based QMetaObject/SIGNAL/SLOT references updated to renamed methods (AddTask, CreatedFile, DeleteSpecificFile, moveSelectionUp, ...) - macro bodies referencing renamed methods (OLIVE_CONFIG, NODE_DEFAULT_DESTRUCTOR, MANAGEDDISPLAYWIDGET_*) - self-shadowing locals renamed where signals/methods became same-named (size_changed, worker_count, selected_items, import param, filters) - third_party OFX member/namespace usages restored (OFX::Host::*, _created, _clipPrefsDirty, createInstance, clearPersistentMessage) - STL protocol aliases restored (const_iterator) with .clang-tidy ignore rules; qHash overloads restored Full build and test suite pass: ctest 4/4, ~1960 gtest cases green.
120 lines
3.3 KiB
C++
120 lines
3.3 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include "widget/columnedgridlayout/columnedgridlayout.h"
|
|
#include "widget/flowlayout/flowlayout.h"
|
|
|
|
TEST(WidgetLayout, FlowLayoutCountsAndTakesItems)
|
|
{
|
|
QWidget container;
|
|
FlowLayout *layout = new FlowLayout(&container, 0, 0, 0);
|
|
|
|
auto *a = new QPushButton(QStringLiteral("A"));
|
|
auto *b = new QPushButton(QStringLiteral("B"));
|
|
layout->addWidget(a);
|
|
layout->addWidget(b);
|
|
|
|
ASSERT_EQ(layout->count(), 2);
|
|
EXPECT_EQ(layout->itemAt(0)->widget(), a);
|
|
EXPECT_EQ(layout->itemAt(1)->widget(), b);
|
|
EXPECT_EQ(layout->itemAt(2), nullptr);
|
|
|
|
QLayoutItem *taken = layout->takeAt(0);
|
|
ASSERT_NE(taken, nullptr);
|
|
EXPECT_EQ(taken->widget(), a);
|
|
EXPECT_EQ(layout->count(), 1);
|
|
delete taken;
|
|
|
|
EXPECT_EQ(layout->takeAt(99), nullptr);
|
|
EXPECT_EQ(layout->takeAt(-1), nullptr);
|
|
}
|
|
|
|
TEST(WidgetLayout, FlowLayoutSpacingGetters)
|
|
{
|
|
QWidget container;
|
|
FlowLayout *layout = new FlowLayout(&container, 0, 7, 9);
|
|
|
|
EXPECT_EQ(layout->horizontal_spacing(), 7);
|
|
EXPECT_EQ(layout->vertical_spacing(), 9);
|
|
}
|
|
|
|
TEST(WidgetLayout, FlowLayoutWrapsAndComputesHeightForWidth)
|
|
{
|
|
QWidget container;
|
|
FlowLayout *layout = new FlowLayout(&container, 0, 0, 0);
|
|
|
|
const int k_button_count = 5;
|
|
for (int i = 0; i < k_button_count; i++) {
|
|
auto *b = new QPushButton(QStringLiteral("Btn"));
|
|
b->setFixedSize(100, 30);
|
|
layout->addWidget(b);
|
|
}
|
|
|
|
EXPECT_TRUE(layout->hasHeightForWidth());
|
|
EXPECT_EQ(layout->expandingDirections(), Qt::Horizontal | Qt::Vertical);
|
|
|
|
// 1000px fits all five 100px buttons on one row; 250px fits two per row,
|
|
// so five buttons need three rows
|
|
EXPECT_EQ(layout->heightForWidth(1000), 30);
|
|
EXPECT_EQ(layout->heightForWidth(250), 90);
|
|
|
|
// Lay out for real and inspect positions
|
|
layout->setGeometry(QRect(0, 0, 250, 90));
|
|
ASSERT_EQ(layout->count(), k_button_count);
|
|
|
|
EXPECT_EQ(layout->itemAt(0)->geometry().topLeft(), QPoint(0, 0));
|
|
EXPECT_EQ(layout->itemAt(1)->geometry().topLeft(), QPoint(100, 0));
|
|
|
|
// Third button wraps to the second row, fifth to the third
|
|
EXPECT_EQ(layout->itemAt(2)->geometry().topLeft(), QPoint(0, 30));
|
|
EXPECT_EQ(layout->itemAt(4)->geometry().topLeft(), QPoint(0, 60));
|
|
|
|
EXPECT_TRUE(layout->sizeHint().isValid());
|
|
}
|
|
|
|
TEST(WidgetLayout, ColumnedGridLayoutArrangesByMaximumColumns)
|
|
{
|
|
QWidget container;
|
|
olive::ColumnedGridLayout *layout =
|
|
new olive::ColumnedGridLayout(&container, 3);
|
|
|
|
QVector<QPushButton *> buttons;
|
|
for (int i = 0; i < 7; i++) {
|
|
auto *b = new QPushButton(QString::number(i));
|
|
buttons.append(b);
|
|
layout->add(b);
|
|
}
|
|
|
|
EXPECT_EQ(layout->maximum_columns(), 3);
|
|
EXPECT_EQ(layout->count(), 7);
|
|
|
|
// Widgets are placed row-major with at most three columns
|
|
for (int i = 0; i < buttons.size(); i++) {
|
|
QLayoutItem *item = layout->itemAtPosition(i / 3, i % 3);
|
|
ASSERT_NE(item, nullptr) << i;
|
|
EXPECT_EQ(item->widget(), buttons.at(i)) << i;
|
|
}
|
|
|
|
// Nothing beyond the last populated cell
|
|
EXPECT_EQ(layout->itemAtPosition(2, 1), nullptr);
|
|
|
|
layout->set_maximum_columns(4);
|
|
EXPECT_EQ(layout->maximum_columns(), 4);
|
|
}
|
|
|
|
TEST(WidgetLayout, ColumnedGridLayoutWithoutColumnLimitStillAdds)
|
|
{
|
|
QWidget container;
|
|
olive::ColumnedGridLayout *layout = new olive::ColumnedGridLayout(&container);
|
|
|
|
EXPECT_EQ(layout->maximum_columns(), 0);
|
|
|
|
auto *a = new QPushButton(QStringLiteral("A"));
|
|
auto *b = new QPushButton(QStringLiteral("B"));
|
|
layout->add(a);
|
|
layout->add(b);
|
|
|
|
EXPECT_EQ(layout->count(), 2);
|
|
}
|