format VisualGroup.cpp file

Signed-off-by: Tayou <tayou@gmx.net>
This commit is contained in:
Tayou 2023-06-28 20:06:17 +02:00
parent 54d88e4dbf
commit 534d156b12
No known key found for this signature in database
GPG Key ID: 02CA43C1CB6E9887

View File

@ -35,22 +35,17 @@
#include "VisualGroup.h"
#include <QApplication>
#include <QDebug>
#include <QModelIndex>
#include <QPainter>
#include <QtMath>
#include <QApplication>
#include <QDebug>
#include "InstanceView.h"
VisualGroup::VisualGroup(const QString &text, InstanceView *view) : view(view), text(text), collapsed(false)
{
}
VisualGroup::VisualGroup(const QString& text, InstanceView* view) : view(view), text(text), collapsed(false) {}
VisualGroup::VisualGroup(const VisualGroup *other)
: view(other->view), text(other->text), collapsed(other->collapsed)
{
}
VisualGroup::VisualGroup(const VisualGroup* other) : view(other->view), text(other->text), collapsed(other->collapsed) {}
void VisualGroup::update()
{
@ -64,10 +59,8 @@ void VisualGroup::update()
int positionInRow = 0;
int currentRow = 0;
int offsetFromTop = 0;
for (auto item: temp_items)
{
if(positionInRow == itemsPerRow)
{
for (auto item : temp_items) {
if (positionInRow == itemsPerRow) {
rows[currentRow].height = maxRowHeight;
rows[currentRow].top = offsetFromTop;
currentRow++;
@ -83,8 +76,7 @@ void VisualGroup::update()
#endif
auto itemHeight = view->itemDelegate()->sizeHint(viewItemOption, item).height();
if(itemHeight > maxRowHeight)
{
if (itemHeight > maxRowHeight) {
maxRowHeight = itemHeight;
}
rows[currentRow].items.append(item);
@ -97,12 +89,9 @@ void VisualGroup::update()
QPair<int, int> VisualGroup::positionOf(const QModelIndex& index) const
{
int y = 0;
for (auto & row: rows)
{
for(auto x = 0; x < row.items.size(); x++)
{
if(row.items[x] == index)
{
for (auto& row : rows) {
for (auto x = 0; x < row.items.size(); x++) {
if (row.items[x] == index) {
return qMakePair(x, y);
}
}
@ -132,24 +121,18 @@ VisualGroup::HitResults VisualGroup::hitScan(const QPoint &pos) const
int body_end = body_start + contentHeight() + 5; // FIXME: wtf is this 5?
int y = pos.y();
// int x = pos.x();
if (y < y_start)
{
if (y < y_start) {
results = VisualGroup::NoHit;
}
else if (y < body_start)
{
} else if (y < body_start) {
results = VisualGroup::HeaderHit;
int collapseSize = headerHeight() - 4;
// the icon
QRect iconRect = QRect(view->m_leftMargin + 2, 2 + y_start, collapseSize, collapseSize);
if (iconRect.contains(pos))
{
if (iconRect.contains(pos)) {
results |= VisualGroup::CheckboxHit;
}
}
else if (y < body_end)
{
} else if (y < body_end) {
results |= VisualGroup::BodyHit;
}
return results;
@ -183,10 +166,14 @@ void VisualGroup::drawHeader(QPainter *painter, const QStyleOptionViewItem &opti
QPolygon polygon;
if (collapsed) {
polygon << QPoint(arrowOffsetLeft - arrowSize/2, centerHeight - arrowSize) << QPoint(arrowOffsetLeft + arrowSize/2, centerHeight) << QPoint(arrowOffsetLeft - arrowSize/2, centerHeight + arrowSize);
polygon << QPoint(arrowOffsetLeft - arrowSize / 2, centerHeight - arrowSize)
<< QPoint(arrowOffsetLeft + arrowSize / 2, centerHeight)
<< QPoint(arrowOffsetLeft - arrowSize / 2, centerHeight + arrowSize);
painter->drawPolyline(polygon);
} else {
polygon << QPoint(arrowOffsetLeft - arrowSize, centerHeight - arrowSize/2) << QPoint(arrowOffsetLeft, centerHeight + arrowSize/2) << QPoint(arrowOffsetLeft + arrowSize, centerHeight - arrowSize/2);
polygon << QPoint(arrowOffsetLeft - arrowSize, centerHeight - arrowSize / 2)
<< QPoint(arrowOffsetLeft, centerHeight + arrowSize / 2)
<< QPoint(arrowOffsetLeft + arrowSize, centerHeight - arrowSize / 2);
painter->drawPolyline(polygon);
}
painter->restore();
@ -235,8 +222,7 @@ int VisualGroup::headerHeight() const
int VisualGroup::contentHeight() const
{
if (collapsed)
{
if (collapsed) {
return 0;
}
auto last = rows[numRows() - 1];
@ -256,11 +242,9 @@ int VisualGroup::verticalPosition() const
QList<QModelIndex> VisualGroup::items() const
{
QList<QModelIndex> indices;
for (int i = 0; i < view->model()->rowCount(); ++i)
{
for (int i = 0; i < view->model()->rowCount(); ++i) {
const QModelIndex index = view->model()->index(i, 0);
if (index.data(InstanceViewRoles::GroupRole).toString() == text)
{
if (index.data(InstanceViewRoles::GroupRole).toString() == text) {
indices.append(index);
}
}