本文整理汇总了C++中QDoubleValidator::validate方法的典型用法代码示例。如果您正苦于以下问题:C++ QDoubleValidator::validate方法的具体用法?C++ QDoubleValidator::validate怎么用?C++ QDoubleValidator::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDoubleValidator
的用法示例。
在下文中一共展示了QDoubleValidator::validate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: validate
QValidator::State cwClinoValidator::validate ( QString & input, int & pos ) const {
if(input.isEmpty()) {
return QValidator::Acceptable;
}
QDoubleValidator doubleValidator;
doubleValidator.setTop(90);
doubleValidator.setBottom(-90);
doubleValidator.setNotation(QDoubleValidator::StandardNotation);
QValidator::State state = doubleValidator.validate(input, pos);
switch(state) {
case QValidator::Invalid: {
QRegExpValidator upDownValidator;
QRegExp regexp("up|down", Qt::CaseInsensitive);
upDownValidator.setRegExp(regexp);
return upDownValidator.validate(input, pos);
}
case QValidator::Acceptable: {
//Just make sure we can convert the input
bool okay;
double value = input.toDouble(&okay);
if(!okay || !check(value)) {
//The validator is dump ... this handle use case input="5,5"
return QValidator::Invalid;
}
break;
}
default:
break;
}
return state;
}
示例2: setModelData
void PropertyEditDelegate::setModelData(QWidget* editor_,
QAbstractItemModel* model_,
const QModelIndex& index) const
{
const QVariant& data = index.data();
GeneratorPropertiesModel* model =
static_cast<GeneratorPropertiesModel*>(model_);
switch (data.type())
{
case QVariant::Double:
{
QLineEdit* editor = static_cast<QLineEdit*>(editor_);
model->setData(index, editor->text().toDouble(), Qt::EditRole);
break;
}
case QVariant::Int:
{
QSpinBox* editor = static_cast<QSpinBox*>(editor_);
editor->interpretText();
model->setData(index, editor->value(), Qt::EditRole);
break;
}
case QVariant::Bool:
{
QCheckBox* editor = static_cast<QCheckBox*>(editor_);
const bool value = editor->checkState() == Qt::Checked;
model->setData(index, value, Qt::EditRole);
break;
}
case QVariant::List:
{
QLineEdit* editor = static_cast<QLineEdit*>(editor_);
QStringList list = editor->text().split(",");
QVariantList varList;
QDoubleValidator validator;
for (QString& str : list)
{
if (str == "")
continue;
int pos = 0;
if (validator.validate(str, pos) == QValidator::Acceptable)
varList.push_back(QVariant(str.toDouble()));
else
varList.push_back(QVariant(-1.0));
}
model->setData(index, varList, Qt::EditRole);
break;
}
default:
{
break;
}
}
}
示例3: validateDlg
/*!
This checks the validators to make sure the number of friction cone vectors
and the dynamic time step are within their ranges. If they aren't, a
warning box explaining the problem is created. Otherwise, the dialog
is closed and accepted.
*/
void SettingsDlg::validateDlg()
{
int zero=0;
QString tst = dlgUI->timeStepLine->text();
QString msg;
QDoubleValidator *tsv = (QDoubleValidator *)dlgUI->timeStepLine->validator();
if (tsv->validate(tst,zero) != QValidator::Acceptable) {
msg = QString("Dynamic time step must be between %1 and %2").arg(tsv->bottom()).arg(tsv->top());
}
if (!msg.isEmpty()) {
QMessageBox::warning(NULL,"GraspIt!",msg,QMessageBox::Ok, Qt::NoButton,Qt::NoButton);
} else {
dlgImpl->accept();
}
}
示例4: setModelData
void DigDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const {
QLineEdit *le = qobject_cast<QLineEdit*>(editor);
QString value = le->text();
int pos = 0;
if (m_type == "DBL") {
QDoubleValidator *dv = new QDoubleValidator(le);
QValidator::State state = dv->validate(value,pos);
if (state != QValidator::Acceptable) {
return;
}
}
if (m_type == "INT") {
QIntValidator *iv = new QIntValidator(le);
QValidator::State state = iv->validate(value,pos);
if (state != QValidator::Acceptable) {
return;
}
}
model->setData(index, value);
}