Skip to content

Commit 007008d

Browse files
committed
Remove enum and change naming conventions.
1 parent 2f28584 commit 007008d

7 files changed

Lines changed: 46 additions & 64 deletions

File tree

examples/basic/mainwindow.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ class MainWindow : public QMainWindow
1414
* UI
1515
*/
1616
private slots:
17-
void on_XLabelAlignmentCombo_currentIndexChanged(int index);
18-
void on_YLabelAlignmentCombo_currentIndexChanged(int index);
19-
void on_ZLabelAlignmentCombo_currentIndexChanged(int index);
17+
void on_XLabelRotationCombo_currentIndexChanged(int index);
18+
void on_YLabelRotationCombo_currentIndexChanged(int index);
19+
void on_ZLabelRotationCombo_currentIndexChanged(int index);
2020

2121
private:
2222
// Main form declaration

examples/basic/mainwindow.ui

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
</widget>
125125
</item>
126126
<item>
127-
<widget class="QComboBox" name="XLabelAlignmentCombo"/>
127+
<widget class="QComboBox" name="XLabelRotationCombo"/>
128128
</item>
129129
</layout>
130130
</item>
@@ -155,7 +155,7 @@
155155
</widget>
156156
</item>
157157
<item>
158-
<widget class="QComboBox" name="YLabelAlignmentCombo"/>
158+
<widget class="QComboBox" name="YLabelRotationCombo"/>
159159
</item>
160160
</layout>
161161
</item>
@@ -186,7 +186,7 @@
186186
</widget>
187187
</item>
188188
<item>
189-
<widget class="QComboBox" name="ZLabelAlignmentCombo"/>
189+
<widget class="QComboBox" name="ZLabelRotationCombo"/>
190190
</item>
191191
</layout>
192192
</item>

examples/basic/mainwindow_funcs.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ MainWindow::MainWindow() : QMainWindow()
2727
ui_.ZVisibleCheck->setChecked(ui_.TestingWidget->zAxis()->isEnabled());
2828
connect(ui_.ZVisibleCheck, SIGNAL(toggled(bool)), ui_.TestingWidget->zAxis(), SLOT(setEnabled(bool)));
2929

30-
ui_.XLabelAlignmentCombo->addItem(QString("Horizontal"));
31-
ui_.XLabelAlignmentCombo->addItem(QString("Vertical"));
32-
ui_.YLabelAlignmentCombo->addItem(QString("Horizontal"));
33-
ui_.YLabelAlignmentCombo->addItem(QString("Vertical"));
34-
ui_.ZLabelAlignmentCombo->addItem(QString("Horizontal"));
35-
ui_.ZLabelAlignmentCombo->addItem(QString("Vertical"));
30+
ui_.XLabelRotationCombo->addItem(QString("Horizontal"));
31+
ui_.XLabelRotationCombo->addItem(QString("Vertical"));
32+
ui_.YLabelRotationCombo->addItem(QString("Horizontal"));
33+
ui_.YLabelRotationCombo->addItem(QString("Vertical"));
34+
ui_.ZLabelRotationCombo->addItem(QString("Horizontal"));
35+
ui_.ZLabelRotationCombo->addItem(QString("Vertical"));
3636

3737
// Data
3838
const auto nPoints = 1000;
@@ -52,47 +52,47 @@ MainWindow::MainWindow() : QMainWindow()
5252
ui_.TestingWidget->showAllData();
5353
};
5454

55-
void MainWindow::on_XLabelAlignmentCombo_currentIndexChanged(int index)
55+
void MainWindow::on_XLabelRotationCombo_currentIndexChanged(int index)
5656
{
5757
switch (index)
5858
{
5959
case 0:
60-
ui_.TestingWidget->xAxis()->setTitleLabelAlignment(Mildred::TextAlignment::Horizontal);
60+
ui_.TestingWidget->xAxis()->setTitleLabelRotation(0.0);
6161
break;
6262
case 1:
63-
ui_.TestingWidget->xAxis()->setTitleLabelAlignment(Mildred::TextAlignment::Vertical);
63+
ui_.TestingWidget->xAxis()->setTitleLabelRotation(90.0);
6464
break;
6565
default:
66-
throw(std::runtime_error("Unhandled text alignment mode."));
66+
throw(std::runtime_error("Unhandled text rotation."));
6767
}
6868
}
6969

