QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsdoublespinbox.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdoublespinbox.h
3  --------------------------------------
4  Date : 09.2014
5  Copyright : (C) 2014 Denis Rouzaud
6  Email : [email protected]
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSDOUBLESPPINBOX_H
17 #define QGSDOUBLESPPINBOX_H
18 
19 #include <QDoubleSpinBox>
20 #include <QToolButton>
21 
27 class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
28 {
29  Q_OBJECT
30  Q_PROPERTY( bool showClearButton READ showClearButton WRITE setShowClearButton )
31  Q_PROPERTY( bool expressionsEnabled READ expressionsEnabled WRITE setExpressionsEnabled )
32 
33  public:
35  {
38  CustomValue
39  };
40 
41  explicit QgsDoubleSpinBox( QWidget *parent = 0 );
42 
45  void setShowClearButton( const bool showClearButton );
46  bool showClearButton() const {return mShowClearButton;}
47 
53  void setExpressionsEnabled( const bool enabled );
59  bool expressionsEnabled() const {return mExpressionsEnabled;}
60 
62  virtual void clear() override;
63 
69  void setClearValue( double customValue, QString clearValueText = QString() );
75  void setClearValueMode( ClearValueMode mode, QString clearValueText = QString() );
76 
78  double clearValue() const;
79 
80  virtual double valueFromText( const QString & text ) const override;
81  virtual QValidator::State validate( QString & input, int & pos ) const override;
82 
83  protected:
84  virtual void resizeEvent( QResizeEvent* event ) override;
85  virtual void changeEvent( QEvent* event ) override;
86  virtual void paintEvent( QPaintEvent* event ) override;
87 
88  private slots:
89  void changed( const double &value );
90 
91  private:
92  int frameWidth() const;
93  bool shouldShowClearForValue( const double value ) const;
94 
95  bool mShowClearButton;
96  ClearValueMode mClearValueMode;
97  double mCustomClearValue;
98 
99  bool mExpressionsEnabled;
100 
101  QToolButton* mClearButton;
102  QString stripped( const QString &originalText ) const;
103 };
104 
105 #endif // QGSDOUBLESPPINBOX_H