A spin box with string items. More...
#include <qxtstringspinbox.h>
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 |
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 in Cleanlooks style.
Definition at line 34 of file qxtstringspinbox.h.
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] |
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 ) |
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().
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);
}
friend class QxtStringSpinBoxPrivate [friend] |
Definition at line 37 of file qxtstringspinbox.h.
const QStringList & QxtStringSpinBox::strings [read, write] |
This property holds the string items of the spin box.
Definition at line 37 of file qxtstringspinbox.h.