String Locale::formatDateTime(const DateComponents& date, FormatType formatType) { if (date.getType() == DateComponents::Invalid) return String(); DateTimeStringBuilder builder(*this, date); switch (date.getType()) { case DateComponents::Time: builder.build(formatType == FormatTypeShort ? shortTimeFormat() : timeFormat()); break; case DateComponents::Date: builder.build(dateFormat()); break; case DateComponents::Month: builder.build(formatType == FormatTypeShort ? shortMonthFormat() : monthFormat()); break; case DateComponents::Week: builder.build(weekFormatInLDML()); break; case DateComponents::DateTime: case DateComponents::DateTimeLocal: builder.build(formatType == FormatTypeShort ? dateTimeFormatWithoutSeconds() : dateTimeFormatWithSeconds()); break; case DateComponents::Invalid: ASSERT_NOT_REACHED(); break; } return builder.toString(); }
QString QtPropertyBrowserUtils::dateTimeFormat() { QString format = dateFormat(); format += QLatin1Char(' '); format += timeFormat(); return format; }
void ImageWindow::paintEvent(QPaintEvent *event) { QString timestamp; QLabel::paintEvent(event); QString timeFormat("hh:mm:ss:zzz"); QString dateFormat("ddd MMMM d yyyy"); QPainter painter(this); QRect dr = drawingRect(); if (m_idle) painter.fillRect(dr, Qt::Dense2Pattern); if (m_selected) { QPen pen(Qt::green, 3); painter.setPen(pen); painter.drawRect(dr); } if (!m_showDate && !m_showTime && !m_showName) return; painter.setPen(m_textColor); int fontHeight = dr.height() / 20; if (fontHeight < 8) fontHeight = 8; else if (fontHeight > 12) fontHeight = 12; painter.setFont(QFont("Arial", fontHeight)); if (m_showName) painter.drawText(dr.left() + 4, dr.top() + fontHeight + 2, m_name); if (m_showTime || m_showDate) { if (dr.width() < 160) { // only room for one, choose time over date if (m_showDate && m_showTime) timestamp = m_displayTime.toString(timeFormat); else if (m_showDate) timestamp = m_displayDate.toString(dateFormat); else timestamp = m_displayTime.toString(timeFormat); } else if (!m_showDate) { timestamp = m_displayTime.toString(timeFormat); } else if (!m_showTime) { timestamp = m_displayDate.toString(dateFormat); } else { timestamp = m_displayDate.toString(dateFormat) + " " + m_displayTime.toString(timeFormat); } painter.drawText(dr.left() + 4, dr.bottom() - 2, timestamp); } }
/*! \internal Constructs the output file path based on formatting tags specified in output path property. */ QString SpdrImportPrivate::getOutputFilePath(const QString &inputFilePath) const { Q_Q(const SpdrImport); // TODO: allow to change the input file name, too! QFileInfo fileInfo(inputFilePath); QDateTime creationDate(fileInfo.lastModified()); // Reads both Unix and Windows paths QStringList pathSegments(q->outputPath().split(mPathSeparatorRegularExpression, QString::KeepEmptyParts)); pathSegments.append(fileInfo.fileName()); QStringList outputPathSegments; foreach (const QString &segment, pathSegments) { if (!segment.contains("<") && !segment.contains(">")) { outputPathSegments.append(segment); continue; } int lessThanIndex = segment.indexOf("<") + 1; int greaterThanIndex = segment.indexOf(">", lessThanIndex); QString dateFormat(segment.mid(lessThanIndex, greaterThanIndex - lessThanIndex)); QString resultSegment(segment); resultSegment.replace(QLatin1String("<") + dateFormat + QLatin1String(">"), creationDate.toString(dateFormat)); outputPathSegments.append(resultSegment); } QString result(outputPathSegments.join("/")); q->log(QCoreApplication::translate("SpdrImportPrivate", "Output file path set to: %1").arg(result), Spdr::Debug); return result; }
String LocaleWin::dateTimeFormatWithoutSeconds() { if (!m_dateTimeFormatWithoutSeconds.isNull()) return m_dateTimeFormatWithoutSeconds; StringBuilder builder; builder.append(dateFormat()); builder.append(' '); builder.append(shortTimeFormat()); m_dateTimeFormatWithoutSeconds = builder.toString(); return m_dateTimeFormatWithoutSeconds; }
static void printStat(unsigned char t) { printf(" type 0x%02x: (%llu)\n", t, type[t]); printf(" size: %llu\n", size[t]); char buf[3][64]; dateFormat(buf[0], tstamp[t][0]); dateFormat(buf[1], tstamp[t][1]); timeFormat(buf[2], tstamp[t][1] - tstamp[t][0]); printf(" time: %s - %s (%s)\n", buf[0], buf[1], buf[2]); if (tstamp[t][1] == tstamp[t][0]) return; double tt = (double) (tstamp[t][1] - tstamp[t][0]) / 1000000.0; double sps = (double) type[t] / tt; double mbs = (double) size[t] / 1024 / 1024 / tt; printf(" sp/s: %.1f\n", sps); printf(" mb/s: %.1f\n", mbs); }
/*! Returns a string based on the locale set, to format date. \return QString String to be used to format date. */ QString SettingsUtility::dateFormatString() { OstTraceFunctionEntry0( SETTINGSUTILITY_DATEFORMATSTRING_ENTRY ); QStringList dummyList; QString format(mDateFormatList.at(dateFormat(dummyList))); QString separator = mDateSeparatorList.at(dateSeparator(dummyList)); format.replace(QString(" "), separator); format.replace(QString("mm"), QString("MM")); OstTraceFunctionExit0( SETTINGSUTILITY_DATEFORMATSTRING_EXIT ); return format; }
void GuildShell::dumpMembers(QTextStream& out) { QDateTime dt; GuildMemberDictIterator it(m_members); GuildMember* member; QString format("%1 %2 %3 %4%5%6%7 %8 %9"); QString dateFormat("ddd MMM dd hh:mm:ss yyyy"); // calculate the maximum class name width size_t maxClassNameLength = 0; for (uint8_t i = 1; i <= PLAYER_CLASSES; i++) if (classString(i).length() > maxClassNameLength) maxClassNameLength = classString(i).length(); out << "Guild has " << m_members.count() << " members: " << endl; int nameFieldWidth = - m_maxNameLength; int classFieldWidth = - maxClassNameLength; out << format.arg("Members", nameFieldWidth) .arg("Lv", 2).arg("Class", classFieldWidth) .arg("R", 1) .arg("B", 1) .arg("A", 1) .arg("P", 1) .arg("Last On", -24) .arg("Zone", -18); out << " Public Note" << endl; QString zone; while ((member = it.current())) { dt.setTime_t(member->lastOn()); zone = zoneString(member->zoneId()); if (member->zoneInstance()) zone += ":" + QString::number(member->zoneInstance()); out << format.arg(member->name(), nameFieldWidth) .arg(member->level(), 2).arg(member->classString(), classFieldWidth) .arg(member->guildRankString(), 1) .arg(member->bankRankString(), 1) .arg(member->altRankString(), 1) .arg(member->memberRankString(), 1) .arg(dt.toString(dateFormat), -24) .arg(zone, -18); out << " " << member->publicNote() << endl; ++it; } }
/* Function: InvokeCallbackForDatePattern Gets the ICU date pattern for the specified locale and EStyle and invokes the callback with the result. */ bool InvokeCallbackForDatePattern(Locale& locale, DateFormat::EStyle style, EnumCalendarInfoCallback callback, const void* context) { LocalPointer<DateFormat> dateFormat(DateFormat::createDateInstance(style, locale)); if (dateFormat.isNull()) return false; // cast to SimpleDateFormat so we can call toPattern() SimpleDateFormat* sdf = dynamic_cast<SimpleDateFormat*>(dateFormat.getAlias()); if (sdf == NULL) return false; UnicodeString pattern; sdf->toPattern(pattern); callback(pattern.getTerminatedBuffer(), context); return true; }
void GuildMember::update(const GuildMemberUpdate* gmu) { m_zoneId = gmu->zoneId; m_zoneInstance = gmu->zoneInstance; m_lastOn = gmu->lastOn; #ifdef GUILDSHELL_DIAG QDateTime dt; QString dateFormat("ddd MMM dd hh:mm:ss yyyy"); dt.setTime_t(m_lastOn); QString zone; zone = QString::number(m_zoneId); if (zoneInstance()) zone += ":" + QString::number(m_zoneInstance); seqDebug("GuildShell: updated zone for member (member: %s, zone: %s, last on: %s", (const char*) m_name, (const char*) zone, (const char*) dt.toString(dateFormat)); #endif }
/// Use current time as the the last access time. const QString & ContentNode::updateLastAccess() { mutable_last_access() = QDateTime::currentDateTime().toString(dateFormat()); return last_access(); }
QString KLocale::dateFormat() const { return d->dateFormat(); }
void TestPreferences::testPreferences() { auto pref = SettingsObjectWrapper::instance(); pref->load(); auto cloud = pref->cloud_storage; cloud->setBackgroundSync(true); TEST(cloud->backgroundSync(), true); cloud->setBackgroundSync(false); TEST(cloud->backgroundSync(), false); cloud->setBaseUrl("test_one"); TEST(cloud->baseUrl(), QStringLiteral("test_one")); cloud->setBaseUrl("test_two"); TEST(cloud->baseUrl(), QStringLiteral("test_two")); cloud->setEmail("*****@*****.**"); TEST(cloud->email(), QStringLiteral("*****@*****.**")); cloud->setEmail("*****@*****.**"); TEST(cloud->email(), QStringLiteral("*****@*****.**")); cloud->setGitLocalOnly(true); TEST(cloud->gitLocalOnly(), true); cloud->setGitLocalOnly(false); TEST(cloud->gitLocalOnly(), false); // Why there's new password and password on the prefs? cloud->setNewPassword("ABCD"); TEST(cloud->newPassword(), QStringLiteral("ABCD")); cloud->setNewPassword("ABCDE"); TEST(cloud->newPassword(), QStringLiteral("ABCDE")); cloud->setPassword("ABCDE"); TEST(cloud->password(), QStringLiteral("ABCDE")); cloud->setPassword("ABCABC"); TEST(cloud->password(), QStringLiteral("ABCABC")); cloud->setSavePasswordLocal(true); TEST(cloud->savePasswordLocal(), true); cloud->setSavePasswordLocal(false); TEST(cloud->savePasswordLocal(), false); // Why this is short and not bool? cloud->setSaveUserIdLocal(1); TEST(cloud->saveUserIdLocal(), (short)1); cloud->setSaveUserIdLocal(0); TEST(cloud->saveUserIdLocal(), (short)0); cloud->setUserId("Tomaz"); TEST(cloud->userId(), QStringLiteral("Tomaz")); cloud->setUserId("Zamot"); TEST(cloud->userId(), QStringLiteral("Zamot")); cloud->setVerificationStatus(0); TEST(cloud->verificationStatus(), (short)0); cloud->setVerificationStatus(1); TEST(cloud->verificationStatus(), (short)1); auto tecDetails = pref->techDetails; tecDetails->setModp02(0.2); TEST(tecDetails->modp02(), 0.2); tecDetails->setModp02(1.0); TEST(tecDetails->modp02(), 1.0); tecDetails->setGflow(2); TEST(tecDetails->gflow(), 2); tecDetails->setGflow(3); TEST(tecDetails->gflow(), 3); tecDetails->setGfhigh(4); TEST(tecDetails->gfhigh(), 4); tecDetails->setGfhigh(5); TEST(tecDetails->gfhigh(), 5); tecDetails->setVpmbConservatism(5); TEST(tecDetails->vpmbConservatism(), (short)5); tecDetails->setVpmbConservatism(6); TEST(tecDetails->vpmbConservatism(), (short)6); tecDetails->setEad(true); TEST(tecDetails->ead(), true); tecDetails->setMod(true); TEST(tecDetails->mod(), true); tecDetails->setDCceiling(true); TEST(tecDetails->dcceiling(), true); tecDetails->setRedceiling(true); TEST(tecDetails->redceiling(), true); tecDetails->setCalcceiling(true); TEST(tecDetails->calcceiling(), true); tecDetails->setCalcceiling3m(true); TEST(tecDetails->calcceiling3m(), true); tecDetails->setCalcalltissues(true); TEST(tecDetails->calcalltissues(), true); tecDetails->setCalcndltts(true); TEST(tecDetails->calcndltts(), true); tecDetails->setBuehlmann(true); TEST(tecDetails->buehlmann(), true); tecDetails->setHRgraph(true); TEST(tecDetails->hrgraph(), true); tecDetails->setTankBar(true); TEST(tecDetails->tankBar(), true); tecDetails->setPercentageGraph(true); TEST(tecDetails->percentageGraph(), true); tecDetails->setRulerGraph(true); TEST(tecDetails->rulerGraph(), true); tecDetails->setShowCCRSetpoint(true); TEST(tecDetails->showCCRSetpoint(), true); tecDetails->setShowCCRSensors(true); TEST(tecDetails->showCCRSensors(), true); tecDetails->setZoomedPlot(true); TEST(tecDetails->zoomedPlot(), true); tecDetails->setShowSac(true); TEST(tecDetails->showSac(), true); tecDetails->setGfLowAtMaxDepth(true); TEST(tecDetails->gfLowAtMaxDepth(), true); tecDetails->setDisplayUnusedTanks(true); TEST(tecDetails->displayUnusedTanks(), true); tecDetails->setShowAverageDepth(true); TEST(tecDetails->showAverageDepth(), true); tecDetails->setShowPicturesInProfile(true); TEST(tecDetails->showPicturesInProfile(), true); tecDetails->setEad(false); TEST(tecDetails->ead(), false); tecDetails->setMod(false); TEST(tecDetails->mod(), false); tecDetails->setDCceiling(false); TEST(tecDetails->dcceiling(), false); tecDetails->setRedceiling(false); TEST(tecDetails->redceiling(), false); tecDetails->setCalcceiling(false); TEST(tecDetails->calcceiling(), false); tecDetails->setCalcceiling3m(false); TEST(tecDetails->calcceiling3m(), false); tecDetails->setCalcalltissues(false); TEST(tecDetails->calcalltissues(), false); tecDetails->setCalcndltts(false); TEST(tecDetails->calcndltts(), false); tecDetails->setBuehlmann(false); TEST(tecDetails->buehlmann(), false); tecDetails->setHRgraph(false); TEST(tecDetails->hrgraph(), false); tecDetails->setTankBar(false); TEST(tecDetails->tankBar(), false); tecDetails->setPercentageGraph(false); TEST(tecDetails->percentageGraph(), false); tecDetails->setRulerGraph(false); TEST(tecDetails->rulerGraph(), false); tecDetails->setShowCCRSetpoint(false); TEST(tecDetails->showCCRSetpoint(), false); tecDetails->setShowCCRSensors(false); TEST(tecDetails->showCCRSensors(), false); tecDetails->setZoomedPlot(false); TEST(tecDetails->zoomedPlot(), false); tecDetails->setShowSac(false); TEST(tecDetails->showSac(), false); tecDetails->setGfLowAtMaxDepth(false); TEST(tecDetails->gfLowAtMaxDepth(), false); tecDetails->setDisplayUnusedTanks(false); TEST(tecDetails->displayUnusedTanks(), false); tecDetails->setShowAverageDepth(false); TEST(tecDetails->showAverageDepth(), false); tecDetails->setShowPicturesInProfile(false); TEST(tecDetails->showPicturesInProfile(), false); auto pp = pref->pp_gas; pp->setShowPn2(false); pp->setShowPhe(false); pp->setShowPo2(false); pp->setPo2Threshold(1.0); pp->setPn2Threshold(2.0); pp->setPheThreshold(3.0); TEST(pp->showPn2(), (short) false); TEST(pp->showPhe(), (short) false); TEST(pp->showPo2(), (short) false); TEST(pp->pn2Threshold(), 2.0); TEST(pp->pheThreshold(), 3.0); TEST(pp->po2Threshold(), 1.0); pp->setShowPn2(true); pp->setShowPhe(true); pp->setShowPo2(true); pp->setPo2Threshold(4.0); pp->setPn2Threshold(5.0); pp->setPheThreshold(6.0); TEST(pp->showPn2(), (short) true); TEST(pp->showPhe(), (short) true); TEST(pp->showPo2(), (short) true); TEST(pp->pn2Threshold(), 5.0); TEST(pp->pheThreshold(), 6.0); TEST(pp->po2Threshold(), 4.0); auto fb = pref->facebook; fb->setAccessToken("rand-access-token"); fb->setUserId("tomaz-user-id"); fb->setAlbumId("album-id"); TEST(fb->accessToken(),QStringLiteral("rand-access-token")); TEST(fb->userId(), QStringLiteral("tomaz-user-id")); TEST(fb->albumId(), QStringLiteral("album-id")); fb->setAccessToken("rand-access-token-2"); fb->setUserId("tomaz-user-id-2"); fb->setAlbumId("album-id-2"); TEST(fb->accessToken(),QStringLiteral("rand-access-token-2")); TEST(fb->userId(), QStringLiteral("tomaz-user-id-2")); TEST(fb->albumId(), QStringLiteral("album-id-2")); auto geo = pref->geocoding; geo->setEnableGeocoding(true); geo->setParseDiveWithoutGps(true); geo->setTagExistingDives(true); TEST(geo->enableGeocoding(),true); TEST(geo->parseDiveWithoutGps(),true); TEST(geo->tagExistingDives(),true); geo->setFirstTaxonomyCategory(TC_NONE); geo->setSecondTaxonomyCategory(TC_OCEAN); geo->setThirdTaxonomyCategory(TC_COUNTRY); TEST(geo->firstTaxonomyCategory(), TC_NONE); TEST(geo->secondTaxonomyCategory(), TC_OCEAN); TEST(geo->thirdTaxonomyCategory(), TC_COUNTRY); geo->setEnableGeocoding(false); geo->setParseDiveWithoutGps(false); geo->setTagExistingDives(false); TEST(geo->enableGeocoding(),false); TEST(geo->parseDiveWithoutGps(),false); TEST(geo->tagExistingDives(),false); geo->setFirstTaxonomyCategory(TC_OCEAN); geo->setSecondTaxonomyCategory(TC_COUNTRY); geo->setThirdTaxonomyCategory(TC_NONE); TEST(geo->firstTaxonomyCategory(), TC_OCEAN); TEST(geo->secondTaxonomyCategory(), TC_COUNTRY); TEST(geo->thirdTaxonomyCategory(), TC_NONE); auto proxy = pref->proxy; proxy->setType(2); proxy->setPort(80); proxy->setAuth(true); proxy->setHost("localhost"); proxy->setUser("unknown"); proxy->setPass("secret"); TEST(proxy->type(),2); TEST(proxy->port(),80); TEST(proxy->auth(),true); TEST(proxy->host(),QStringLiteral("localhost")); TEST(proxy->user(),QStringLiteral("unknown")); TEST(proxy->pass(),QStringLiteral("secret")); proxy->setType(3); proxy->setPort(8080); proxy->setAuth(false); proxy->setHost("127.0.0.1"); proxy->setUser("unknown_1"); proxy->setPass("secret_1"); TEST(proxy->type(),3); TEST(proxy->port(),8080); TEST(proxy->auth(),false); TEST(proxy->host(),QStringLiteral("127.0.0.1")); TEST(proxy->user(),QStringLiteral("unknown_1")); TEST(proxy->pass(),QStringLiteral("secret_1")); auto planner = pref->planner_settings; planner->setLastStop(true); planner->setVerbatimPlan(true); planner->setDisplayRuntime(true); planner->setDisplayDuration(true); planner->setDisplayTransitions(true); planner->setDoo2breaks(true); planner->setDropStoneMode(true); planner->setSafetyStop(true); planner->setSwitchAtRequiredStop(true); planner->setAscrate75(1); planner->setAscrate50(2); planner->setAscratestops(3); planner->setAscratelast6m(4); planner->setDescrate(5); planner->setBottompo2(6); planner->setDecopo2(7); planner->setBestmixend(8); planner->setReserveGas(9); planner->setMinSwitchDuration(10); planner->setBottomSac(11); planner->setDecoSac(12); planner->setDecoMode(BUEHLMANN); TEST(planner->lastStop(),true); TEST(planner->verbatimPlan(),true); TEST(planner->displayRuntime(),true); TEST(planner->displayDuration(),true); TEST(planner->displayTransitions(),true); TEST(planner->doo2breaks(),true); TEST(planner->dropStoneMode(),true); TEST(planner->safetyStop(),true); TEST(planner->switchAtRequiredStop(),true); TEST(planner->ascrate75(),1); TEST(planner->ascrate50(),2); TEST(planner->ascratestops(),3); TEST(planner->ascratelast6m(),4); TEST(planner->descrate(),5); TEST(planner->bottompo2(),6); TEST(planner->decopo2(),7); TEST(planner->bestmixend(),8); TEST(planner->reserveGas(),9); TEST(planner->minSwitchDuration(),10); TEST(planner->bottomSac(),11); TEST(planner->decoSac(),12); TEST(planner->decoMode(),BUEHLMANN); planner->setLastStop(false); planner->setVerbatimPlan(false); planner->setDisplayRuntime(false); planner->setDisplayDuration(false); planner->setDisplayTransitions(false); planner->setDoo2breaks(false); planner->setDropStoneMode(false); planner->setSafetyStop(false); planner->setSwitchAtRequiredStop(false); planner->setAscrate75(11); planner->setAscrate50(12); planner->setAscratestops(13); planner->setAscratelast6m(14); planner->setDescrate(15); planner->setBottompo2(16); planner->setDecopo2(17); planner->setBestmixend(18); planner->setReserveGas(19); planner->setMinSwitchDuration(110); planner->setBottomSac(111); planner->setDecoSac(112); planner->setDecoMode(RECREATIONAL); TEST(planner->lastStop(),false); TEST(planner->verbatimPlan(),false); TEST(planner->displayRuntime(),false); TEST(planner->displayDuration(),false); TEST(planner->displayTransitions(),false); TEST(planner->doo2breaks(),false); TEST(planner->dropStoneMode(),false); TEST(planner->safetyStop(),false); TEST(planner->switchAtRequiredStop(),false); TEST(planner->ascrate75(),11); TEST(planner->ascrate50(),12); TEST(planner->ascratestops(),13); TEST(planner->ascratelast6m(),14); TEST(planner->descrate(),15); TEST(planner->bottompo2(),16); TEST(planner->decopo2(),17); TEST(planner->bestmixend(),18); TEST(planner->reserveGas(),19); TEST(planner->minSwitchDuration(),110); TEST(planner->bottomSac(),111); TEST(planner->decoSac(),112); TEST(planner->decoMode(),RECREATIONAL); auto units = pref->unit_settings; units->setLength(0); units->setPressure(0); units->setVolume(0); units->setTemperature(0); units->setWeight(0); units->setVerticalSpeedTime(0); units->setUnitSystem(QStringLiteral("metric")); units->setCoordinatesTraditional(false); TEST(units->length(),0); TEST(units->pressure(),0); TEST(units->volume(),0); TEST(units->temperature(),0); TEST(units->weight(),0); TEST(units->verticalSpeedTime(),0); TEST(units->unitSystem(),QStringLiteral("metric")); TEST(units->coordinatesTraditional(),false); units->setLength(1); units->setPressure(1); units->setVolume(1); units->setTemperature(1); units->setWeight(1); units->setVerticalSpeedTime(1); units->setUnitSystem(QStringLiteral("fake-metric-system")); units->setCoordinatesTraditional(true); TEST(units->length(),1); TEST(units->pressure(),1); TEST(units->volume(),1); TEST(units->temperature(),1); TEST(units->weight(),1); TEST(units->verticalSpeedTime(),1); TEST(units->unitSystem(),QStringLiteral("personalized")); TEST(units->coordinatesTraditional(),true); auto general = pref->general_settings; general->setDefaultFilename ("filename"); general->setDefaultCylinder ("cylinder_2"); //TODOl: Change this to a enum. // This is 'undefined', it will need to figure out later between no_file or use_deault file. general->setDefaultFileBehavior (0); general->setDefaultSetPoint (0); general->setO2Consumption (0); general->setPscrRatio (0); general->setUseDefaultFile (true); TEST(general->defaultFilename(), QStringLiteral("filename")); TEST(general->defaultCylinder(), QStringLiteral("cylinder_2")); TEST(general->defaultFileBehavior(), (short) LOCAL_DEFAULT_FILE); // since we have a default file, here it returns TEST(general->defaultSetPoint(), 0); TEST(general->o2Consumption(), 0); TEST(general->pscrRatio(), 0); TEST(general->useDefaultFile(), true); general->setDefaultFilename ("no_file_name"); general->setDefaultCylinder ("cylinder_1"); //TODOl: Change this to a enum. general->setDefaultFileBehavior (CLOUD_DEFAULT_FILE); general->setDefaultSetPoint (1); general->setO2Consumption (1); general->setPscrRatio (1); general->setUseDefaultFile (false); TEST(general->defaultFilename(), QStringLiteral("no_file_name")); TEST(general->defaultCylinder(), QStringLiteral("cylinder_1")); TEST(general->defaultFileBehavior(), (short) CLOUD_DEFAULT_FILE); TEST(general->defaultSetPoint(), 1); TEST(general->o2Consumption(), 1); TEST(general->pscrRatio(), 1); TEST(general->useDefaultFile(), false); auto display = pref->display_settings; display->setDivelistFont("comic"); display->setFontSize(10.0); display->setDisplayInvalidDives(true); TEST(display->divelistFont(),QStringLiteral("comic")); TEST(display->fontSize(), 10.0); TEST(display->displayInvalidDives(),(short) true); //TODO: this is true / false. display->setDivelistFont("helvetica"); display->setFontSize(14.0); display->setDisplayInvalidDives(false); TEST(display->divelistFont(),QStringLiteral("helvetica")); TEST(display->fontSize(), 14.0); TEST(display->displayInvalidDives(),(short) false); auto language = pref->language_settings; language->setLangLocale ("en_US"); language->setLanguage ("en"); language->setTimeFormat ("hh:mm"); language->setDateFormat ("dd/mm/yy"); language->setDateFormatShort ("dd/mm"); language->setTimeFormatOverride (false); language->setDateFormatOverride (false); language->setUseSystemLanguage (false); TEST(language->langLocale(), QStringLiteral("en_US")); TEST(language->language(), QStringLiteral("en")); TEST(language->timeFormat(), QStringLiteral("hh:mm")); TEST(language->dateFormat(), QStringLiteral("dd/mm/yy")); TEST(language->dateFormatShort(), QStringLiteral("dd/mm")); TEST(language->timeFormatOverride(), false); TEST(language->dateFormatOverride(), false); TEST(language->useSystemLanguage(), false); language->setLangLocale ("en_EN"); language->setLanguage ("br"); language->setTimeFormat ("mm:hh"); language->setDateFormat ("yy/mm/dd"); language->setDateFormatShort ("dd/yy"); language->setTimeFormatOverride (true); language->setDateFormatOverride (true); language->setUseSystemLanguage (true); TEST(language->langLocale(), QStringLiteral("en_EN")); TEST(language->language(), QStringLiteral("br")); TEST(language->timeFormat(), QStringLiteral("mm:hh")); TEST(language->dateFormat(), QStringLiteral("yy/mm/dd")); TEST(language->dateFormatShort(), QStringLiteral("dd/yy")); TEST(language->timeFormatOverride(),true); TEST(language->dateFormatOverride(),true); TEST(language->useSystemLanguage(), true); pref->animation_settings->setAnimationSpeed(20); TEST(pref->animation_settings->animationSpeed(), 20); pref->animation_settings->setAnimationSpeed(30); TEST(pref->animation_settings->animationSpeed(), 30); auto location = pref->location_settings; location->setTimeThreshold(10); location->setDistanceThreshold(20); TEST(location->timeThreshold(), 10); TEST(location->distanceThreshold(), 20); location->setTimeThreshold(30); location->setDistanceThreshold(40); TEST(location->timeThreshold(), 30); TEST(location->distanceThreshold(), 40); auto update = pref->update_manager_settings; QDate date = QDate::currentDate(); update->setDontCheckForUpdates(true); update->setLastVersionUsed("tomaz-1"); update->setNextCheck(date); TEST(update->dontCheckForUpdates(), true); TEST(update->lastVersionUsed(), QStringLiteral("tomaz-1")); TEST(update->nextCheck(), date); date.addDays(3); update->setDontCheckForUpdates(false); update->setLastVersionUsed("tomaz-2"); update->setNextCheck(date); TEST(update->dontCheckForUpdates(), false); TEST(update->lastVersionUsed(), QStringLiteral("tomaz-2")); TEST(update->nextCheck(), date); auto dc = pref->dive_computer_settings; dc->setDevice("TomazComputer"); TEST(dc->dc_device(), QStringLiteral("TomazComputer")); dc->setDevice("Deepwater"); TEST(dc->dc_device(), QStringLiteral("Deepwater")); dc->setDownloadMode(0); TEST(dc->downloadMode(), 0); dc->setDownloadMode(1); TEST(dc->downloadMode(), 1); dc->setProduct("Thingy1"); TEST(dc->dc_product(), QStringLiteral("Thingy1")); dc->setProduct("Thingy2"); TEST(dc->dc_product(), QStringLiteral("Thingy2")); dc->setVendor("Sharewater"); TEST(dc->dc_vendor(), QStringLiteral("Sharewater")); dc->setVendor("OSTS"); TEST(dc->dc_vendor(), QStringLiteral("OSTS")); }
/*! Validates the specified parameter \a hash by the set rules. As default, TF::Required is set for all parameters. If not required, set the rule to \a false like this: setRule("xxx", Tf::Required, false); */ bool TFormValidator::validate(const QVariantHash &hash) { errors.clear(); // Add default rules, Tf::Required. QString msg = Tf::app()->validationErrorMessage(Tf::Required); for (QStringListIterator i(hash.keys()); i.hasNext(); ) { const QString &k = i.next(); if (!containsRule(k, Tf::Required)) { rules.append(RuleEntry(k, (int)Tf::Required, true, msg)); } } for (QListIterator<RuleEntry> i(rules); i.hasNext(); ) { const RuleEntry &r = i.next(); QString str = hash.value(r.key).toString(); // value string if (str.isEmpty()) { bool req = r.value.toBool(); if (r.rule == Tf::Required && req) { tSystemDebug("validation error: required parameter is empty, key:%s", qPrintable(r.key)); errors << qMakePair(r.key, r.rule); } } else { bool ok1, ok2; tSystemDebug("validating key:%s value: %s", qPrintable(r.key), qPrintable(str)); switch (r.rule) { case Tf::Required: break; case Tf::MaxLength: { int max = r.value.toInt(&ok2); if (!ok2 || str.length() > max) { errors << qMakePair(r.key, r.rule); } break; } case Tf::MinLength: { int min = r.value.toInt(&ok2); if (!ok2 || str.length() < min) { errors << qMakePair(r.key, r.rule); } break; } case Tf::IntMax: { qint64 n = str.toLongLong(&ok1); qint64 max = r.value.toLongLong(&ok2); if (!ok1 || !ok2 || n > max) { errors << qMakePair(r.key, r.rule); } break; } case Tf::IntMin: { qint64 n = str.toLongLong(&ok1); qint64 min = r.value.toLongLong(&ok2); if (!ok1 || !ok2 || n < min) { errors << qMakePair(r.key, r.rule); } break; } case Tf::DoubleMax: { double n = str.toDouble(&ok1); double max = r.value.toLongLong(&ok2); if (!ok1 || !ok2 || n > max) { errors << qMakePair(r.key, r.rule); } break; } case Tf::DoubleMin: { double n = str.toDouble(&ok1); double min = r.value.toDouble(&ok2); if (!ok1 || !ok2 || n < min) { errors << qMakePair(r.key, r.rule); } break; } case Tf::EmailAddress: { // refer to RFC5321 if ( r.value.toBool() ) { QRegExp reg("^" ADDR_SPEC "$"); if (!reg.exactMatch(str)) { errors << qMakePair(r.key, r.rule); } } break; } case Tf::Url: { if ( r.value.toBool() ) { QUrl url(str, QUrl::StrictMode); if (!url.isValid()) { errors << qMakePair(r.key, r.rule); } } break; } case Tf::Date: { if ( r.value.toBool() ) { QDate date = QLocale().toDate(str, dateFormat()); if (!date.isValid()) { errors << qMakePair(r.key, r.rule); tSystemDebug("Validation error: Date format: %s", qPrintable(dateFormat())); } } break; } case Tf::Time: { if ( r.value.toBool() ) { QTime time = QLocale().toTime(str, timeFormat()); if (!time.isValid()) { errors << qMakePair(r.key, r.rule); tSystemDebug("Validation error: Time format: %s", qPrintable(timeFormat())); } } break; } case Tf::DateTime: { if ( r.value.toBool() ) { QDateTime dt = QLocale().toDateTime(str, dateTimeFormat()); if (!dt.isValid()) { errors << qMakePair(r.key, r.rule); tSystemDebug("Validation error: DateTime format: %s", qPrintable(dateTimeFormat())); } } break; } case Tf::Pattern: { QRegExp rx = r.value.toRegExp(); if (rx.isEmpty() || !rx.exactMatch(str)) { errors << qMakePair(r.key, r.rule); } break; } default: tSystemError("Internal Error, invalid rule: %d [%s:%d]", r.rule, __FILE__, __LINE__); break; } } } return errors.isEmpty(); }
bool DlgMain::OnClickSearch() { double maxCloud = QBeforeLast(m_ComboBox_MaxCloud->currentText(), '%').toDouble(); vector<MTLParser> selectedMTLParsers; QStringList selectedMTLFiles; QString inputPath = m_Edit_InputPath->text(); m_StartDate = m_DateEdit_StartDate->date(); m_EndDate = m_DateEdit_EndDate->date(); QStringList filter; QStringList MTLFiles; filter<<"*MTL.txt"; FindFile(inputPath, filter, MTLFiles); int nFiles = (int)MTLFiles.size(); if (nFiles < 1) { #ifdef debug cout<<"no MTL files are found!"<<endl; #endif return false; } vector<MTLParser> MTLParserList; for (int i = 0;i < nFiles;++i) { MTLParser psr; psr.parse(MTLFiles[i]); if (psr.DATE_ACQUIRED > m_StartDate && psr.DATE_ACQUIRED < m_EndDate) { MTLParserList.push_back(psr); } } nFiles = (int)MTLParserList.size(); if (nFiles < 1) { #ifdef debug cout<<"no MTL files are found!"<<endl; #endif return false; } // 按Path Row排序 std::sort(MTLParserList.begin(), MTLParserList.end(), comparePathRow); vector<MTLParser> MTLParserListTemp; MTLParserListTemp.push_back(MTLParserList[0]); QString currentPathRow = MTLParserList[0].m_strPathRow; for (int i = 1;i < nFiles;++i) { if (0 == MTLParserList[i].m_strPathRow.compare(currentPathRow)) { MTLParserListTemp.push_back(MTLParserList[i]); } else { MTLParser bestMTL = Best(MTLParserListTemp, m_StartDate, m_EndDate); if (bestMTL.CLOUD_COVER <= maxCloud) { selectedMTLParsers.push_back(bestMTL); selectedMTLFiles.push_back(bestMTL.m_PathMTL); } MTLParserListTemp.clear(); MTLParserListTemp.push_back(MTLParserList[i]); } currentPathRow = MTLParserListTemp.back().m_strPathRow; } MTLParser bestMTL = Best(MTLParserListTemp, m_StartDate, m_EndDate); if (bestMTL.CLOUD_COVER <= maxCloud) { selectedMTLParsers.push_back(bestMTL); selectedMTLFiles.push_back(bestMTL.m_PathMTL); } // 将挑选的数据写入日志文件 QString outLogFile = QDir::toNativeSeparators(m_Edit_OutputPath->text() + QDir::separator() + logFile); FILE* pf; QString dateFormat("yyyy.MM.dd"); fopen_s(&pf, outLogFile.toUtf8(), "w+"); int nSelected = (int)selectedMTLParsers.size(); fprintf(pf, "起始时间:%s\n", m_StartDate.toString(dateFormat).toUtf8().data()); fprintf(pf, "截止时间:%s\n", m_EndDate.toString(dateFormat).toUtf8().data()); fprintf(pf, "共挑选 %d 景\n", nSelected); for (int i = 0;i < nSelected;++i) { // 轨道号 日期 云量 路径 fprintf(pf, "%s\t%s\t%lf\t%s\n", selectedMTLParsers[i].m_strPathRow.toUtf8().data(), selectedMTLParsers[i].DATE_ACQUIRED.toString(dateFormat).toUtf8().data(), selectedMTLParsers[i].CLOUD_COVER, selectedMTLParsers[i].m_PathMTL.toUtf8().data()); } fclose(pf); ////////////////////////////////////////////////////////////////////////// // 开始复制数据 FileCopyProcessThread *fileCopyProcess = new FileCopyProcessThread; //m_progressListener = new DemConvertListener; //connect(m_progressListener,SIGNAL(updateProgress(double)),this,SLOT(OnUpdateProgress(double))); //connect(fileCopyProcess, SIGNAL(addLog(QString)),this,SLOT(OnAddLog(QString))); connect(fileCopyProcess, SIGNAL(taskProgress(double)),this,SLOT(OnTaskProgress(double))); //connect(fileCopyProcess, SIGNAL(newProgressListener()),this,SLOT(OnNewProgressListener())); //connect(fileCopyProcess, SIGNAL(releaseProgressListener()),this,SLOT(OnReleaseProgressListener())); connect(fileCopyProcess, SIGNAL(beginUI()),this,SLOT(lockUI())); connect(fileCopyProcess, SIGNAL(endUI()),this,SLOT(unlockUI())); //demListener->start(); //demListener->demListener(demProcess->m_progressListener);//监视进度线程 //demProcess->m_pDEMListenerThread = demListener; //double could = m_ComboBox_MaxCloud->currentText().toDouble(); bool bOverWrite = false; if (Qt::CheckState::Checked == m_CheckBox_OverWrite->checkState()) { bOverWrite = true; } fileCopyProcess->Process(selectedMTLFiles, m_Edit_OutputPath->text(), bOverWrite); //数据处理线程 return true; }
QVariant QSystemLocalePrivate::dateTimeFormat(QLocale::FormatType type) { return QString(dateFormat(type).toString() + QLatin1Char(' ') + timeFormat(type).toString()); }