//-+#+-+#+-+#+-+#+-+#+-+#+-+#+-+#+-+#+-+#+-+#+-+#+-+#+-+#+-+#+-+#+-+#+-+#+- void ovQDateSpanDialog::slotEndYearLineEditTextChanged( const QString &constText ) { if( this->isValidatingEndYear ) return; this->isValidatingEndYear = true; // validate the input int pos; QValidator *v = new QIntValidator( 1, 9999, NULL ); QString text = constText; this->ui->endYearLineEdit->setText( QValidator::Invalid == v->validate( text, pos ) ? "" : text ); // enable/disable month drop down depending on if we have a year this->ui->endMonthComboBox->setEnabled( 0 < this->ui->endYearLineEdit->text().length() ); // We may be changing the year with the month and day combo boxes already active, // so make sure to update the number of days per month (in case the month selector // is on February and we change whether we're in a leap year or not) if( 2 == this->ui->endMonthComboBox->currentIndex() ) { // this is cheating a bit, but currently speed (of coding) is of the essence this->ovQDateSpanDialog::slotEndMonthComboBoxCurrentIndexChanged( 2 ); } this->isValidatingEndYear = false; }
//****************************************************************************************** //function: getWebServiceURL //params: const QString &lpzURL //return: QString //Description: Get correct webservice URL. //****************************************************************************************** QString WSClient::getWebServiceURL(const QString &lpzURL) { int index = 0; QString lpzValidateURL = lpzURL; QRegExp urlRegex("^(http|https)://[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}(([0-9]{1,5})?/?.*)$"); QValidator* urlValidate = new QRegExpValidator(urlRegex); if (urlValidate->validate(lpzValidateURL, index) == QValidator::Acceptable) { if(lpzValidateURL.indexOf(QString(SERVICE_BASE)) >= 1) { return lpzValidateURL; } else { if(lpzValidateURL.at(lpzValidateURL.length() -1) == '/') { lpzValidateURL += QString(SERVICE_BASE); } else { lpzValidateURL += "/" + QString(SERVICE_BASE); } } } else { throw "Invalid URL"; } return lpzValidateURL; }
void MultipleRangeSelector::sl_multipleButtonToggled( bool toggleState){ if (toggleState){ QValidator *v = new GenbankLocationValidator(ui->buttonBox->button(QDialogButtonBox::Ok), seqLen, isCircular, ui->multipleRegionEdit); ui->multipleRegionEdit->setValidator(v); int size = ui->multipleRegionEdit->text().size(); QString toValidate = ui->multipleRegionEdit->text(); v->validate(toValidate, size); }else{ delete ui->multipleRegionEdit->validator(); ui->multipleRegionEdit->setValidator(NULL); } }
bool VUtils::checkPathLegal(const QString &p_path) { // Ensure every part of the p_path is a valid file name until we come to // an existing parent directory. if (p_path.isEmpty()) { return false; } if (QFileInfo::exists(p_path)) { #if defined(Q_OS_WIN) // On Windows, "/" and ":" will also make exists() return true. if (p_path.startsWith('/') || p_path == ":") { return false; } #endif return true; } bool ret = false; int pos; QString basePath = basePathFromPath(p_path); QString fileName = fileNameFromPath(p_path); QValidator *validator = new QRegExpValidator(QRegExp(c_fileNameRegExp)); while (!fileName.isEmpty()) { QValidator::State validFile = validator->validate(fileName, pos); if (validFile != QValidator::Acceptable) { break; } if (QFileInfo::exists(basePath)) { ret = true; #if defined(Q_OS_WIN) // On Windows, "/" and ":" will also make exists() return true. if (basePath.startsWith('/') || basePath == ":") { ret = false; } #endif break; } fileName = fileNameFromPath(basePath); basePath = basePathFromPath(basePath); } delete validator; return ret; }
void Commentaire::goNext(){ QString qteString = ui->qteEdit->text(); QRegExp rx("[1-9]\\d{0,3}"); QValidator *validator = new QRegExpValidator(rx, 0); int pos = 0; if(validator->validate(qteString,pos) != 2){ QMessageBox::warning(this,"Erreur de saisie","Veuillez saisir un nombre entre 1 et 999"); return; } else{ currentProduit->setQte(ui->qteEdit->text().toInt()); if(generateReplaceVBS()) zipXlsx(); else return; } }
void MainWindow::postAddFriendLogin(const QString &login) { QValidator *loginValidator = LineEditVerifier::createLoginValidator(); int i = 0; QString loginCheck(login); QValidator::State state = loginValidator->validate(loginCheck, i); delete loginValidator; if (state != QValidator::Acceptable) { QMessageBox::warning(this, tr(CHECK_ERROR_TITLE), tr(CHECK_LOGIN_ERROR_MESSAGE)); return; } else friendLoginFromUrl = login; if (INFOMANAGER->isUserOnline()) addFriendByLogin(); }
void QLineEdit::keyPressEvent( QKeyEvent *e ) { if ( e->key() == Key_Enter || e->key() == Key_Return ) { QValidator * v = validator(); if ( !v || v->validate( tbuf, cursorPos ) == QValidator::Acceptable ) { emit returnPressed(); } else if ( v ) { v->fixup( tbuf ); if ( v->validate( tbuf, cursorPos ) == QValidator::Acceptable ) emit returnPressed(); } // ### 2.0 must fix this e->ignore(); return; } if ( e->ascii() >= 32 && e->key() != Key_Delete && e->key() != Key_Backspace ) { QString t( 2 ); t[0] = e->ascii(); t[1] = '\0'; insert( t ); return; } int unknown = 0; if ( e->state() & ControlButton ) { switch ( e->key() ) { case Key_A: case Key_Left: home( e->state() & ShiftButton ); break; case Key_B: cursorLeft( e->state() & ShiftButton ); break; case Key_C: if ( hasMarkedText() && echoMode() == Normal ) copyText(); break; case Key_D: del(); break; case Key_E: case Key_Right: end( e->state() & ShiftButton ); break; case Key_F: cursorRight( e->state() & ShiftButton ); break; case Key_H: backspace(); break; case Key_K: if ( cursorPos < (int)tbuf.length() ) { QString t( tbuf ); t.detach(); // ### 2.0 t.truncate( cursorPos ); validateAndSet( t, cursorPos, cursorPos, cursorPos ); } break; case Key_V: insert( QApplication::clipboard()->text() ); case Key_X: if ( hasMarkedText() && echoMode() == Normal ) { copyText(); del(); } break; default: unknown++; } } else { switch ( e->key() ) { case Key_Left: cursorLeft( e->state() & ShiftButton ); break; case Key_Right: cursorRight( e->state() & ShiftButton ); break; case Key_Backspace: backspace(); break; case Key_Home: home( e->state() & ShiftButton ); break; case Key_End: end( e->state() & ShiftButton ); break; case Key_Delete: del(); break; default: unknown++; } } if ( unknown ) { // unknown key e->ignore(); return; } }
bool QLineEdit::validateAndSet( const char * newText, int newPos, int newMarkAnchor, int newMarkDrag ) { QString t( newText ); if ( !t.isEmpty() ) { uchar *p = (uchar *) t.data(); while ( *p ) { // unprintable/linefeed becomes space if ( *p < 32 ) *p = 32; p++; } } if ( t.length() > (uint)maxLength() ) t.truncate( maxLength() ); QValidator * v = validator(); if ( v && v->validate( t, newPos ) == QValidator::Invalid && v->validate( tbuf, cursorPos ) != QValidator::Invalid ) { return FALSE; } // okay, it succeeded if ( newMarkDrag != markDrag || newMarkAnchor |! markAnchor || newPos != cursorPos || t != tbuf ) { int minP = QMIN( cursorPos, minMark() ); int maxP = QMAX( cursorPos, maxMark() ); cursorPos = newPos; markAnchor = newMarkAnchor; markDrag = newMarkDrag; d->pmDirty = TRUE; minP = QMIN( minP, QMIN( cursorPos, minMark() ) ); maxP = QMAX( maxP, QMAX( cursorPos, maxMark() ) ); if ( tbuf == t || tbuf == t.right( tbuf.length() ) ) { int i = 0; while( i < minP && t[i] == tbuf[i] ) i++; minP = i; i = t.length(); if ( i > (int) tbuf.length() ) { tbuf = t; } else { while( i > maxP && t[i] == tbuf[i] ) i--; } maxP = i; repaintArea( minP, maxP ); } else { tbuf = t; d->pmDirty = TRUE; QFontMetrics fm = fontMetrics(); int x; if ( offset > cursorPos ) x = 0; else x = fm.width(t.mid( offset, cursorPos - offset) ); int margin = frame() ? 2 : 0; if ( x >= width() - margin ) { while( x >= width() - margin ) { int w = fm.width( tbuf[offset] ); x -= w; offset++; } } d->pmDirty = TRUE; repaint( FALSE ); } } emit textChanged( tbuf ); return TRUE; }
//--------------------------------------------------------------------------- // typeChanged // //! Called when an option in the type dropdown box is activated. // //! @param string the activated option //--------------------------------------------------------------------------- void SearchConditionForm::typeChanged(const QString& string) { SearchCondition::SearchType type = Auxil::stringToSearchType(string); switch (type) { case SearchCondition::PatternMatch: case SearchCondition::AnagramMatch: case SearchCondition::SubanagramMatch: case SearchCondition::Prefix: case SearchCondition::Suffix: case SearchCondition::IncludeLetters: case SearchCondition::Definition: { QValidator* validator = 0; if ((type == SearchCondition::Prefix) || (type == SearchCondition::Suffix) || (type == SearchCondition::IncludeLetters)) { validator = letterValidator; } else if ((type == SearchCondition::PatternMatch) || (type == SearchCondition::AnagramMatch) || (type == SearchCondition::SubanagramMatch)) { validator = patternValidator; } paramLine->setValidator(validator); if (validator) { QString text = paramLine->text(); int pos = 0; validator->validate(text, pos); paramLine->setText(text); } negationCbox->setEnabled(true); paramStack->setCurrentWidget(paramLineWidget); } break; case SearchCondition::Length: case SearchCondition::NumVowels: case SearchCondition::NumUniqueLetters: negationCbox->setCheckState(Qt::Unchecked); negationCbox->setEnabled(false); paramMinSbox->setMaximum(MAX_WORD_LEN); paramMinSbox->setValue(0); paramMaxSbox->setMaximum(MAX_WORD_LEN); paramMaxSbox->setValue(MAX_WORD_LEN); paramBlanksLabel->hide(); paramBlanksSbox->hide(); paramProbCbox->hide(); paramStack->setCurrentWidget(paramSboxWidget); break; case SearchCondition::PointValue: negationCbox->setCheckState(Qt::Unchecked); negationCbox->setEnabled(false); paramMinSbox->setMaximum(10 * MAX_WORD_LEN); paramMinSbox->setValue(0); paramMaxSbox->setMaximum(10 * MAX_WORD_LEN); paramMaxSbox->setValue(10 * MAX_WORD_LEN); paramBlanksLabel->hide(); paramBlanksSbox->hide(); paramProbCbox->hide(); paramStack->setCurrentWidget(paramSboxWidget); break; case SearchCondition::NumAnagrams: case SearchCondition::ProbabilityOrder: case SearchCondition::LimitByProbabilityOrder: case SearchCondition::PlayabilityOrder: case SearchCondition::LimitByPlayabilityOrder: negationCbox->setCheckState(Qt::Unchecked); negationCbox->setEnabled(false); paramMinSbox->setMaximum(MAX_MAX_INT_VALUE); paramMinSbox->setValue(0); paramMaxSbox->setMaximum(MAX_MAX_INT_VALUE); paramMaxSbox->setValue(MAX_MAX_INT_VALUE); paramProbCbox->setCheckState(Qt::Checked); paramBlanksSbox->setValue(MainSettings::getProbabilityNumBlanks()); if ((type == SearchCondition::ProbabilityOrder) || (type == SearchCondition::LimitByProbabilityOrder)) { paramBlanksLabel->show(); paramBlanksSbox->show(); } else { paramBlanksLabel->hide(); paramBlanksSbox->hide(); } if ((type == SearchCondition::ProbabilityOrder) || (type == SearchCondition::LimitByProbabilityOrder) || (type == SearchCondition::PlayabilityOrder) || (type == SearchCondition::LimitByPlayabilityOrder)) { paramProbCbox->show(); } else { paramProbCbox->hide(); } paramStack->setCurrentWidget(paramSboxWidget); break; case SearchCondition::Probability: negationCbox->setCheckState(Qt::Unchecked); negationCbox->setEnabled(false); paramMinSbox->setMaximum(100); paramMinSbox->setValue(0); paramMaxSbox->setMaximum(100); paramMaxSbox->setValue(100); paramStack->setCurrentWidget(paramSboxWidget); break; case SearchCondition::BelongToGroup: negationCbox->setEnabled(true); paramCbox->clear(); paramCbox->addItem(Auxil::searchSetToString(SetHookWords)); paramCbox->addItem(Auxil::searchSetToString(SetFrontHooks)); paramCbox->addItem(Auxil::searchSetToString(SetBackHooks)); paramCbox->addItem(Auxil::searchSetToString(SetHighFives)); paramCbox->addItem(Auxil::searchSetToString(SetTypeOneSevens)); paramCbox->addItem(Auxil::searchSetToString(SetTypeTwoSevens)); paramCbox->addItem(Auxil::searchSetToString(SetTypeThreeSevens)); paramCbox->addItem(Auxil::searchSetToString(SetTypeOneEights)); paramCbox->addItem(Auxil::searchSetToString(SetTypeTwoEights)); paramCbox->addItem(Auxil::searchSetToString(SetTypeThreeEights)); paramCbox->addItem( Auxil::searchSetToString(SetEightsFromSevenLetterStems)); paramStack->setCurrentWidget(paramCboxWidget); break; case SearchCondition::PartOfSpeech: negationCbox->setEnabled(true); paramCbox->clear(); foreach (const QString& pos, nicePosToPosMap.keys()) { paramCbox->addItem(pos); } paramStack->setCurrentWidget(paramCboxWidget); break; case SearchCondition::InLexicon: negationCbox->setEnabled(true); paramCbox->clear(); paramCbox->addItems(MainSettings::getAutoImportLexicons()); paramStack->setCurrentWidget(paramCboxWidget); break; case SearchCondition::ConsistOf: negationCbox->setCheckState(Qt::Unchecked); negationCbox->setEnabled(false); paramConsistMinSbox->setValue(0); paramConsistMaxSbox->setValue(100); paramStack->setCurrentWidget(paramConsistWidget); break; case SearchCondition::InWordList: negationCbox->setEnabled(true); setWordListString(QString()); paramStack->setCurrentWidget(paramWordListWidget); break; default: //qWarning("Unrecognized search condition: " + string); break; } legacy = false; emit contentsChanged(); }