Repository navigation
Expand file tree
/
Copy pathBerechnungsModell.cpp
More file actions
154 lines (138 loc) · 4.93 KB
/
Copy pathBerechnungsModell.cpp
File metadata and controls
154 lines (138 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/**************************************************************************************************
* Datei: BerechnungsModell.cpp
* Autor: Stefan <St0fF / Neoplasia ^ the Obsessed Maniacs> Kaps, 2024-2025
*
* Dieses BerechnungsModell stellt über die StrategieFactory eine aktuelle Berechnung und Animation
* zur Verfügung.
**************************************************************************************************
* Diese Datei ist Teil von PieMenuTesting.
*
* PieMenuTesting ist Freie Software: Sie können es unter den Bedingungen
* der GNU General Public License, wie von der Free Software Foundation,
* Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
* veröffentlichten Version, weiter verteilen und/oder modifizieren.
*
* PieMenuTesting wird in der Hoffnung, dass es nützlich sein wird, aber
* OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
* Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
* Siehe die GNU General Public License für weitere Details.
*
* Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
* Programm erhalten haben. Wenn nicht, siehe <https://www.gnu.org/licenses/>.
*************************************************************************************************/
#include "BerechnungsModell.h"
BerechnungsModell::BerechnungsModell( QObject *parent )
: QAbstractItemModel( parent )
{
for ( auto i : StrategieFactory::Classes() ) _strategien.append( i.first() );
}
BerechnungsModell::~BerechnungsModell() {}
int BerechnungsModell::rowCount( const QModelIndex &parent ) const
{
// Top Level Items:
if ( !parent.isValid() ) return _strategien.count();
else if ( parent.row() < _strategien.count() )
return _strategien.at( parent.row() )->options().count();
return 0;
}
int BerechnungsModell::columnCount( const QModelIndex &parent ) const
{
return 1; // always only one level of information to display
}
QVariant BerechnungsModell::data( const QModelIndex &index, int role ) const
{
switch ( role )
{
case Qt::DisplayRole:
if ( index.isValid() )
{
if ( index.parent().isValid() )
{
if ( index.parent().row() < _strategien.count() )
{
auto &strat = _strategien.at( index.parent().row() );
if ( index.row() < strat->options().count() )
return strat->options().at( index.row() );
}
} else if ( index.row() < _strategien.count() )
return _strategien.at( index.row() )->description();
}
[[fallthrough]];
default: return {};
}
}
QModelIndex BerechnungsModell::index( int row, int column, const QModelIndex &parent ) const
{
if ( column == 0 )
if ( !parent.isValid() )
{
if ( row < _strategien.count() ) return createIndex( row, column, nullptr );
} else if ( parent.row() < _strategien.count() ) {
auto &strat = _strategien.at( parent.row() );
if ( row < strat->options().count() )
return createIndex( row, column, _strategien.at( parent.row() ) );
}
return {};
}
QModelIndex BerechnungsModell::parent( const QModelIndex &index ) const
{
if ( index.isValid() )
{
if ( auto strat = static_cast< StrategieBasis * >( index.internalPointer() ) )
{
auto i = _strategien.indexOf( strat );
if ( i >= 0 ) return createIndex( i, 0, nullptr );
}
}
return {};
}
void BerechnungsModell::calculateItems( int row, StrategieBasis::Items &items_with_sizes )
{
if ( row >= 0 && row < _strategien.count() )
_strategien.at( row )->calculateItems( items_with_sizes );
}
Opacities BerechnungsModell::animateItems( int row, qreal t,
StrategieBasis::Items &items_with_sizes )
{
if ( row >= 0 && row < _strategien.count() )
return _strategien.at( row )->animateItems( items_with_sizes, t );
return {};
}
int BerechnungsModell::defaultRadiusPolicy( const QModelIndex &index ) const
{
auto r = index.parent().isValid() ? index.parent().row() : index.row();
if ( r >= 0 && r < _strategien.count() ) return _strategien[ r ]->defaultOption();
else return -1;
}
void BerechnungsModell::setStartAngle( int angle )
{
for ( auto i : _strategien ) i->setStartAngle( angle );
emit uniformDataChanged();
}
void BerechnungsModell::setMinDelta( int delta )
{
for ( auto i : _strategien ) i->setMinDelta( delta );
emit uniformDataChanged();
}
void BerechnungsModell::setMaxDelta( int delta )
{
for ( auto i : _strategien ) i->setMaxDelta( delta );
emit uniformDataChanged();
}
void BerechnungsModell::setOpenParam( int v )
{
for ( auto i : _strategien ) i->setOpenParam( v );
emit uniformDataChanged();
}
void BerechnungsModell::setDirection( bool clockwise )
{
for ( auto i : _strategien )
i->setDirection( clockwise ? StrategieBasis::clockwise : StrategieBasis::counterclockwise );
emit uniformDataChanged();
}
void BerechnungsModell::selectOption( const QModelIndex &index, int no )
{
auto r = index.parent().isValid() ? index.parent().row() : index.row();
if ( r >= 0 && r < _strategien.count() )
_strategien.at( r )->selectOption( no ), emit uniformDataChanged();
}