diff --git a/src/blackgui/altitudeedit.cpp b/src/blackgui/altitudeedit.cpp new file mode 100644 index 000000000..66a5e547c --- /dev/null +++ b/src/blackgui/altitudeedit.cpp @@ -0,0 +1,44 @@ +/* Copyright (C) 2017 + * swift project Community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "altitudeedit.h" +#include +#include + +using namespace BlackMisc; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::PhysicalQuantities; + +namespace BlackGui +{ + CAltitudeEdit::CAltitudeEdit(QWidget *parent) : QLineEdit(parent) + { + this->setToolTip("Altitude e.g. " + CAltitude::fpAltitudeInfo("
")); + this->setPlaceholderText(CAltitude::fpAltitudeExamples()); + this->setValidator(new QRegularExpressionValidator(CAltitude::fpAltitudeRegExp(), this)); + } + + CAltitude CAltitudeEdit::getAltitude() const + { + CAltitude a; + a.parseFromFpAltitudeString(this->text()); + return a; + } + + void CAltitudeEdit::setAltitude(const CAltitude &altitude) + { + this->setText(altitude.asFpAltitudeString()); + } + + bool CAltitudeEdit::isValid(CStatusMessageList *msgs) const + { + CAltitude a; + return a.parseFromFpAltitudeString(this->text(), msgs); + } +} // ns diff --git a/src/blackgui/altitudeedit.h b/src/blackgui/altitudeedit.h new file mode 100644 index 000000000..92edff79e --- /dev/null +++ b/src/blackgui/altitudeedit.h @@ -0,0 +1,43 @@ +/* Copyright (C) 2017 + * swift project Community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_ALTITUDEEDIT_H +#define BLACKGUI_ALTITUDEEDIT_H + +#include "blackmisc/aviation/altitude.h" +#include "blackmisc/statusmessagelist.h" +#include "blackgui/blackguiexport.h" +#include +#include + +namespace BlackGui +{ + /*! + * Line edit for altitude as used in flight plan + */ + class BLACKGUI_EXPORT CAltitudeEdit : public QLineEdit + { + public: + //! Constructor + CAltitudeEdit(QWidget *parent = nullptr); + + //! Get altitude + BlackMisc::Aviation::CAltitude getAltitude() const; + + //! Set altitude + void setAltitude(const BlackMisc::Aviation::CAltitude &altitude); + + //! Valid altitude + bool isValid(BlackMisc::CStatusMessageList *msgs = nullptr) const; + }; +} // ns + +#endif // guard