Warning, file /sdk/ktechlab/src/gui/doublespinbox.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /***************************************************************************
0002  *   Copyright (C) 2003-2006 by David Saxton                               *
0003  *   david@bluehaze.org                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #ifndef DOUBLESPINBOX_H
0012 #define DOUBLESPINBOX_H
0013 
0014 #include <QDoubleSpinBox>
0015 
0016 /**
0017 Where appropriate, function names with value in them should
0018 be prefixed with "real" - e.g. realValue() - to get the value stored in the
0019 spin box plus the SI magnitude symbol it is showing
0020 
0021 @author David Saxton
0022 */
0023 class DoubleSpinBox : public QDoubleSpinBox
0024 {
0025     Q_OBJECT
0026 public:
0027     DoubleSpinBox(double lower, double upper, double minAbs, double value, const QString &unit, QWidget *parent = nullptr);
0028     DoubleSpinBox(QWidget *parent = nullptr);
0029     ~DoubleSpinBox() override;
0030 
0031     /**
0032      * The minimum value is the lowest number that the user can enter.
0033      */
0034     //      double minValue() const { return m_minValue; }
0035     /**
0036      * @see minValue
0037      */
0038     //      void setMinValue( double minValue ) { m_minValue = minValue; }
0039     /**
0040      * The minimum value is the lowest number that the user can enter.
0041      */
0042     //      void setMinValue( int minValue ) { m_minValue = minValue; }
0043     /**
0044      * The maximum value is the highest number that the user can enter.
0045      */
0046     //      double maxValue() const { return m_maxValue; }
0047     /**
0048      * @see maxValue
0049      */
0050     //      void setMaxValue( double maxValue ) { m_maxValue = maxValue; }
0051     /**
0052      * @see maxValue
0053      */
0054     //      void setMaxValue( int maxValue ) { m_maxValue = maxValue; }
0055     /**
0056      * The minimum absolute value is the smallest value that the user can
0057      * enter before the value is considered 0.
0058      */
0059     void setMinAbsValue(double minAbsValue)
0060     {
0061         m_minAbsValue = minAbsValue;
0062     }
0063     /**
0064      * The actual value that the user has entered - e.g. if the spinbox
0065      * displays "100 kF", then the value returned will be 1e5.
0066      */
0067     //      double value();
0068     /**
0069      * Sets the unit used, e.g. "F"
0070      */
0071     //      void setUnit( const QString & unit );
0072 
0073     QValidator::State validate(QString &text, int &pos) const override;
0074 
0075 public slots:
0076     //      virtual void stepUp(); // QDoubleSpinBox has these
0077     //      virtual void stepDown();
0078     /**
0079      * Set the value to be displayed - e.g. if value is 1e5, then the
0080      * spinbox might display "100 kF".
0081      */
0082     //      void setValue( double value );
0083 
0084 signals:
0085     /**
0086      * This value is emitted whenever the value of the spinbox changes.
0087      */
0088     //      void valueChanged( double value ); // exists in QDoubleSpinBox
0089 
0090 protected slots:
0091     /**
0092      * Checks if the value has changed - and if so, emits a valueChanged
0093      * signal.
0094      */
0095     //      void checkIfChanged(double value);
0096     /**
0097      * Sets the suffix from m_queuedSuffix. Called from QTimer::singleShot
0098      * to avoid strange recursion problems.
0099      */
0100     //      void setQueuedSuffix();
0101 
0102 protected:
0103     /**
0104      * make Qt enable the up/down step arrows
0105      */
0106     StepEnabled stepEnabled() const override;
0107     /**
0108      * Change the value of the spin box, because of user interaction
0109      */
0110     void stepBy(int steps) override;
0111 
0112     double getNextUpStepValue(double in);
0113     double getNextDownStepValue(double in);
0114 
0115     /**
0116      * Updates the suffix using m_unit and value.
0117      */
0118     void updateSuffix(double value);
0119     /**
0120      * Returns the multiplication number from what is displayed
0121      * in the box, e.g. "10 kV" will return "1000" due to the letter "k" presence
0122      */
0123     //      double getMult();
0124     /**
0125      * Returns the number currently displayed in the spin box.
0126      */
0127     //      double getDisplayedNumber( bool * ok );
0128     /**
0129      *  Overloaded the method in QSpinxBox to allow SI prefixes to be entered
0130      */
0131     //      virtual int mapTextToValue( bool * ok );
0132     double valueFromText(const QString &text) const override;
0133     /**
0134      *  Overloaded the method in QSpinxBox to allow SI prefixes to be entered
0135      */
0136     //      virtual QString mapValueToText( int v );
0137     QString textFromValue(double value) const override;
0138     /**
0139      * Returns value rounded off to one significant figure.
0140      */
0141     static double roundToOneSF(double value);
0142 
0143     void init();
0144 
0145     //      QString m_queuedSuffix; ///< Used
0146     QString m_unit;
0147     //      double m_minValue;
0148     //      double m_maxValue;
0149     double m_minAbsValue;
0150     double m_lastEmittedValue;
0151 };
0152 
0153 #endif