Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
add support for NULL values in range widget (new Qgs(Double)SpinBox c…
…lasses to show the clear button)
- Loading branch information
Showing
10 changed files
with
413 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/*************************************************************************** | ||
qgsdoublespinbox.cpp | ||
-------------------------------------- | ||
Date : 09.2014 | ||
Copyright : (C) 2014 Denis Rouzaud | ||
Email : denis.rouzaud@gmail.com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include <QLineEdit> | ||
#include <QMouseEvent> | ||
#include <QSettings> | ||
#include <QStyle> | ||
#include <QToolButton> | ||
|
||
#include "qgsdoublespinbox.h" | ||
|
||
#include "qgsapplication.h" | ||
#include "qgslogger.h" | ||
|
||
QgsDoubleSpinBox::QgsDoubleSpinBox( QWidget *parent ) | ||
: QDoubleSpinBox( parent ) | ||
, mShowClearButton( true ) | ||
{ | ||
mClearButton = new QToolButton( this ); | ||
mClearButton->setIcon( QgsApplication::getThemeIcon( "/mIconClear.svg" ) ); | ||
mClearButton->setCursor( Qt::ArrowCursor ); | ||
mClearButton->setStyleSheet( "position: absolute; border: none; padding: 0px;" ); | ||
connect( mClearButton, SIGNAL( clicked() ), this, SLOT( clear() ) ); | ||
|
||
setStyleSheet( QString( "padding-right: %1px;" ).arg( mClearButton->sizeHint().width() + 18 + frameWidth() + 1 ) ); | ||
|
||
QSize msz = minimumSizeHint(); | ||
setMinimumSize( qMax( msz.width(), mClearButton->sizeHint().height() + frameWidth() * 2 + 2 ), | ||
qMax( msz.height(), mClearButton->sizeHint().height() + frameWidth() * 2 + 2 ) ); | ||
|
||
connect( this, SIGNAL( valueChanged( double ) ), this, SLOT( changed( double ) ) ); | ||
} | ||
|
||
void QgsDoubleSpinBox::setShowClearButton( bool showClearButton ) | ||
{ | ||
mShowClearButton = showClearButton; | ||
mClearButton->setVisible( mShowClearButton && isEnabled() && value() != minimum() ); | ||
} | ||
|
||
void QgsDoubleSpinBox::changeEvent( QEvent *event ) | ||
{ | ||
QDoubleSpinBox::changeEvent( event ); | ||
mClearButton->setVisible( mShowClearButton && isEnabled() && value() != minimum() ); | ||
} | ||
|
||
void QgsDoubleSpinBox::changed( const double& value ) | ||
{ | ||
mClearButton->setVisible( mShowClearButton && isEnabled() && value != minimum() ); | ||
} | ||
|
||
void QgsDoubleSpinBox::clear() | ||
{ | ||
setValue( minimum() ); | ||
} | ||
|
||
int QgsDoubleSpinBox::frameWidth() const | ||
{ | ||
return style()->pixelMetric( QStyle::PM_DefaultFrameWidth ); | ||
} | ||
|
||
void QgsDoubleSpinBox::resizeEvent( QResizeEvent * event ) | ||
{ | ||
QDoubleSpinBox::resizeEvent( event ); | ||
|
||
QSize sz = mClearButton->sizeHint(); | ||
|
||
mClearButton->move( rect().right() - frameWidth() - 18 - sz.width() , | ||
( rect().bottom() + 1 - sz.height() ) / 2 ); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/*************************************************************************** | ||
qgsdoublespinbox.h | ||
-------------------------------------- | ||
Date : 09.2014 | ||
Copyright : (C) 2014 Denis Rouzaud | ||
Email : denis.rouzaud@gmail.com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSDOUBLESPPINBOX_H | ||
#define QGSDOUBLESPPINBOX_H | ||
|
||
#include <QDoubleSpinBox> | ||
#include <QToolButton> | ||
|
||
/** | ||
* @brief The QgsSpinBox is a spin box with a clear button that will set the value to the minimum. This minum can then be handled by a special value text. | ||
*/ | ||
class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox | ||
{ | ||
Q_OBJECT | ||
Q_PROPERTY( bool showClearButton READ showClearButton WRITE setShowClearButton ) | ||
|
||
public: | ||
explicit QgsDoubleSpinBox( QWidget *parent = 0 ); | ||
|
||
//! determines if the widget will show a clear button | ||
//! @note the clear button will set the widget to its minimum value | ||
void setShowClearButton( bool showClearButton ); | ||
bool showClearButton() const {return mShowClearButton;} | ||
|
||
//! Set the current value to the minimum | ||
virtual void clear(); | ||
|
||
protected: | ||
virtual void resizeEvent( QResizeEvent* event ); | ||
virtual void changeEvent( QEvent* event ); | ||
|
||
private slots: | ||
void changed( const double &value ); | ||
|
||
private: | ||
int spinButtonWidth() const; | ||
int frameWidth() const; | ||
|
||
bool mShowClearButton; | ||
|
||
QToolButton* mClearButton; | ||
}; | ||
|
||
#endif // QGSDOUBLESPPINBOX_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.