Skip to content
Permalink
Browse files

Avoid complex editable combobox logic

  • Loading branch information
nyalldawson committed Jun 29, 2018
1 parent 2d810fa commit 40b838d5717cbb159f0670726c85e26074206f01
@@ -61,6 +61,11 @@
#include <QPixmap>
#include <QPen>


const int MAXACQUISITIONINTERVAL = 3000; // max gps information acquisition suspension interval (in seconds)
const int MAXDISTANCETHRESHOLD = 200; // max gps distance threshold (in meters)


QgsGpsInformationWidget::QgsGpsInformationWidget( QgsMapCanvas *thepCanvas, QWidget *parent, Qt::WindowFlags f )
: QWidget( parent, f )
, mpCanvas( thepCanvas )
@@ -263,39 +268,28 @@ QgsGpsInformationWidget::QgsGpsInformationWidget( QgsMapCanvas *thepCanvas, QWid
mDistanceThresholdValidator = new QIntValidator( 0, MAXDISTANCETHRESHOLD, this );
mAcquisitionTimer = std::unique_ptr<QTimer>( new QTimer( this ) );
mAcquisitionTimer->setSingleShot( true );
mCboAcquisitionInterval->setInsertPolicy( QComboBox::NoInsert );
mCboDistanceThreshold->setInsertPolicy( QComboBox::NoInsert );
mCboAcquisitionInterval->addItem( QStringLiteral( "0" ), 0 );
mCboAcquisitionInterval->addItem( QStringLiteral( "2" ), 2 );
mCboAcquisitionInterval->addItem( QStringLiteral( "5" ), 5 );
mCboAcquisitionInterval->addItem( QStringLiteral( "10" ), 10 );
mCboAcquisitionInterval->addItem( QStringLiteral( "15" ), 15 );
mCboAcquisitionInterval->addItem( QStringLiteral( "30" ), 30 );
mCboAcquisitionInterval->addItem( QStringLiteral( "60" ), 60 );
mCboAcquisitionInterval->addItem( tr( "" ) );
mCboDistanceThreshold->addItem( QStringLiteral( "0" ), 0 );
mCboDistanceThreshold->addItem( QStringLiteral( "3" ), 3 );
mCboDistanceThreshold->addItem( QStringLiteral( "5" ), 5 );
mCboDistanceThreshold->addItem( QStringLiteral( "10" ), 10 );
mCboDistanceThreshold->addItem( QStringLiteral( "15" ), 15 );
mCboDistanceThreshold->addItem( tr( "" ) );
mCboAcquisitionInterval->setCurrentIndex( 0 );
mCboAcquisitionInterval->setCurrentIndex( 0 );
connect( mAcquisitionTimer.get(), &QTimer::timeout,
this, &QgsGpsInformationWidget::switchAcquisition );
connect( mCboAcquisitionInterval, qgis::overload< const QString & >::of( &QComboBox::activated ),
this, &QgsGpsInformationWidget::cboAcquisitionIntervalActivated );
connect( mCboDistanceThreshold, qgis::overload< const QString & >::of( &QComboBox::activated ),
this, &QgsGpsInformationWidget::cboDistanceThresholdActivated );
mAcIntervalEdit = new QLineEdit;
mDistThresholdEdit = new QLineEdit;
mAcIntervalEdit->setValidator( mAcquisitionIntValidator );
mDistThresholdEdit->setValidator( mDistanceThresholdValidator );
connect( mAcIntervalEdit, &QLineEdit::editingFinished,
connect( mCboAcquisitionInterval, qgis::overload< const QString & >::of( &QComboBox::currentTextChanged ),
this, &QgsGpsInformationWidget::cboAcquisitionIntervalEdited );
connect( mDistThresholdEdit, &QLineEdit::editingFinished,
connect( mCboDistanceThreshold, qgis::overload< const QString & >::of( &QComboBox::currentTextChanged ),
this, &QgsGpsInformationWidget::cboDistanceThresholdEdited );

mCboAcquisitionInterval->setValidator( mAcquisitionIntValidator );
mCboDistanceThreshold->setValidator( mDistanceThresholdValidator );
}

QgsGpsInformationWidget::~QgsGpsInformationWidget()
@@ -1193,7 +1187,7 @@ void QgsGpsInformationWidget::showStatusBarMessage( const QString &msg )
{
QgisApp::instance()->statusBarIface()->showMessage( msg );
}
void QgsGpsInformationWidget::setAcquisitionInterval( int interval )
void QgsGpsInformationWidget::setAcquisitionInterval( uint interval )
{
mAcquisitionInterval = interval * 1000;
if ( mAcquisitionTimer->isActive() )
@@ -1202,48 +1196,19 @@ void QgsGpsInformationWidget::setAcquisitionInterval( int interval )
switchAcquisition();

}
void QgsGpsInformationWidget::setDistanceThreshold( int distance )
void QgsGpsInformationWidget::setDistanceThreshold( uint distance )
{
mDistanceThreshold = distance;
}

void QgsGpsInformationWidget::cboAcquisitionIntervalActivated( const QString &text )
{
if ( text == "" )
{
mCboAcquisitionInterval->setEditable( true );
mCboAcquisitionInterval->setLineEdit( mAcIntervalEdit );
mCboAcquisitionInterval->clearEditText();
}
else
{
setAcquisitionInterval( text.toInt() );
}
}

void QgsGpsInformationWidget::cboDistanceThresholdActivated( const QString &text )
{
if ( text == "" )
{
mCboDistanceThreshold->setEditable( true );
mCboDistanceThreshold->setLineEdit( mDistThresholdEdit );
mCboDistanceThreshold->clearEditText();

}
else
{
setDistanceThreshold( text.toInt() );
}
}

void QgsGpsInformationWidget::cboAcquisitionIntervalEdited()
{
setAcquisitionInterval( mAcIntervalEdit->text().toInt() );
setAcquisitionInterval( mCboAcquisitionInterval->currentText().toUInt() );
}

void QgsGpsInformationWidget::cboDistanceThresholdEdited()
{
setDistanceThreshold( mDistThresholdEdit->text().toInt() );
setDistanceThreshold( mCboDistanceThreshold->currentText().toUInt() );
}

void QgsGpsInformationWidget::switchAcquisition()
@@ -30,8 +30,6 @@
#include <qwt_polar_grid.h>
#include <qwt_polar_marker.h>
#endif
#define MAXACQUISITIONINTERVAL 300 // max gps information acquisition suspension interval (in seconds)
#define MAXDISTANCETHRESHOLD 10 // max gps distance threshold (in meters)

class QextSerialPort;
class QgsGpsConnection;
@@ -76,8 +74,6 @@ class QgsGpsInformationWidget: public QWidget, private Ui::QgsGpsInformationWidg
void connected( QgsGpsConnection * );
void timedout();
void switchAcquisition();
void cboAcquisitionIntervalActivated( const QString & );
void cboDistanceThresholdActivated( const QString & );
void cboAcquisitionIntervalEdited();
void cboDistanceThresholdEdited();
private:
@@ -92,8 +88,8 @@ class QgsGpsInformationWidget: public QWidget, private Ui::QgsGpsInformationWidg
void populateDevices();
void setStatusIndicator( FixStatus statusValue );
void showStatusBarMessage( const QString &msg );
void setAcquisitionInterval( int );
void setDistanceThreshold( int );
void setAcquisitionInterval( uint );
void setDistanceThreshold( uint );
QgsGpsConnection *mNmea = nullptr;
QgsMapCanvas *mpCanvas = nullptr;
QgsGpsMarker *mpMapMarker = nullptr;
@@ -119,8 +115,6 @@ class QgsGpsInformationWidget: public QWidget, private Ui::QgsGpsInformationWidg
QColor mTrackColor;
QIntValidator *mAcquisitionIntValidator = nullptr;
QIntValidator *mDistanceThresholdValidator = nullptr;
QLineEdit *mAcIntervalEdit = nullptr;
QLineEdit *mDistThresholdEdit = nullptr;
nmeaPOS mLastNmeaPosition;
std::unique_ptr<QTimer> mAcquisitionTimer;
bool mAcquisitionEnabled = true;
@@ -1030,6 +1030,9 @@ gray = no data
</item>
<item row="0" column="1">
<widget class="QPushButton" name="mBtnLogFile">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>23</horstretch>
@@ -1214,7 +1217,11 @@ gray = no data
</property>
<layout class="QGridLayout" name="gridLayout_14" columnstretch="0,1">
<item row="1" column="1">
<widget class="QComboBox" name="mCboDistanceThreshold"/>
<widget class="QComboBox" name="mCboDistanceThreshold">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_9">
@@ -1231,7 +1238,11 @@ gray = no data
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="mCboAcquisitionInterval"/>
<widget class="QComboBox" name="mCboAcquisitionInterval">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>

0 comments on commit 40b838d

Please sign in to comment.
You can’t perform that action at this time.