void KReplaceDialogPrivate::_k_slotOk() { // If regex and backrefs are enabled, do a sanity check. if ( q->KFindDialog::d->regExp->isChecked() && q->KFindDialog::d->backRef->isChecked() ) { QRegExp r ( q->pattern() ); int caps = r.numCaptures(); QRegExp check(QString("((?:\\\\)+)(\\d+)")); int p = 0; QString rep = q->replacement(); while ( (p = check.indexIn( rep, p ) ) > -1 ) { if ( check.cap(1).length()%2 && check.cap(2).toInt() > caps ) { KMessageBox::information( q, i18n( "Your replacement string is referencing a capture greater than '\\%1', ", caps ) + ( caps ? i18np("but your pattern only defines 1 capture.", "but your pattern only defines %1 captures.", caps ) : i18n("but your pattern defines no captures.") ) + i18n("\nPlease correct.") ); return; // abort OKing } p += check.matchedLength(); } } q->KFindDialog::d->_k_slotOk(); q->KFindDialog::d->replace->addToHistory(q->replacement()); }
/** * \brief stepwidth is always relative (it is a double in case axistype == datetime) * * @param stepwidth to calculate the next step ( must be convertible to int or double) */ void evePosCalc::setStepWidth(QString stepwidth) { bool ok=false; if (axisType == eveDateTimeT){ // stepwidth is a double, we accept a number or HH:mm:ss.mmm format QRegExp regex = QRegExp("^(\\d+):(\\d+):([\\d.]+)$"); QRegExp duration = QRegExp("^P(\\d+)Y(\\d+)M(\\d+)DT(\\d+)H(\\d+)M([\\d.]+)S$"); if (stepwidth.contains(regex) && (regex.numCaptures() == 3)){ QStringList list = regex.capturedTexts(); int hours = list.at(1).toInt(&ok); int minutes = list.at(2).toInt(&ok); double seconds = list.at(3).toDouble(&ok) + (double)(60*minutes + 3600*hours); stepWidth.setValue(seconds); } else if (stepwidth.contains(duration) && (duration.numCaptures() == 6)){ QStringList list = duration.capturedTexts(); if ((list.at(1).toInt(&ok)!= 0) || (list.at(2).toInt(&ok)!= 0) || (list.at(3).toInt(&ok)!= 0)) sendError(MINOR, QString("ISO Duration not implemented for Y/M/D (%1)").arg(stepwidth)); double seconds = list.at(4).toDouble(&ok)*3600 + list.at(5).toDouble(&ok)*60 + list.at(6).toDouble(&ok); stepWidth.setValue(seconds); } else { stepWidth.setValue(stepwidth.toDouble(&ok)); } sendError(DEBUG, QString("set stepwidth to %1 (%2)").arg(stepWidth.toDouble(&ok)).arg(stepwidth)); } else if ((stepmode == MULTIPLY) || (axisType == eveDOUBLE)){ stepWidth.setValue(stepwidth.toDouble(&ok)); } else if (axisType == eveINT){ stepWidth.setValue(stepwidth.toInt(&ok)); } else if (axisType == eveStringT){ stepWidth.setValue(stepwidth.toInt(&ok)); } if (!ok) sendError(ERROR, QString("unable to set %1 as stepwidth").arg(stepwidth)); checkValues(); }
/** * * @param position start or end position relative or absolute * @param posVariant the variant startpos or endpos */ void evePosCalc::setPos(QString position, eveVariant* posVariant) { if ((axisType == eveDateTimeT) && absolute){ // absolute: we accept only "yyyy-MM-dd HH:mm:ss(.zzz)" or "HH:mm:ss(.zzz)" format if (!position.contains(QRegExp("^\\d{4}-\\d{1,2}-\\d{1,2} \\d{1,2}:\\d{1,2}:\\d{1,2}([.]\\d{1,3})?$")) && !position.contains(QRegExp("^\\d{1,2}:\\d{1,2}:\\d{1,2}([.]\\d{1,3})?$"))){ sendError(ERROR, QString("invalid absolute datetime format %1, using current time").arg(position)); posVariant->setValue(QDateTime::currentDateTime()); return; } } else if ((axisType == eveDateTimeT) && !absolute){ // relative: we accept an ISO duration format or obsolete HH:mm:ss QRegExp duration = QRegExp("^P(\\d+)Y(\\d+)M(\\d+)DT(\\d+)H(\\d+)M([\\d.]+)S$"); if (position.contains(duration) && (duration.numCaptures() == 6)){ bool ok; QStringList list = duration.capturedTexts(); if ((list.at(1).toInt(&ok)!= 0) || (list.at(2).toInt(&ok)!= 0) || (list.at(3).toInt(&ok)!= 0)) sendError(MINOR, QString("ISO Duration not implemented for Y/M/D (%1)").arg(position)); double seconds = list.at(4).toDouble(&ok)*3600 + list.at(5).toDouble(&ok)*60 + list.at(6).toDouble(&ok); posVariant->setValue(seconds); return ; } // obsolete relative format accepts only a number for seconds or HH:mm:ss format else if (position.contains(QRegExp("^\\d{1,2}:\\d{1,2}:\\d{1,2}([.]\\d{1,3})?$"))){ // obsolete relative format accepts only a number for seconds or HH:mm:ss format QString format; if (position.contains(".")) format = "h:m:s.z"; else format = "h:m:s"; posVariant->setValue(QDateTime::fromString(position,format)); return; } else { sendError(ERROR, QString("invalid relative datetime format %1, using 0").arg(position)); posVariant->setValue(QDateTime()); return; } } if (!posVariant->setValue(position)) sendError(ERROR, QString("unable to set %1 as start/end position").arg(position)); checkValues(); return; }
bool MetricAggregator::importRide(QDir path, RideFile *ride, QString fileName, unsigned long fingerprint, bool modify) { SummaryMetrics *summaryMetric = new SummaryMetrics(); QFile file(path.absolutePath() + "/" + fileName); QRegExp rx = RideFileFactory::instance().rideFileRegExp(); if (!rx.exactMatch(fileName)) { return false; // not a ridefile! } summaryMetric->setFileName(fileName); assert(rx.numCaptures() == 7); QDate date(rx.cap(1).toInt(), rx.cap(2).toInt(),rx.cap(3).toInt()); QTime time(rx.cap(4).toInt(), rx.cap(5).toInt(),rx.cap(6).toInt()); QDateTime dateTime(date, time); summaryMetric->setRideDate(dateTime); summaryMetric->setId(ride->id()); const RideMetricFactory &factory = RideMetricFactory::instance(); QStringList metrics; for (int i = 0; i < factory.metricCount(); ++i) metrics << factory.metricName(i); // compute all the metrics QHash<QString, RideMetricPtr> computed = RideMetric::computeMetrics(main, ride, zones, hrzones, metrics); // get metrics into summaryMetric QMap for(int i = 0; i < factory.metricCount(); ++i) { // check for override summaryMetric->setForSymbol(factory.metricName(i), computed.value(factory.metricName(i))->value(true)); } // what color will this ride be? QColor color = colorEngine->colorFor(ride->getTag(main->rideMetadata()->getColorField(), "")); dbaccess->importRide(summaryMetric, ride, color, fingerprint, modify); #ifdef GC_HAVE_LUCENE main->lucene->importRide(summaryMetric, ride, color, fingerprint, modify); #endif delete summaryMetric; return true; }
void TCommandLine::handleTabCompletion( bool direction ) { if( ( mTabCompletionCount < 0 ) || ( mUserKeptOnTyping ) ) { mTabCompletionTyped = toPlainText(); if( mTabCompletionTyped.size() == 0 ) return; mUserKeptOnTyping = false; mTabCompletionCount = -1; } int amount = mpHost->mpConsole->buffer.size(); if( amount > 500 ) amount = 500; QStringList bufferList = mpHost->mpConsole->buffer.getEndLines( amount ); QString buffer = bufferList.join(" "); buffer.replace(QChar( 0x21af ), "\n"); buffer.replace(QChar('\n'), " " ); QStringList wordList = buffer.split( QRegExp("\\b"), QString::SkipEmptyParts ); if( direction ) { mTabCompletionCount++; } else { mTabCompletionCount--; } if( wordList.size() > 0 ) { if( mTabCompletionTyped.endsWith(" ") ) return; QString lastWord; QRegExp reg = QRegExp("\\b(\\w+)$"); int typePosition = reg.indexIn( mTabCompletionTyped ); if( reg.numCaptures() >= 1 ) lastWord = reg.cap( 1 ); else lastWord = ""; QStringList filterList = wordList.filter( QRegExp( "^"+lastWord+"\\w+",Qt::CaseInsensitive ) ); if( filterList.size() < 1 ) return; int offset = 0; for( ; ; ) { QString tmp = filterList.back(); filterList.removeAll( tmp ); filterList.insert( offset, tmp ); ++offset; if( offset >= filterList.size() ) break; } if( filterList.size() > 0 ) { if( mTabCompletionCount >= filterList.size() ) mTabCompletionCount = filterList.size()-1; if( mTabCompletionCount < 0 ) mTabCompletionCount = 0; QString proposal = filterList[mTabCompletionCount]; QString userWords = mTabCompletionTyped.left( typePosition ); setPlainText( QString( userWords + proposal ).trimmed() ); moveCursor( QTextCursor::End, QTextCursor::MoveAnchor ); mTabCompletionOld = toPlainText(); } } }
QString ImageImporter::replaceStrings(const QString& src, const QFileInfo* fileinfo, QRegExp regexp ) { QString retval = src; //general replacement for keys of the form $qdt-XXX where XXX is one of the generic QDateTime // format strings QStringList qdt; qdt << "dddd" << "ddd" << "dd" << "d" << "MMMM" << "MMM" << "MM" << "M" << "yyyy" << "yy" << "hh" << "h" << "mm" << "m" << "ss" << "s" << "zzz" << "z" << "AP" << "ap"; QStringList dateTimeVars; QStringList dateTimeRepl; dateTimeVars << "year" << "month" << "day" << "hour" << "min" << "sec"; dateTimeRepl << "yyyy" << "MM" << "dd" << "hh" << "mm" << "ss" ; for (QStringList::iterator it = qdt.begin(); it != qdt.end(); ++it) { dateTimeVars << QString("$qdt-%1").arg(*it); dateTimeRepl << QString(*it); } if (fileinfo == 0L) { QDateTime dt = QDateTime::currentDateTime(); if (dt.isValid()) { retval = retval.replace("$year" , dt.toString("yyyy")); retval = retval.replace("$month", dt.toString("MM")); retval = retval.replace("$day" , dt.toString("dd")); retval = retval.replace("$hour" , dt.toString("hh")); retval = retval.replace("$min" , dt.toString("mm")); retval = retval.replace("$sec" , dt.toString("ss")); for (QStringList::iterator it = qdt.begin(); it != qdt.end(); ++it) { retval = retval.replace(QString("$qdt-%1").arg(*it) , dt.toString(*it)); } } retval = retval.replace("$ext" , "[ext]"); retval = retval.replace("$model" , "[model]"); retval = retval.replace("$make" , "[make]"); retval = retval.replace("$0" , "[orig-filename]"); for (int i = 1; i < 10; ++i) { retval = retval.replace(QString("$%1").arg(i) , QString("[capture-%1]").arg(i)); } } else { //replace the captures ... if (regexp.exactMatch(fileinfo->fileName())) { for (int i = 0; i <= regexp.numCaptures(); ++i) { retval = retval.replace(QString("$%1").arg(i) , regexp.cap(i)); } } // we begin with model, as it is a nice way to find out, if exif data is available // model QString model = getExifData(fileinfo->absFilePath(), EXIF_TAG_MODEL); // I assume: No exifdata available if model is not set if (model.isEmpty()) { return ""; } retval = retval.replace("$model" , model); // make QString make = getExifData(fileinfo->absFilePath(), EXIF_TAG_MAKE); retval = retval.replace("$make" , make); // dateTime original QDateTime dt = QDateTime::fromString(getExifData(fileinfo->absFilePath(), EXIF_TAG_DATE_TIME_ORIGINAL) .replace(":", "-"), Qt::ISODate); if (dt.isValid()) { retval = retval.replace("$year" , dt.toString("yyyy")); retval = retval.replace("$month", dt.toString("MM")); retval = retval.replace("$day" , dt.toString("dd")); retval = retval.replace("$hour" , dt.toString("hh")); retval = retval.replace("$min" , dt.toString("mm")); retval = retval.replace("$sec" , dt.toString("ss")); for (QStringList::iterator it = qdt.begin(); it != qdt.end(); ++it) { retval = retval.replace(QString("$qdt-%1").arg(*it) , dt.toString(*it)); } } // extension int pos = fileinfo->fileName().findRev('.') + 1; if (pos > 0) { retval = retval.replace("$ext" , fileinfo->fileName().mid(pos)); } } //remove all unreplaced $variables if (retval.contains("$") ) { ///@todo remove all $variables that could not be replaced } //finally remove multiple slashes while (retval.contains("//")) { retval = retval.replace("//", "/"); } return retval; }