70-
void MainWindow::on_YLabelAlignmentCombo_currentIndexChanged(int index)
70+
void MainWindow::on_YLabelRotationCombo_currentIndexChanged(int index)
7171
{
7272
switch (index)
7373
{
7474
case 0:
75-
ui_.TestingWidget->yAxis()->setTitleLabelAlignment(Mildred::TextAlignment::Horizontal);
75+
ui_.TestingWidget->yAxis()->setTitleLabelRotation(0.0);
7676
break;
7777
case 1:
78-
ui_.TestingWidget->yAxis()->setTitleLabelAlignment(Mildred::TextAlignment::Vertical);
78+
ui_.TestingWidget->yAxis()->setTitleLabelRotation(90.0);
7979
break;
8080
default:
81-
throw(std::runtime_error("Unhandled text alignment mode."));
81+
throw(std::runtime_error("Unhandled text rotation."));
8282
}
8383
}
8484

85-
void MainWindow::on_ZLabelAlignmentCombo_currentIndexChanged(int index)
85+
void MainWindow::on_ZLabelRotationCombo_currentIndexChanged(int index)
8686
{
8787
switch (index)
8888
{
8989
case 0:
90-
ui_.TestingWidget->zAxis()->setTitleLabelAlignment(Mildred::TextAlignment::Horizontal);
90+
ui_.TestingWidget->zAxis()->setTitleLabelRotation(0.0);
9191
break;
9292
case 1:
93-
ui_.TestingWidget->zAxis()->setTitleLabelAlignment(Mildred::TextAlignment::Vertical);
93+
ui_.TestingWidget->zAxis()->setTitleLabelRotation(90.0);
9494
break;
9595
default:
96-
throw(std::runtime_error("Unhandled text alignment mode."));
96+
throw(std::runtime_error("Unhandled text Rotation mode."));
9797
}
9898
}

src/entities/axis.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,16 +466,20 @@ void AxisEntity::setType(AxisType type)
466466
}
467467
}
468468

469-
//! Define title alignment
469+
//! Define title rotation
470470
/*!
471-
* Set the alignment of the title label to @param alignment.
471+
* Set the rotation of the title label to @param rotation.
472472
*/
473-
void AxisEntity::setTitleLabelAlignment(Mildred::TextAlignment alignment) { axisTitleEntity_->setTextAlignment(alignment); }
473+
void AxisEntity::setTitleLabelRotation(double rotation) { axisTitleEntity_->setRotation(rotation); }
474474

475-
void AxisEntity::setTickLabelAlignment(Mildred::TextAlignment alignment)
475+
//! Define tick label rotation
476+
/*!
477+
* Set the rotation of the tick labels to @param rotation.
478+
*/
479+
void AxisEntity::setTickLabelRotation(double rotation)
476480
{
477481
for (auto &entity : tickLabelEntities_)
478-
entity->setTextAlignment(alignment);
482+
entity->setRotation(rotation);
479483
}
480484

481485
//! Define direction

src/entities/axis.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ class AxisEntity : public Qt3DCore::QEntity
114114
public:
115115
// Set axis type
116116
void setType(AxisType type);
117-
// Set title label alignment
118-
void setTitleLabelAlignment(Mildred::TextAlignment alignment);
119-
// Set tick label alignment
120-
void setTickLabelAlignment(Mildred::TextAlignment alignment);
117+
// Set title label rotation
118+
void setTitleLabelRotation(double rotation);
119+
// Set tick label rotation
120+
void setTickLabelRotation(double rotation);
121121
// Set explicit direction
122122
void setDirection(QVector3D v);
123123
// Return explicit direction

