Public Member Functions | Protected Member Functions | Properties | Friends

QxtStringSpinBox Class Reference
[QxtGui]

A spin box with string items. More...

#include <qxtstringspinbox.h>

Collaboration diagram for QxtStringSpinBox:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 QxtStringSpinBox (QWidget *pParent=0)
virtual ~QxtStringSpinBox ()
const QStringList & strings () const
void setStrings (const QStringList &strings)
virtual void fixup (QString &input) const
virtual QValidator::State validate (QString &input, int &pos) const

Protected Member Functions

virtual QString textFromValue (int value) const
virtual int valueFromText (const QString &text) const

Properties

QStringList strings
 This property holds the string items of the spin box.

Friends

class QxtStringSpinBoxPrivate

Detailed Description

A spin box with string items.

QxtStringSpinBox is spin box that takes strings. QxtStringSpinBox allows the user to choose a value by clicking the up and down buttons or by pressing Up or Down on the keyboard to increase or decrease the value currently displayed. The user can also type the value in manually.

qxtstringspinbox.png

QxtStringSpinBox in Cleanlooks style.

Definition at line 34 of file qxtstringspinbox.h.


Constructor & Destructor Documentation

QxtStringSpinBox::QxtStringSpinBox ( QWidget *  pParent = 0 ) [explicit]

Constructs a new QxtStringSpinBox with parent.

Definition at line 67 of file qxtstringspinbox.cpp.

                                                   : QSpinBox(pParent)
{
    setRange(0, 0);
}
QxtStringSpinBox::~QxtStringSpinBox (  ) [virtual]

Destructs the spin box.

Definition at line 75 of file qxtstringspinbox.cpp.

{}

Member Function Documentation

void QxtStringSpinBox::fixup ( QString &  input ) const [virtual]

Definition at line 98 of file qxtstringspinbox.cpp.

{
    // just attempt to change the input string to be valid according to the string list
    // no need to result in a valid string, callers of this function are responsible to
    // re-test the validity afterwards

    // try finding a string from the list which starts with input
    input = input.simplified();
    if (!input.isEmpty())
    {
        qxt_d().startsWith(input, input);
    }
}
void QxtStringSpinBox::setStrings ( const QStringList &  strings )

Definition at line 87 of file qxtstringspinbox.cpp.

References strings().

{
    qxt_d().strings = strings;
    setRange(0, strings.size() - 1);
    if (!strings.isEmpty())
        setValue(0);
}
const QStringList& QxtStringSpinBox::strings (  ) const

Referenced by setStrings(), textFromValue(), and validate().

QString QxtStringSpinBox::textFromValue ( int  value ) const [protected, virtual]

Definition at line 141 of file qxtstringspinbox.cpp.

References strings().

{
    Q_ASSERT(qxt_d().strings.isEmpty() || (value >= 0 && value < qxt_d().strings.size()));
    return qxt_d().strings.isEmpty() ? QLatin1String("") : qxt_d().strings.at(value);
}
QValidator::State QxtStringSpinBox::validate ( QString &  input,
int &  pos 
) const [virtual]

Definition at line 115 of file qxtstringspinbox.cpp.

References strings().

{
    // Invalid:  input is invalid according to the string list
    // Intermediate: it is likely that a little more editing will make the input acceptable
    //   (e.g. the user types "A" and stringlist contains "ABC")
    // Acceptable:  the input is valid.
    Q_UNUSED(pos);
    QString temp;
    QValidator::State state = QValidator::Invalid;
    if (qxt_d().strings.contains(input))
    {
        // exact match
        state = QValidator::Acceptable;
    }
    else if (input.isEmpty() || qxt_d().startsWith(input, temp) != -1)
    {
        // still empty or some string in the list starts with input
        state = QValidator::Intermediate;
    }
    // else invalid
    return state;
}
int QxtStringSpinBox::valueFromText ( const QString &  text ) const [protected, virtual]

Definition at line 150 of file qxtstringspinbox.cpp.

{
    return qxt_d().strings.indexOf(text);
}

Friends And Related Function Documentation

friend class QxtStringSpinBoxPrivate [friend]

Definition at line 37 of file qxtstringspinbox.h.


Property Documentation

const QStringList & QxtStringSpinBox::strings [read, write]

This property holds the string items of the spin box.

Definition at line 37 of file qxtstringspinbox.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines