QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsspinbox.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsspinbox.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 QGSSPPINBOX_H
17 #define QGSSPPINBOX_H
18 
19 #include <QSpinBox>
20 #include <QToolButton>
21 
27 class GUI_EXPORT QgsSpinBox : public QSpinBox
28 {
29  Q_OBJECT
30  Q_PROPERTY( bool showClearButton READ showClearButton WRITE setShowClearButton )
31 
32  public:
34  {
37  CustomValue
38  };
39 
40  explicit QgsSpinBox( QWidget *parent = 0 );
41 
44  void setShowClearButton( const bool showClearButton );
45  bool showClearButton() const {return mShowClearButton;}
46 
52  void setExpressionsEnabled( const bool enabled );
58  bool expressionsEnabled() const {return mExpressionsEnabled;}
59 
61  virtual void clear() override;
62 
68  void setClearValue( int customValue, QString clearValueText = QString() );
74  void setClearValueMode( ClearValueMode mode, QString clearValueText = QString() );
75 
77  int clearValue() const;
78 
79  virtual int valueFromText( const QString & text ) const override;
80  virtual QValidator::State validate( QString & input, int & pos ) const override;
81 
82  protected:
83  virtual void resizeEvent( QResizeEvent* event ) override;
84  virtual void changeEvent( QEvent* event ) override;
85  virtual void paintEvent( QPaintEvent* event ) override;
86 
87  private slots:
88  void changed( const int& value );
89 
90  private:
91  int frameWidth() const;
92  bool shouldShowClearForValue( const int value ) const;
93 
94  bool mShowClearButton;
95  ClearValueMode mClearValueMode;
96  int mCustomClearValue;
97 
98  bool mExpressionsEnabled;
99 
100  QToolButton* mClearButton;
101  QString stripped( const QString &originalText ) const;
102 };
103 
104 #endif // QGSSPPINBOX_H