src/entities/text.cpp

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ void TextEntity::updateTranslation()
8787
positionalTransform_->setTranslation(anchorPosition_);
8888

8989
// Set the rotation about z.
90-
positionalTransform_->setRotationZ(rotationZFromAlignment());
90+
positionalTransform_->setRotationZ(rotation_);
9191

9292
// Set the text translation vector so that the defined anchor point is located at {0,0,0}
93-
auto [textCuboid, translation] = boundingCuboid(textMesh_->font(), textMesh_->text(), {}, anchorPoint_, textMesh_->depth());
93+
auto [textCuboid, translation] = boundingCuboid(textMesh_->font(), textMesh_->text(), {}, anchorPoint_, textMesh_->depth(), rotation_);
9494
auto v = QVector3D(textCuboid.lowerLeftBack().x(), textCuboid.lowerLeftBack().y(), 0.0);
9595
textTransform_->setTranslation(v + translation);
9696

@@ -146,28 +146,14 @@ void TextEntity::setAnchorPosition(QVector3D p)
146146
updateTranslation();
147147
}
148148

149-
//! Set alignment of text
150-
void TextEntity::setTextAlignment(Mildred::TextAlignment alignment)
149+
//! Set rotation of text
150+
void TextEntity::setRotation(double rotation)
151151
{
152-
alignment_ = alignment;
152+
rotation_ = rotation;
153153

154154
updateTranslation();
155155
}
156156

157-
//! Gets the required rotation, around z, in degrees, to achieve the current alignment.
158-
float TextEntity::rotationZFromAlignment()
159-
{
160-
switch (alignment_)
161-
{
162-
case (Mildred::TextAlignment::Horizontal):
163-
return 0.0;
164-
case (Mildred::TextAlignment::Vertical):
165-
return 90.0;
166-
default:
167-
throw(std::runtime_error("Unhandled text alignment mode."));
168-
}
169-
}
170-
171157
//! Return simple bounding cuboid for text, along with baseline descent from font metrics
172158
/*!
173159
* Calculates a bounding cuboid in the XY plane for the specified @param font and @param text. The @param depth is applied in
@@ -224,4 +210,4 @@ std::pair<Cuboid, QVector3D> TextEntity::boundingCuboid(const QFont &font, const
224210
cuboid.translate(-QVector3D(cuboid.xExtent() * anchorFrac.x(), cuboid.yExtent() * anchorFrac.y(), 0.0));
225211

226212
return {cuboid, meshTranslation};
227-
}
213+
}

src/entities/text.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
namespace Mildred
1212
{
1313

14-
enum class TextAlignment
15-
{
16-
Horizontal,
17-
Vertical
18-
};
19-
2014
//! TextEntity represents a 3D text entity
2115
/*!
2216
* TextEntity represents a renderable entity displaying a specified string with a given transform.
@@ -30,8 +24,8 @@ class TextEntity : public Qt3DCore::QEntity
3024
private:
3125
// Collective positional transform
3226
Qt3DCore::QTransform *positionalTransform_{nullptr};
33-
// Alignment
34-
Mildred::TextAlignment alignment_{Mildred::TextAlignment::Horizontal};
27+
// Rotation
28+
double rotation_{0.0};
3529
// Material
3630
RenderableMaterial *material_{nullptr};
3731
// Main entity
@@ -74,9 +68,7 @@ class TextEntity : public Qt3DCore::QEntity
7468
// Set anchor position
7569
void setAnchorPosition(QVector3D p);
7670
// Set rotation
77-
void setTextAlignment(Mildred::TextAlignment alignment);
78-
// Get required rotation in degrees
79-
float rotationZFromAlignment();
71+
void setRotation(double rotation);
8072
// Return simple bounding cuboid for text, along with baseline descent from font metrics
8173
static std::pair<Cuboid, int> boundingCuboid(const QFont &font, const QString &text, float depth = 0.1f);
8274
// Return bounding cuboid with translation and anchor point applied, and required translation vector for text mesh

0 commit comments

Comments
 (0)