コード例 #1
0
bool NewClassWidget::isValid(QString *error) const
{
    if (!m_d->m_ui.classLineEdit->isValid()) {
        if (error) {
            *error = m_d->m_ui.classLineEdit->errorMessage();
        }
        return false;
    }

    if (isBaseClassInputVisible() && isBaseClassEditable()) {
        // TODO: Should this be a ClassNameValidatingComboBox?
        QRegExp classNameValidator(QLatin1String("[a-zA-Z_][a-zA-Z0-9_]*(::[a-zA-Z_][a-zA-Z0-9_]*)*"));
        const QString baseClass = m_d->m_ui.baseClassComboBox->currentText().trimmed();
        if (!baseClass.isEmpty() && !classNameValidator.exactMatch(baseClass)) {
            if (error) {
                *error = tr("Invalid base class name");
            }
            return false;
        }
    }

    if (!m_d->m_ui.headerFileLineEdit->isValid()) {
        if (error) {
            *error = tr("Invalid header file name: '%1'").arg(m_d->m_ui.headerFileLineEdit->errorMessage());
        }
        return false;
    }

    if (!m_d->m_ui.sourceFileLineEdit->isValid()) {
        if (error) {
            *error = tr("Invalid source file name: '%1'").arg(m_d->m_ui.sourceFileLineEdit->errorMessage());
        }
        return false;
    }

    if (isFormInputVisible()) {
        if (!m_d->m_ui.formFileLineEdit->isValid()) {
            if (error) {
                *error = tr("Invalid form file name: '%1'").arg(m_d->m_ui.formFileLineEdit->errorMessage());
            }
            return false;
        }
    }

    if (isPathInputVisible()) {
        if (!m_d->m_ui.pathChooser->isValid()) {
            if (error) {
                *error = m_d->m_ui.pathChooser->errorMessage();
            }
            return false;
        }
    }
    return true;
}
コード例 #2
0
bool NewClassWidget::isValid(QString *error) const
{
    if (!d->m_ui.classLineEdit->isValid()) {
        if (error)
            *error = d->m_ui.classLineEdit->errorMessage();
        return false;
    }

    if (isBaseClassInputVisible() && isBaseClassEditable()) {
        const QString baseClass = d->m_ui.baseClassComboBox->currentText().trimmed();
        if (!baseClass.isEmpty() && !d->m_classNameValidator.exactMatch(baseClass)) {
            if (error)
                *error = tr("Invalid base class name");
            return false;
        }
    }

    if (isHeaderInputVisible() && !d->m_ui.headerFileLineEdit->isValid()) {
        if (error)
            *error = tr("Invalid header file name: '%1'").arg(d->m_ui.headerFileLineEdit->errorMessage());
        return false;
    }

    if (isSourceInputVisible() && !d->m_ui.sourceFileLineEdit->isValid()) {
        if (error)
            *error = tr("Invalid source file name: '%1'").arg(d->m_ui.sourceFileLineEdit->errorMessage());
        return false;
    }

    if (isFormInputVisible() &&
        (!d->m_formInputCheckable || d->m_ui.generateFormCheckBox->isChecked())) {
        if (!d->m_ui.formFileLineEdit->isValid()) {
            if (error)
                *error = tr("Invalid form file name: '%1'").arg(d->m_ui.formFileLineEdit->errorMessage());
            return false;
        }
    }

    if (isPathInputVisible()) {
        if (!d->m_ui.pathChooser->isValid()) {
            if (error)
                *error =  d->m_ui.pathChooser->errorMessage();
            return false;
        }
    }
    return true;
}