Skip to content

Commit

Permalink
Flags property on profile for persisting editability
Browse files Browse the repository at this point in the history
  • Loading branch information
hrobeers committed Jul 18, 2017
1 parent 0c790aa commit a116789
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 20 deletions.
1 change: 0 additions & 1 deletion include/foileditors/profileeditor/profileeditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ namespace foileditors
explicit ProfileEditor(QWidget *parent = 0);

void setFoil(foillogic::Foil* foil);
void setEditable(bool editable);

virtual ~ProfileEditor() {}

Expand Down
12 changes: 11 additions & 1 deletion include/foillogic/profile.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
Copyright (c) 2013, Hans Robeers
Copyright (c) 2017, Hans Robeers
All rights reserved.
BSD 2-Clause License
Expand Down Expand Up @@ -45,6 +45,7 @@ namespace foillogic
Q_PROPERTY(QString symmetry READ symmetryStr WRITE setSymmetryStr)
Q_PROPERTY(patheditor::Path* topProfile READ pTopProfile WRITE pSetTopProfile)
Q_PROPERTY(patheditor::Path* botProfile READ pBotProfile WRITE pSetBotProfile RESET pResetBotProfile)
Q_PROPERTY(int flags READ flags WRITE setFlags RESET resetFlags)

// optional properties
Q_PROPERTY_UUID
Expand All @@ -71,20 +72,27 @@ namespace foillogic
qreal pxThickness() const;
qreal thicknessRatio() const;

// Flags
bool editable() const;
void setEditable(bool editable);

// Q_PROPERTY getters
QString symmetryStr() const;
patheditor::Path* pTopProfile();
patheditor::Path* pBotProfile();
int flags() const;

// Q_PROPERTY setters
void setSymmetryStr(QString symmetry);
void pSetTopProfile(patheditor::Path *topProfile);
void pSetBotProfile(patheditor::Path *botProfile);
void setFlags(int flags);

void pSetThickness_legacy(qreal thickness) { _thickness_legacy = thickness; }
void pResetThickness_legacy() { _thickness_legacy = NAN; }

void pResetBotProfile();
void resetFlags();

virtual ~Profile();

Expand All @@ -104,6 +112,8 @@ namespace foillogic
QPointF _topProfileTop, _botProfileTop;
qreal t_topProfileTop, t_botProfileTop;

int _flags;

void initProfile();
void attachSignals(patheditor::Path* path);

Expand Down
2 changes: 1 addition & 1 deletion src/app/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ void MainWindow::loadProfile()
ifs.open(filePath.toStdString(), std::ifstream::in);

_fin->pSetProfile(ProfileLoader::loadDatStream(ifs));
_fin->profile()->setEditable(false);
_profileEditor->setFoil(_fin.get());
_profileEditor->setEditable(false);
_fin->onDeserialized();
return;
}
Expand Down
22 changes: 10 additions & 12 deletions src/foileditors/profileeditor/profileeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,37 +74,35 @@ void ProfileEditor::setFoil(Foil *foil)
_pathEditor->addPath(_topProfile);
}

void ProfileEditor::setEditable(bool editable)
{
_topProfile->setEditable(editable);
_botProfile->setEditable(editable);
// TODO disable symmetry combobox
}

void ProfileEditor::setGridUnitSize(qreal pxPerUnit)
{
_pathEditor->setGridUnitSize(pxPerUnit);
}

void ProfileEditor::symmetryChanged(int sym)
{
bool editable = _foil->profile()->editable();

switch (sym)
{
case 0:
_foil->profile()->setSymmetry(Profile::Symmetric);
_botProfile->setEditable(false);
_topProfile->setEditable(true);
_botProfile->setEditable(editable && false);
_topProfile->setEditable(editable && true);
break;
case 1:
_foil->profile()->setSymmetry(Profile::Asymmetric);
_botProfile->setEditable(true);
_botProfile->setEditable(editable && true);
_topProfile->setEditable(editable);
break;
case 2:
_foil->profile()->setSymmetry(Profile::Flat);
_botProfile->setEditable(false);
_topProfile->setEditable(true);
_botProfile->setEditable(editable && false);
_topProfile->setEditable(editable && true);
break;
}

_symmetryCombo->setDisabled(!editable);

_pathEditor->scene()->invalidate();
}
39 changes: 36 additions & 3 deletions src/foillogic/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,17 @@ using namespace foillogic;
using namespace patheditor;
using namespace boost::units;

namespace {
struct Flags { enum e {
None = 0x0,
Editable = 0x1,
Default = Editable
}; };
}

Profile::Profile(QObject *parent) :
QObject(parent), _symmetry(Symmetry::Symmetric),
t_topProfileTop(0.3), t_botProfileTop(0.3)
t_topProfileTop(0.3), t_botProfileTop(0.3), _flags(Flags::Default)
{
initProfile();
}
Expand Down Expand Up @@ -108,6 +116,16 @@ qreal Profile::thicknessRatio() const
return -_topProfileTop.y() / _botProfileTop.y();
}

bool Profile::editable() const
{
return _flags & Flags::Editable;
}

void Profile::setEditable(bool editable)
{
_flags = editable ? _flags | Flags::Editable : _flags ^ Flags::Editable;
}

QString Profile::symmetryStr() const
{
QMetaEnum symmetryEnum = this->metaObject()->enumerator(0);
Expand All @@ -124,7 +142,12 @@ Path *Profile::pBotProfile()
if (symmetry() == Symmetry::Asymmetric)
return botProfile();
else
return nullptr;
return nullptr;
}

int Profile::flags() const
{
return _flags;
}

void Profile::setSymmetryStr(QString symmetry)
Expand Down Expand Up @@ -168,9 +191,19 @@ void Profile::pSetBotProfile(Path *botProfile)
attachSignals(_botProfile.get());
}

void Profile::setFlags(int flags)
{
_flags = flags;
}

void Profile::pResetBotProfile()
{
// Do nothing, initialized in ctor
// Do nothing, initialized in ctor
}

void Profile::resetFlags()
{
_flags = Flags::Default;
}

Profile::~Profile() {}
Expand Down
4 changes: 2 additions & 2 deletions src/version_autogen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define MINOR_VERSION 1
#define REVISION 1

#define BUILD_NUMBER 500
#define COMMIT_HASH "a00542debe0fd8367f4952372023c5bbd287a8e4"
#define BUILD_NUMBER 503
#define COMMIT_HASH "0c790aa172876158cfd1e5365652f420a0466e7c"

#endif // VERSION_AUTOGEN_H

0 comments on commit a116789

Please sign in to comment.