format VisualGroup.cpp file
Signed-off-by: Tayou <tayou@gmx.net>
This commit is contained in:
parent
54d88e4dbf
commit
534d156b12
@ -35,22 +35,17 @@
|
|||||||
|
|
||||||
#include "VisualGroup.h"
|
#include "VisualGroup.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QDebug>
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
#include <QApplication>
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
#include "InstanceView.h"
|
#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)
|
VisualGroup::VisualGroup(const VisualGroup* other) : view(other->view), text(other->text), collapsed(other->collapsed) {}
|
||||||
: view(other->view), text(other->text), collapsed(other->collapsed)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void VisualGroup::update()
|
void VisualGroup::update()
|
||||||
{
|
{
|
||||||
@ -64,10 +59,8 @@ void VisualGroup::update()
|
|||||||
int positionInRow = 0;
|
int positionInRow = 0;
|
||||||
int currentRow = 0;
|
int currentRow = 0;
|
||||||
int offsetFromTop = 0;
|
int offsetFromTop = 0;
|
||||||
for (auto item: temp_items)
|
for (auto item : temp_items) {
|
||||||
{
|
if (positionInRow == itemsPerRow) {
|
||||||
if(positionInRow == itemsPerRow)
|
|
||||||
{
|
|
||||||
rows[currentRow].height = maxRowHeight;
|
rows[currentRow].height = maxRowHeight;
|
||||||
rows[currentRow].top = offsetFromTop;
|
rows[currentRow].top = offsetFromTop;
|
||||||
currentRow++;
|
currentRow++;
|
||||||
@ -83,8 +76,7 @@ void VisualGroup::update()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto itemHeight = view->itemDelegate()->sizeHint(viewItemOption, item).height();
|
auto itemHeight = view->itemDelegate()->sizeHint(viewItemOption, item).height();
|
||||||
if(itemHeight > maxRowHeight)
|
if (itemHeight > maxRowHeight) {
|
||||||
{
|
|
||||||
maxRowHeight = itemHeight;
|
maxRowHeight = itemHeight;
|
||||||
}
|
}
|
||||||
rows[currentRow].items.append(item);
|
rows[currentRow].items.append(item);
|
||||||
@ -97,12 +89,9 @@ void VisualGroup::update()
|
|||||||
QPair<int, int> VisualGroup::positionOf(const QModelIndex& index) const
|
QPair<int, int> VisualGroup::positionOf(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
int y = 0;
|
int y = 0;
|
||||||
for (auto & row: rows)
|
for (auto& row : rows) {
|
||||||
{
|
for (auto x = 0; x < row.items.size(); x++) {
|
||||||
for(auto x = 0; x < row.items.size(); x++)
|
if (row.items[x] == index) {
|
||||||
{
|
|
||||||
if(row.items[x] == index)
|
|
||||||
{
|
|
||||||
return qMakePair(x, y);
|
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 body_end = body_start + contentHeight() + 5; // FIXME: wtf is this 5?
|
||||||
int y = pos.y();
|
int y = pos.y();
|
||||||
// int x = pos.x();
|
// int x = pos.x();
|
||||||
if (y < y_start)
|
if (y < y_start) {
|
||||||
{
|
|
||||||
results = VisualGroup::NoHit;
|
results = VisualGroup::NoHit;
|
||||||
}
|
} else if (y < body_start) {
|
||||||
else if (y < body_start)
|
|
||||||
{
|
|
||||||
results = VisualGroup::HeaderHit;
|
results = VisualGroup::HeaderHit;
|
||||||
int collapseSize = headerHeight() - 4;
|
int collapseSize = headerHeight() - 4;
|
||||||
|
|
||||||
// the icon
|
// the icon
|
||||||
QRect iconRect = QRect(view->m_leftMargin + 2, 2 + y_start, collapseSize, collapseSize);
|
QRect iconRect = QRect(view->m_leftMargin + 2, 2 + y_start, collapseSize, collapseSize);
|
||||||
if (iconRect.contains(pos))
|
if (iconRect.contains(pos)) {
|
||||||
{
|
|
||||||
results |= VisualGroup::CheckboxHit;
|
results |= VisualGroup::CheckboxHit;
|
||||||
}
|
}
|
||||||
}
|
} else if (y < body_end) {
|
||||||
else if (y < body_end)
|
|
||||||
{
|
|
||||||
results |= VisualGroup::BodyHit;
|
results |= VisualGroup::BodyHit;
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
@ -183,10 +166,14 @@ void VisualGroup::drawHeader(QPainter *painter, const QStyleOptionViewItem &opti
|
|||||||
|
|
||||||
QPolygon polygon;
|
QPolygon polygon;
|
||||||
if (collapsed) {
|
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);
|
painter->drawPolyline(polygon);
|
||||||
} else {
|
} 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->drawPolyline(polygon);
|
||||||
}
|
}
|
||||||
painter->restore();
|
painter->restore();
|
||||||
@ -235,8 +222,7 @@ int VisualGroup::headerHeight() const
|
|||||||
|
|
||||||
int VisualGroup::contentHeight() const
|
int VisualGroup::contentHeight() const
|
||||||
{
|
{
|
||||||
if (collapsed)
|
if (collapsed) {
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
auto last = rows[numRows() - 1];
|
auto last = rows[numRows() - 1];
|
||||||
@ -256,11 +242,9 @@ int VisualGroup::verticalPosition() const
|
|||||||
QList<QModelIndex> VisualGroup::items() const
|
QList<QModelIndex> VisualGroup::items() const
|
||||||
{
|
{
|
||||||
QList<QModelIndex> indices;
|
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);
|
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);
|
indices.append(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user