CoordinateEdit.h
#pragma once
#include <QWidget>
#include <QEvent>
class QLineEdit;
class QLabel;
class CoordinateEdit : public QWidget
{
Q_OBJECT
public:
enum Type
{
Type_Longitude,
Type_Lagitude
};
CoordinateEdit(Type type = Type_Longitude,QWidget *parent = 0);
~CoordinateEdit();
void SetType(Type type){
m_type = type; }
QString GetCoordinate() {
return m_coordinate; }
QString GetDegree() {
return m_d; }
QString GetMinute() {
return m_m; }
QString GetSecond() {
return m_s + "." + m_ms; }
protected:
bool eventFilter(QObject *watched, QEvent *event);
signals:
void coordChange(const QString &);
private slots:
void OnLineEdit(const QString& text);
private:
Type m_type;
QLineEdit* m_degree;
QLineEdit* m_minute;
QLineEdit* m_second;
QLineEdit* m_msec;
QLabel* m_dLab;
QLabel* m_mLab;
QLabel* m_sLab;
QString m_coordinate;
QString m_d;
QString m_m;
QString m_s;
QString m_ms;
};
CoordinateEdit.cpp
#include "CoordinateEdit.h"
#include <QLineEdit>
#include <QLabel>
#include <QHBoxLayout>
#include <QRegExp>
#include <QRegExpValidator>
#include <QKeyEvent>
CoordinateEdit::CoordinateEdit(Type type,QWidget *parent)
: QWidget(parent)
, m_type(type)
{
if (parent)
{
parent->setLayout(new QHBoxLayout