forked from qt-creator/qt-creator
LUA: Clang format layoutbuilder.* with manual adaptations
Change-Id: I709db191c23320c1e6b34deae4afac4c28de54b3 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -44,13 +44,16 @@ class FlowLayout : public QLayout
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1)
|
explicit FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1)
|
||||||
: QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing)
|
: QLayout(parent)
|
||||||
|
, m_hSpace(hSpacing)
|
||||||
|
, m_vSpace(vSpacing)
|
||||||
{
|
{
|
||||||
setContentsMargins(margin, margin, margin, margin);
|
setContentsMargins(margin, margin, margin, margin);
|
||||||
}
|
}
|
||||||
|
|
||||||
FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1)
|
FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1)
|
||||||
: m_hSpace(hSpacing), m_vSpace(vSpacing)
|
: m_hSpace(hSpacing)
|
||||||
|
, m_vSpace(vSpacing)
|
||||||
{
|
{
|
||||||
setContentsMargins(margin, margin, margin, margin);
|
setContentsMargins(margin, margin, margin, margin);
|
||||||
}
|
}
|
||||||
@@ -80,10 +83,7 @@ public:
|
|||||||
return smartSpacing(QStyle::PM_LayoutVerticalSpacing);
|
return smartSpacing(QStyle::PM_LayoutVerticalSpacing);
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::Orientations expandingDirections() const override
|
Qt::Orientations expandingDirections() const override { return {}; }
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasHeightForWidth() const override { return true; }
|
bool hasHeightForWidth() const override { return true; }
|
||||||
|
|
||||||
@@ -95,10 +95,7 @@ public:
|
|||||||
|
|
||||||
int count() const override { return itemList.size(); }
|
int count() const override { return itemList.size(); }
|
||||||
|
|
||||||
QLayoutItem *itemAt(int index) const override
|
QLayoutItem *itemAt(int index) const override { return itemList.value(index); }
|
||||||
{
|
|
||||||
return itemList.value(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
QSize minimumSize() const override
|
QSize minimumSize() const override
|
||||||
{
|
{
|
||||||
@@ -118,10 +115,7 @@ public:
|
|||||||
doLayout(rect, false);
|
doLayout(rect, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize sizeHint() const override
|
QSize sizeHint() const override { return minimumSize(); }
|
||||||
{
|
|
||||||
return minimumSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
QLayoutItem *takeAt(int index) override
|
QLayoutItem *takeAt(int index) override
|
||||||
{
|
{
|
||||||
@@ -144,13 +138,15 @@ private:
|
|||||||
for (QLayoutItem *item : itemList) {
|
for (QLayoutItem *item : itemList) {
|
||||||
QWidget *wid = item->widget();
|
QWidget *wid = item->widget();
|
||||||
int spaceX = horizontalSpacing();
|
int spaceX = horizontalSpacing();
|
||||||
if (spaceX == -1)
|
if (spaceX == -1) {
|
||||||
spaceX = wid->style()->layoutSpacing(
|
spaceX = wid->style()->layoutSpacing(
|
||||||
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
|
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
|
||||||
|
}
|
||||||
int spaceY = verticalSpacing();
|
int spaceY = verticalSpacing();
|
||||||
if (spaceY == -1)
|
if (spaceY == -1) {
|
||||||
spaceY = wid->style()->layoutSpacing(
|
spaceY = wid->style()->layoutSpacing(
|
||||||
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
|
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
|
||||||
|
}
|
||||||
int nextX = x + item->sizeHint().width() + spaceX;
|
int nextX = x + item->sizeHint().width() + spaceX;
|
||||||
if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) {
|
if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) {
|
||||||
x = effectiveRect.x();
|
x = effectiveRect.x();
|
||||||
@@ -199,7 +195,6 @@ private:
|
|||||||
\sa Layouting::Widget, Layouting::Layout
|
\sa Layouting::Widget, Layouting::Layout
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class Layouting::Layout
|
\class Layouting::Layout
|
||||||
\inmodule QtCreator
|
\inmodule QtCreator
|
||||||
@@ -230,15 +225,18 @@ LayoutItem::LayoutItem() = default;
|
|||||||
LayoutItem::~LayoutItem() = default;
|
LayoutItem::~LayoutItem() = default;
|
||||||
|
|
||||||
LayoutItem::LayoutItem(QLayout *l)
|
LayoutItem::LayoutItem(QLayout *l)
|
||||||
: layout(l), empty(!l)
|
: layout(l)
|
||||||
|
, empty(!l)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
LayoutItem::LayoutItem(QWidget *w)
|
LayoutItem::LayoutItem(QWidget *w)
|
||||||
: widget(w), empty(!w)
|
: widget(w)
|
||||||
|
, empty(!w)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
LayoutItem::LayoutItem(const QString &t)
|
LayoutItem::LayoutItem(const QString &t)
|
||||||
: text(t), empty(t.isEmpty())
|
: text(t)
|
||||||
|
, empty(t.isEmpty())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -333,7 +331,6 @@ static void addItemToFlowLayout(FlowLayout *layout, const LayoutItem &item)
|
|||||||
\brief The Stretch class represents some stretch in a layout.
|
\brief The Stretch class represents some stretch in a layout.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Layout
|
// Layout
|
||||||
|
|
||||||
void Layout::span(int cols, int rows)
|
void Layout::span(int cols, int rows)
|
||||||
@@ -527,12 +524,21 @@ void Layout::flush()
|
|||||||
// if (auto widget = builder.stack.at(builder.stack.size() - 2).widget) {
|
// if (auto widget = builder.stack.at(builder.stack.size() - 2).widget) {
|
||||||
// a = widget->style()->styleHint(QStyle::SH_FormLayoutLabelAlignment);
|
// a = widget->style()->styleHint(QStyle::SH_FormLayoutLabelAlignment);
|
||||||
}
|
}
|
||||||
if (item.widget)
|
if (item.widget) {
|
||||||
lt->addWidget(item.widget, currentGridRow, currentGridColumn, item.spanRows, item.spanCols, a);
|
lt->addWidget(
|
||||||
else if (item.layout)
|
item.widget, currentGridRow, currentGridColumn, item.spanRows, item.spanCols, a);
|
||||||
lt->addLayout(item.layout, currentGridRow, currentGridColumn, item.spanRows, item.spanCols, a);
|
} else if (item.layout) {
|
||||||
else if (!item.text.isEmpty())
|
lt->addLayout(
|
||||||
lt->addWidget(createLabel(item.text), currentGridRow, currentGridColumn, item.spanRows, item.spanCols, a);
|
item.layout, currentGridRow, currentGridColumn, item.spanRows, item.spanCols, a);
|
||||||
|
} else if (!item.text.isEmpty()) {
|
||||||
|
lt->addWidget(
|
||||||
|
createLabel(item.text),
|
||||||
|
currentGridRow,
|
||||||
|
currentGridColumn,
|
||||||
|
item.spanRows,
|
||||||
|
item.spanCols,
|
||||||
|
a);
|
||||||
|
}
|
||||||
currentGridColumn += item.spanCols;
|
currentGridColumn += item.spanCols;
|
||||||
// Intentionally not used, use 'br'/'empty' for vertical progress.
|
// Intentionally not used, use 'br'/'empty' for vertical progress.
|
||||||
// currentGridRow += item.spanRows;
|
// currentGridRow += item.spanRows;
|
||||||
@@ -976,7 +982,8 @@ TabWidget::TabWidget(std::initializer_list<I> ps)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Tab::Tab(const QString &tabName, const Layout &inner)
|
Tab::Tab(const QString &tabName, const Layout &inner)
|
||||||
: tabName(tabName), inner(inner)
|
: tabName(tabName)
|
||||||
|
, inner(inner)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void addToTabWidget(TabWidget *tabWidget, const Tab &tab)
|
void addToTabWidget(TabWidget *tabWidget, const Tab &tab)
|
||||||
@@ -986,9 +993,10 @@ void addToTabWidget(TabWidget *tabWidget, const Tab &tab)
|
|||||||
|
|
||||||
// Special If
|
// Special If
|
||||||
|
|
||||||
If::If(bool condition,
|
If::If(
|
||||||
const std::initializer_list<Layout::I> ifcase,
|
bool condition,
|
||||||
const std::initializer_list<Layout::I> thencase)
|
const std::initializer_list<Layout::I> ifcase,
|
||||||
|
const std::initializer_list<Layout::I> thencase)
|
||||||
: used(condition ? ifcase : thencase)
|
: used(condition ? ifcase : thencase)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@@ -1009,11 +1017,14 @@ QWidget *createHr(QWidget *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Span::Span(int cols, const Layout::I &item)
|
Span::Span(int cols, const Layout::I &item)
|
||||||
: item(item), spanCols(cols)
|
: item(item)
|
||||||
|
, spanCols(cols)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Span::Span(int cols, int rows, const Layout::I &item)
|
Span::Span(int cols, int rows, const Layout::I &item)
|
||||||
: item(item), spanCols(cols), spanRows(rows)
|
: item(item)
|
||||||
|
, spanCols(cols)
|
||||||
|
, spanRows(rows)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void addToLayout(Layout *layout, const Span &inner)
|
void addToLayout(Layout *layout, const Span &inner)
|
||||||
@@ -1052,5 +1063,4 @@ void addToLayout(Layout *layout, const Stretch &inner)
|
|||||||
// item->onAdd = [t](LayoutBuilder &builder) { doAddWidget(builder, t); };
|
// item->onAdd = [t](LayoutBuilder &builder) { doAddWidget(builder, t); };
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
} // namespace Layouting
|
||||||
} // Layouting
|
|
||||||
|
@@ -185,7 +185,9 @@ public:
|
|||||||
class QTCREATOR_UTILS_EXPORT Stretch
|
class QTCREATOR_UTILS_EXPORT Stretch
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit Stretch(int stretch) : stretch(stretch) {}
|
explicit Stretch(int stretch)
|
||||||
|
: stretch(stretch)
|
||||||
|
{}
|
||||||
|
|
||||||
int stretch;
|
int stretch;
|
||||||
};
|
};
|
||||||
@@ -193,7 +195,9 @@ public:
|
|||||||
class QTCREATOR_UTILS_EXPORT Space
|
class QTCREATOR_UTILS_EXPORT Space
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit Space(int space) : space(space) {}
|
explicit Space(int space)
|
||||||
|
: space(space)
|
||||||
|
{}
|
||||||
|
|
||||||
int space;
|
int space;
|
||||||
};
|
};
|
||||||
@@ -325,7 +329,9 @@ public:
|
|||||||
using Implementation = QStackedWidget;
|
using Implementation = QStackedWidget;
|
||||||
using I = Building::BuilderItem<Stack>;
|
using I = Building::BuilderItem<Stack>;
|
||||||
|
|
||||||
Stack() : Stack({}) {}
|
Stack()
|
||||||
|
: Stack({})
|
||||||
|
{}
|
||||||
Stack(std::initializer_list<I> items);
|
Stack(std::initializer_list<I> items);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -389,8 +395,8 @@ public:
|
|||||||
|
|
||||||
// Special dispatchers
|
// Special dispatchers
|
||||||
|
|
||||||
|
class BindToId
|
||||||
class BindToId {};
|
{};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto bindTo(T **p)
|
auto bindTo(T **p)
|
||||||
@@ -404,8 +410,13 @@ void doit(Interface *x, BindToId, auto p)
|
|||||||
*p = static_cast<typename Interface::Implementation *>(x->ptr);
|
*p = static_cast<typename Interface::Implementation *>(x->ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
class IdId {};
|
class IdId
|
||||||
auto id(auto p) { return Building::IdAndArg{IdId{}, p}; }
|
{};
|
||||||
|
|
||||||
|
auto id(auto p)
|
||||||
|
{
|
||||||
|
return Building::IdAndArg{IdId{}, p};
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Interface>
|
template <typename Interface>
|
||||||
void doit(Interface *x, IdId, auto p)
|
void doit(Interface *x, IdId, auto p)
|
||||||
@@ -511,4 +522,4 @@ QTCREATOR_UTILS_EXPORT LayoutModifier spacing(int space);
|
|||||||
|
|
||||||
QTCREATOR_UTILS_EXPORT QWidget *createHr(QWidget *parent = nullptr);
|
QTCREATOR_UTILS_EXPORT QWidget *createHr(QWidget *parent = nullptr);
|
||||||
|
|
||||||
} // Layouting
|
} // namespace Layouting
|
||||||
|
Reference in New Issue
Block a user