本文整理汇总了C++中QDate::year方法的典型用法代码示例。如果您正苦于以下问题:C++ QDate::year方法的具体用法?C++ QDate::year怎么用?C++ QDate::year使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDate
的用法示例。
在下文中一共展示了QDate::year方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createMonthView
void HtmlExport::createMonthView(QTextStream *ts)
{
QDate start = fromDate();
start.setYMD(start.year(), start.month(), 1); // go back to first day in month
QDate end(start.year(), start.month(), start.daysInMonth());
int startmonth = start.month();
int startyear = start.year();
while (start < toDate()) {
// Write header
QDate hDate(start.year(), start.month(), 1);
QString hMon = hDate.toString(QStringLiteral("MMMM"));
QString hYear = hDate.toString(QStringLiteral("yyyy"));
*ts << "<h2>"
<< i18nc("@title month and year", "%1 %2", hMon, hYear)
<< "</h2>" << endl;
if (QLocale().firstDayOfWeek() == 1) {
start = start.addDays(1 - start.dayOfWeek());
} else {
if (start.dayOfWeek() != 7) {
start = start.addDays(-start.dayOfWeek());
}
}
*ts << "<table border=\"1\">" << endl;
// Write table header
*ts << " <tr>";
for (int i = 0; i < 7; ++i) {
*ts << "<th>" << QLocale().dayName(start.addDays(i).dayOfWeek()) << "</th>";
}
*ts << "</tr>" << endl;
// Write days
while (start <= end) {
*ts << " <tr>" << endl;
for (int i = 0; i < 7; ++i) {
*ts << " <td valign=\"top\"><table border=\"0\">";
*ts << "<tr><td ";
if (d->mHolidayMap.contains(start) || start.dayOfWeek() == 7) {
*ts << "class=\"dateholiday\"";
} else {
*ts << "class=\"date\"";
}
*ts << ">" << QString::number(start.day());
if (d->mHolidayMap.contains(start)) {
*ts << " <em>" << d->mHolidayMap[start] << "</em>";
}
*ts << "</td></tr><tr><td valign=\"top\">";
// Only print events within the from-to range
if (start >= fromDate() && start <= toDate()) {
Event::List events = d->mCalendar->events(start, d->mCalendar->timeSpec(),
EventSortStartDate,
SortDirectionAscending);
if (events.count()) {
*ts << "<table>";
Event::List::ConstIterator it;
for (it = events.constBegin(); it != events.constEnd(); ++it) {
if (checkSecrecy(*it)) {
createEvent(ts, *it, start, false);
}
}
*ts << "</table>";
} else {
*ts << " ";
}
}
*ts << "</td></tr></table></td>" << endl;
start = start.addDays(1);
}
*ts << " </tr>" << endl;
}
*ts << "</table>" << endl;
startmonth += 1;
if (startmonth > 12) {
startyear += 1;
startmonth = 1;
}
start.setYMD(startyear, startmonth, 1);
end.setYMD(start.year(), start.month(), start.daysInMonth());
}
}
示例2: VoltageLogOpenFile
/**
*
* @brief Open the log file for putting the voltage readings
*
* @return bool true on success, false otherwise
*/
bool TestMgr::VoltageLogOpenFile(void) {
int status = 0;
std::string name;
QDate cd = QDate::currentDate();
QTime ct = QTime::currentTime();
// Create the logs directory if it does not exist
QDir dir("/opt/ES/VocPhase1Test/Logs");
if (!dir.exists()) {
if (!dir.mkpath("/op/ES/VocPhase1Test/Logs")) {
// creation failed
status = -1;
}
}
// Attempt to open the file and write header
if (status == 0) {
m_VoltageLogEntryNumber = 0;
char buf[1024];
if (m_TestId.length() > 0) {
// Name format is log_yyyy-mm-dd_hhmmss_testId
sprintf(buf, "/opt/ES/VocPhase1Test/Logs/log_%4d-%02d-%02d_%02d%02d%02d_%s.csv",
cd.year(), cd.month(), cd.day(),
ct.hour(), ct.minute(), ct.second(),
m_TestId.toLocal8Bit().constData());
} else {
// Name format is log_yyyy-mm-dd_hhmmss
sprintf(buf, "/opt/ES/VocPhase1Test/Logs/log_%4d-%02d-%02d_%02d%02d%02d.csv",
cd.year(), cd.month(), cd.day(), ct.hour(), ct.minute(), ct.second());
}
m_LogFileHandle = fopen(buf, "w");
if (m_LogFileHandle) {
printf("LOG FILE IS OPEN: %s\n", buf);
sprintf(buf, "Run Date,%d/%d/%d %02d:%02d:%02d\n",
cd.year(), cd.month(), cd.day(), ct.hour(), ct.minute(), ct.second());
fprintf(m_LogFileHandle, buf, "%s");
if (m_TestId.length() > 0) {
sprintf(buf, "Test ID,%s\n", m_TestId.toLocal8Bit().constData());
fprintf(m_LogFileHandle, buf, "%s");
}
if (m_TestNote.length() > 0) {
sprintf(buf, "Test Note,%s\n", m_TestNote.toLocal8Bit().constData());
fprintf(m_LogFileHandle, buf, "%s");
}
fprintf(m_LogFileHandle,
"%s,%s,%s,%s,%s\n",
"Entry", "Time(ms)", "Temp(C)", "VAC(volts)", "FREQ(HZ)");
} else {
std::cout << "ERROR: Could not open file for logging: " << buf << std::endl;
status = -1;
}
}
return (status == 0) ? true : false;
}
示例3: updateData
void Calendar::updateData()
{
if (m_weeks == 0) {
return;
}
m_dayList.clear();
m_weekList.clear();
int totalDays = 7 * m_weeks;
int daysBeforeCurrentMonth = 0;
int daysAfterCurrentMonth = 0;
QDate firstDay(m_startDate.year(), m_startDate.month(), 1);
daysBeforeCurrentMonth = firstDay.dayOfWeek();
int daysThusFar = daysBeforeCurrentMonth + m_startDate.daysInMonth();
if (daysThusFar < totalDays) {
daysAfterCurrentMonth = totalDays - daysThusFar;
}
if (daysBeforeCurrentMonth > 0) {
QDate previousMonth = m_startDate.addMonths(-1);
for (int i = 0; i < daysBeforeCurrentMonth; ++i) {
DayData day;
day.isCurrentMonth = false;
day.isNextMonth = false;
day.isPreviousMonth = true;
day.dayNumber = previousMonth.daysInMonth() -
(daysBeforeCurrentMonth - (i + 1));
day.monthNumber = previousMonth.month();
day.yearNumber = previousMonth.year();
day.containsEventItems = false;
m_dayList << day;
}
}
for (int i = 0; i < m_startDate.daysInMonth(); ++i) {
DayData day;
day.isCurrentMonth = true;
day.isNextMonth = false;
day.isPreviousMonth = false;
day.dayNumber = i + 1;
day.monthNumber = m_startDate.month();
day.yearNumber = m_startDate.year();
day.containsEventItems = false;
m_dayList << day;
}
if (daysAfterCurrentMonth > 0) {
for (int i = 0; i < daysAfterCurrentMonth; ++i) {
DayData day;
day.isCurrentMonth = false;
day.isNextMonth = true;
day.isPreviousMonth = false;
day.dayNumber = i + 1;
day.monthNumber = m_startDate.addMonths(1).month();
day.yearNumber = m_startDate.addMonths(1).year();
day.containsEventItems = false;
m_dayList << day;
}
}
const int numOfDaysInCalendar = m_dayList.count();
for (int i = 0; i < numOfDaysInCalendar; i += 7) {
const DayData& data = m_dayList.at(i);
m_weekList <<
QDate(data.yearNumber, data.monthNumber, data.dayNumber).weekNumber();
}
m_model->update();
}
示例4: ApplyModifiers
/**
* Apply variable modifiers to a QHash containing variables.
* @param varModifierDefs [in] Variable modifier definitions.
* @param vars [in, out] Variables to modify.
* @param qDateTime [out, opt] If specified, QDateTime for the timestamp.
* @return 0 on success; non-zero if any modifiers failed.
*/
int VarReplace::ApplyModifiers(const QHash<QString, VarModifierDef> &varModifierDefs,
QHash<QString, QString> &vars,
QDateTime *qDateTime)
{
// Timestamp construction.
int year = -1, month = -1, day = -1;
int hour = -1, minute = -1, second = -1;
int ampm = -1;
// TODO: Verify that all variables to be modified
// were present in vars.
QList<QString> varIDs = vars.keys();
foreach (const QString &id, varIDs) {
if (!varModifierDefs.contains(id))
continue;
QString var = vars.value(id);
const VarModifierDef &varModifierDef = varModifierDefs[id];
// Always convert the string to num and char,
// in case it's needed for e.g. useAs==month.
int num = strToInt(var);
num += varModifierDef.addValue;
char chr = 0;
if (var.size() == 1) {
chr = var.at(0).toLatin1();
chr += varModifierDef.addValue;
}
// Apply the modifier.
switch (varModifierDef.varType) {
default:
case VarModifierDef::VARTYPE_STRING:
// Parse as a string.
// Nothing special needs to be done here...
break;
case VarModifierDef::VARTYPE_NUMBER:
// Parse as a number. (Base 10)
var = QString::number(num, 10);
break;
case VarModifierDef::VARTYPE_CHAR:
// Parse as an ASCII character.
if (var.size() != 1)
return -2;
var = QChar::fromLatin1(chr);
break;
}
// Pad the variable with fillChar, if necessary.
if (var.size() < varModifierDef.minWidth) {
var.reserve(varModifierDef.minWidth);
QChar fillChar = QChar::fromLatin1(varModifierDef.fillChar);
if (varModifierDef.fieldAlign == VarModifierDef::FIELDALIGN_LEFT) {
while (var.size() < varModifierDef.minWidth)
var.append(fillChar);
} else /*if (variableDef.fieldAlign == VarModifierDef::FIELDALIGN_RIGHT)*/ {
while (var.size() < varModifierDef.minWidth)
var.prepend(fillChar);
}
}
// Check if this variable should be used in the QDateTime.
switch (varModifierDef.useAs) {
default:
case VarModifierDef::USEAS_FILENAME:
// Not a QDateTime component.
break;
case VarModifierDef::USEAS_TS_YEAR:
if (num >= 0 && num <= 99) {
// 2-digit year.
year = num + 2000;
} else if (num >= 2000 && num <= 9999) {
// 4-digit year.
year = num;
} else {
// Invalid year.
return -3;
}
break;
case VarModifierDef::USEAS_TS_MONTH: {
if (num >= 1 && num <= 12)
month = num;
else
return -4;
break;
}
case VarModifierDef::USEAS_TS_DAY:
//.........这里部分代码省略.........
示例5: createMonthView
void HtmlExport::createMonthView(QTextStream *ts)
{
QDate start = fromDate();
start.setYMD(start.year(), start.month(), 1); // go back to first day in month
QDate end(start.year(), start.month(), start.daysInMonth());
int startmonth = start.month();
int startyear = start.year();
while(start < toDate())
{
// Write header
*ts << "<h2>" << (i18n("month_year", "%1 %2").arg(KGlobal::locale()->calendar()->monthName(start))
.arg(start.year())) << "</h2>\n";
if(KGlobal::locale()->weekStartDay() == 1)
{
start = start.addDays(1 - start.dayOfWeek());
}
else
{
if(start.dayOfWeek() != 7)
{
start = start.addDays(-start.dayOfWeek());
}
}
*ts << "<table border=\"1\">\n";
// Write table header
*ts << " <tr>";
for(int i = 0; i < 7; ++i)
{
*ts << "<th>" << KGlobal::locale()->calendar()->weekDayName(start.addDays(i)) << "</th>";
}
*ts << "</tr>\n";
// Write days
while(start <= end)
{
*ts << " <tr>\n";
for(int i = 0; i < 7; ++i)
{
*ts << " <td valign=\"top\"><table border=\"0\">";
*ts << "<tr><td ";
if(mHolidayMap.contains(start) || start.dayOfWeek() == 7)
{
*ts << "class=\"dateholiday\"";
}
else
{
*ts << "class=\"date\"";
}
*ts << ">" << QString::number(start.day());
if(mHolidayMap.contains(start))
{
*ts << " <em>" << mHolidayMap[start] << "</em>";
}
*ts << "</td></tr><tr><td valign=\"top\">";
Event::List events = mCalendar->events(start,
EventSortStartDate,
SortDirectionAscending);
if(events.count())
{
*ts << "<table>";
Event::List::ConstIterator it;
for(it = events.begin(); it != events.end(); ++it)
{
if(checkSecrecy(*it))
{
createEvent(ts, *it, start, false);
}
}
*ts << "</table>";
}
else
{
*ts << " ";
}
*ts << "</td></tr></table></td>\n";
start = start.addDays(1);
}
*ts << " </tr>\n";
}
*ts << "</table>\n";
startmonth += 1;
if(startmonth > 12)
{
startyear += 1;
startmonth = 1;
}
start.setYMD(startyear, startmonth, 1);
end.setYMD(start.year(), start.month(), start.daysInMonth());
}
}
示例6: getSetCheck
// Testing get/set functions
void tst_QCalendarWidget::getSetCheck()
{
QWidget topLevel;
QCalendarWidget object(&topLevel);
//horizontal header formats
object.setHorizontalHeaderFormat(QCalendarWidget::NoHorizontalHeader);
QCOMPARE(QCalendarWidget::NoHorizontalHeader, object.horizontalHeaderFormat());
object.setHorizontalHeaderFormat(QCalendarWidget::SingleLetterDayNames);
QCOMPARE(QCalendarWidget::SingleLetterDayNames, object.horizontalHeaderFormat());
object.setHorizontalHeaderFormat(QCalendarWidget::ShortDayNames);
QCOMPARE(QCalendarWidget::ShortDayNames, object.horizontalHeaderFormat());
object.setHorizontalHeaderFormat(QCalendarWidget::LongDayNames);
QCOMPARE(QCalendarWidget::LongDayNames, object.horizontalHeaderFormat());
//vertical header formats
object.setVerticalHeaderFormat(QCalendarWidget::ISOWeekNumbers);
QCOMPARE(QCalendarWidget::ISOWeekNumbers, object.verticalHeaderFormat());
object.setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
QCOMPARE(QCalendarWidget::NoVerticalHeader, object.verticalHeaderFormat());
//maximum Date
QDate maxDate(2006, 7, 3);
object.setMaximumDate(maxDate);
QCOMPARE(maxDate, object.maximumDate());
//minimum date
QDate minDate(2004, 7, 3);
object.setMinimumDate(minDate);
QCOMPARE(minDate, object.minimumDate());
//day of week
object.setFirstDayOfWeek(Qt::Thursday);
QCOMPARE(Qt::Thursday, object.firstDayOfWeek());
//grid visible
object.setGridVisible(true);
QVERIFY(object.isGridVisible());
object.setGridVisible(false);
QVERIFY(!object.isGridVisible());
//header visible
object.setNavigationBarVisible(true);
QVERIFY(object.isNavigationBarVisible());
object.setNavigationBarVisible(false);
QVERIFY(!object.isNavigationBarVisible());
//selection mode
QCOMPARE(QCalendarWidget::SingleSelection, object.selectionMode());
object.setSelectionMode(QCalendarWidget::NoSelection);
QCOMPARE(QCalendarWidget::NoSelection, object.selectionMode());
object.setSelectionMode(QCalendarWidget::SingleSelection);
QCOMPARE(QCalendarWidget::SingleSelection, object.selectionMode());
//selected date
QDate selectedDate(2005, 7, 3);
QSignalSpy spy(&object, SIGNAL(selectionChanged()));
object.setSelectedDate(selectedDate);
QCOMPARE(spy.count(), 1);
QCOMPARE(selectedDate, object.selectedDate());
//month and year
object.setCurrentPage(2004, 1);
QCOMPARE(1, object.monthShown());
QCOMPARE(2004, object.yearShown());
object.showNextMonth();
QCOMPARE(2, object.monthShown());
object.showPreviousMonth();
QCOMPARE(1, object.monthShown());
object.showNextYear();
QCOMPARE(2005, object.yearShown());
object.showPreviousYear();
QCOMPARE(2004, object.yearShown());
//date range
minDate = QDate(2006,1,1);
maxDate = QDate(2010,12,31);
object.setDateRange(minDate, maxDate);
QCOMPARE(maxDate, object.maximumDate());
QCOMPARE(minDate, object.minimumDate());
//date should not go beyond the minimum.
selectedDate = minDate.addDays(-10);
object.setSelectedDate(selectedDate);
QCOMPARE(minDate, object.selectedDate());
QVERIFY(selectedDate != object.selectedDate());
//date should not go beyond the maximum.
selectedDate = maxDate.addDays(10);
object.setSelectedDate(selectedDate);
QCOMPARE(maxDate, object.selectedDate());
QVERIFY(selectedDate != object.selectedDate());
//show today
QDate today = QDate::currentDate();
object.showToday();
QCOMPARE(today.month(), object.monthShown());
QCOMPARE(today.year(), object.yearShown());
//slect a different date and move.
object.setSelectedDate(minDate);
object.showSelectedDate();
QCOMPARE(minDate.month(), object.monthShown());
QCOMPARE(minDate.year(), object.yearShown());
}
示例7: saveXML
QDomElement Validity::saveXML(QDomDocument& doc, const ValueConverter *converter) const
{
QDomElement validityElement = doc.createElement("validity");
QDomElement param = doc.createElement("param");
param.setAttribute("cond", (int)d->cond);
param.setAttribute("action", (int)d->action);
param.setAttribute("allow", (int)d->restriction);
param.setAttribute("valmin", converter->asString(d->minValue).asString());
param.setAttribute("valmax", converter->asString(d->maxValue).asString());
param.setAttribute("displaymessage", d->displayMessage);
param.setAttribute("displayvalidationinformation", d->displayValidationInformation);
param.setAttribute("allowemptycell", d->allowEmptyCell);
if (!d->listValidity.isEmpty())
param.setAttribute("listvalidity", d->listValidity.join(";"));
validityElement.appendChild(param);
QDomElement titleElement = doc.createElement("title");
titleElement.appendChild(doc.createTextNode(d->title));
validityElement.appendChild(titleElement);
QDomElement messageElement = doc.createElement("message");
messageElement.appendChild(doc.createCDATASection(d->message));
validityElement.appendChild(messageElement);
QDomElement inputTitle = doc.createElement("inputtitle");
inputTitle.appendChild(doc.createTextNode(d->titleInfo));
validityElement.appendChild(inputTitle);
QDomElement inputMessage = doc.createElement("inputmessage");
inputMessage.appendChild(doc.createTextNode(d->messageInfo));
validityElement.appendChild(inputMessage);
QString tmp;
if (d->restriction == Time) {
QDomElement timeMinElement = doc.createElement("timemin");
tmp = converter->asString(d->minValue).asString();
timeMinElement.appendChild(doc.createTextNode(tmp));
validityElement.appendChild(timeMinElement);
if (d->cond == Conditional::Between || d->cond == Conditional::Different) {
QDomElement timeMaxElement = doc.createElement("timemax");
tmp = converter->asString(d->maxValue).asString();
timeMaxElement.appendChild(doc.createTextNode(tmp));
validityElement.appendChild(timeMaxElement);
}
}
if (d->restriction == Date) {
QDomElement dateMinElement = doc.createElement("datemin");
const QDate minDate = d->minValue.asDate(converter->settings());
QString tmp("%1/%2/%3");
tmp = tmp.arg(minDate.year()).arg(minDate.month()).arg(minDate.day());
dateMinElement.appendChild(doc.createTextNode(tmp));
validityElement.appendChild(dateMinElement);
if (d->cond == Conditional::Between || d->cond == Conditional::Different) {
QDomElement dateMaxElement = doc.createElement("datemax");
const QDate maxDate = d->maxValue.asDate(converter->settings());
QString tmp("%1/%2/%3");
tmp = tmp.arg(maxDate.year()).arg(maxDate.month()).arg(maxDate.day());
dateMaxElement.appendChild(doc.createTextNode(tmp));
validityElement.appendChild(dateMaxElement);
}
}
return validityElement;
}
示例8: SetLastModified
bool AssetCache::SetLastModified(const QString &assetRef, const QDateTime &dateTime)
{
if (!dateTime.isValid())
{
LogError("AssetCache::SetLastModified() DateTime is invalid: " + assetRef);
return false;
}
QString absolutePath = FindInCache(assetRef);
if (absolutePath.isEmpty())
return false;
QDate date = dateTime.date();
QTime time = dateTime.time();
#ifdef Q_WS_WIN
HANDLE fileHandle = (HANDLE)OpenFileHandle(absolutePath);
if (fileHandle == INVALID_HANDLE_VALUE)
{
LogError("AssetCache: Failed to open cache file to update last modified time: " + assetRef);
return false;
}
// Notes: For SYSTEMTIME Sunday is 0 and ignore msec.
SYSTEMTIME sysTime;
sysTime.wDay = (WORD)date.day();
sysTime.wDayOfWeek = (WORD)date.dayOfWeek();
if (sysTime.wDayOfWeek == 7)
sysTime.wDayOfWeek = 0;
sysTime.wMonth = (WORD)date.month();
sysTime.wYear = (WORD)date.year();
sysTime.wHour = (WORD)time.hour();
sysTime.wMinute = (WORD)time.minute();
sysTime.wSecond = (WORD)time.second();
sysTime.wMilliseconds = 0;
// Set last write time
FILETIME fileTime;
BOOL success = SystemTimeToFileTime(&sysTime, &fileTime);
if (success)
success = SetFileTime(fileHandle, 0, 0, &fileTime);
CloseHandle(fileHandle);
if (!success)
{
LogError("AssetCache: Failed to update cache file last modified time: " + assetRef);
return false;
}
return true;
#else
QString nativePath = QDir::toNativeSeparators(absolutePath);
utimbuf modTime;
modTime.actime = (time_t)(dateTime.toMSecsSinceEpoch() / 1000);
modTime.modtime = (time_t)(dateTime.toMSecsSinceEpoch() / 1000);
if (utime(nativePath.toStdString().c_str(), &modTime) == -1)
{
LogError("AssetCache: Failed to read cache file last modified time: " + assetRef);
return false;
}
else
return true;
#endif
}
示例9: computeRollOverTime
void RollingFileAppender::computeRollOverTime()
{
Q_ASSERT_X(!m_datePatternString.isEmpty(), "DailyRollingFileAppender::computeRollOverTime()", "No active date pattern");
QDateTime now = QDateTime::currentDateTime();
QDate nowDate = now.date();
QTime nowTime = now.time();
QDateTime start;
switch (m_frequency)
{
case MinutelyRollover:
{
start = QDateTime(nowDate, QTime(nowTime.hour(), nowTime.minute(), 0, 0));
m_rollOverTime = start.addSecs(60);
}
break;
case HourlyRollover:
{
start = QDateTime(nowDate, QTime(nowTime.hour(), 0, 0, 0));
m_rollOverTime = start.addSecs(60*60);
}
break;
case HalfDailyRollover:
{
int hour = nowTime.hour();
if (hour >= 12)
hour = 12;
else
hour = 0;
start = QDateTime(nowDate, QTime(hour, 0, 0, 0));
m_rollOverTime = start.addSecs(60*60*12);
}
break;
case DailyRollover:
{
start = QDateTime(nowDate, QTime(0, 0, 0, 0));
m_rollOverTime = start.addDays(1);
}
break;
case WeeklyRollover:
{
// Qt numbers the week days 1..7. The week starts on Monday.
// Change it to being numbered 0..6, starting with Sunday.
int day = nowDate.dayOfWeek();
if (day == Qt::Sunday)
day = 0;
start = QDateTime(nowDate, QTime(0, 0, 0, 0)).addDays(-1 * day);
m_rollOverTime = start.addDays(7);
}
break;
case MonthlyRollover:
{
start = QDateTime(QDate(nowDate.year(), nowDate.month(), 1), QTime(0, 0, 0, 0));
m_rollOverTime = start.addMonths(1);
}
break;
default:
Q_ASSERT_X(false, "DailyRollingFileAppender::computeInterval()", "Invalid datePattern constant");
m_rollOverTime = QDateTime::fromTime_t(0);
}
m_rollOverSuffix = start.toString(m_datePatternString);
Q_ASSERT_X(now.toString(m_datePatternString) == m_rollOverSuffix,
"DailyRollingFileAppender::computeRollOverTime()", "File name changes within interval");
Q_ASSERT_X(m_rollOverSuffix != m_rollOverTime.toString(m_datePatternString),
"DailyRollingFileAppender::computeRollOverTime()", "File name does not change with rollover");
}
示例10: checkTradeDate
QList<int> tradeDateCalendar::computeFrequencyTradeYearly(int date_, int minimumDate_, int maximumDate_)
{
QList<int> tradeDates;
QDate yearDayCounter = QDate::fromJulianDay(minimumDate_);
int dayOfYear = QDate::fromJulianDay(date_).dayOfYear();
forever
{
QDate yearDayComputation = yearDayCounter;
int leapDayofYear = dayOfYear + (dayOfYear > 59 /* Feb 28th */ && QDate::isLeapYear(yearDayComputation.year()) ? 1 : 0);
if (yearDayComputation.dayOfYear() > leapDayofYear)
{
yearDayComputation = yearDayComputation.addYears(1);
leapDayofYear = dayOfYear + (dayOfYear > 59 /* Feb 28th */ && QDate::isLeapYear(yearDayComputation.year()) ? 1 : 0);
}
date_ = checkTradeDate(yearDayComputation.toJulianDay(), direction_ascending);
if (date_ > maximumDate_)
break;
tradeDates.append(date_);
yearDayCounter = yearDayCounter.addYears(1);
}
return tradeDates;
}
示例11: on_calculateButton_clicked
void BestTimesImpl::on_calculateButton_clicked()
{
enum period
{
ALL = 0,
THISMONTH,
THISYEAR,
LASTMONTH,
LASTYEAR
};
timesTable->clearContents();
timesTable->setRowCount(0);
// otherwise the rows move around while they are added
// and we set the item in the wrong place
timesTable->setSortingEnabled(false);
int id = periodBox->currentIndex();
const QString distStr = distanceBox->currentText();
bool ok = false;
const uint distance = distStr.toUInt(&ok);
if (!ok || distance == 0)
{
return;
}
double bestSpeed = std::numeric_limits<double>::max();
const std::vector<Workout>& workouts = ds->Workouts();
for (size_t i = 0; i < workouts.size(); ++i)
{
const Workout & w = workouts[i];
switch(id)
{
case ALL:
break;
case THISMONTH:
{
QDate now = QDate::currentDate();
if (w.date.month() != now.month() ||
w.date.year() != now.year())
continue;
break;
}
case THISYEAR:
{
QDate now = QDate::currentDate();
if (w.date.year() != now.year())
continue;
break;
}
case LASTMONTH:
{
QDate then = QDate::currentDate().addMonths(-1);
if (w.date.month() != then.month() ||
w.date.year() != then.year())
continue;
break;
}
case LASTYEAR:
{
QDate then = QDate::currentDate().addYears(-1);
if (w.date.year() != then.year())
continue;
break;
}
}
if (w.type != "Swim" && w.type != "SwimHR")
{
continue;
}
const int pool = w.pool;
if (pool <= 0)
{
continue;
}
// this is the number of lanes to get above or equal the desired distance
const int numberOfLanes = (distance + pool - 1) / pool; // round up
for (size_t j = 0; j < w.sets.size(); ++j)
{
const Set & set = w.sets[j];
if (set.lens < numberOfLanes)
{
// not enough in this set
continue;
}
//.........这里部分代码省略.........
示例12: setExpirationDate
//! Change the map expiration date
void AdditionalMap::setExpirationDate(QDate date)
{
_data.expirationYear = date.year();
_data.expirationMonth = date.month();
_data.expirationDay = date.day();
}
示例13: listInvoicesToTable
/**
Affiche les factures
@param filter, filtre a appliquer
@param field, champ ou appliquer le filtre
*/
void DialogInvoiceList::listInvoicesToTable(QDate mdate) {
invoice::InvoicesBook ilist;
//Clear les items, attention tjs utiliser la fonction clear()
ui->tableWidget_Invoices->clear();
for (int i=ui->tableWidget_Invoices->rowCount()-1; i >= 0; --i)
ui->tableWidget_Invoices->removeRow(i);
for (int i=ui->tableWidget_Invoices->columnCount()-1; i>=0; --i)
ui->tableWidget_Invoices->removeColumn(i);
ui->tableWidget_Invoices->setSortingEnabled(false);
//Style de la table de facture
ui->tableWidget_Invoices->setColumnCount( COL_COUNT );
ui->tableWidget_Invoices->setColumnWidth( COL_DESCRIPTION, 250 );
#ifdef QT_NO_DEBUG
ui->tableWidget_Invoices->setColumnHidden(COL_ID , true); //cache la colonne ID ou DEBUG
#endif
ui->tableWidget_Invoices->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableWidget_Invoices->setSelectionMode(QAbstractItemView::SingleSelection);
ui->tableWidget_Invoices->setEditTriggers(QAbstractItemView::NoEditTriggers);
QStringList titles;
titles << tr("Id") << tr("sélection") << tr("Date") << tr("Code Facture") << tr("Client") << tr("Description") << tr("Montant") << tr("TTC") << QLatin1String("Règlement");
ui->tableWidget_Invoices->setHorizontalHeaderLabels( titles );
if(!m_data->getIsTax()) {
ui->tableWidget_Invoices->setColumnHidden(COL_PRICE_TAX , true);
}
//Recuperation des donnees presentent dans la bdd
m_invoice->getInvoices(ilist, QString::number(mdate.year()), QString::number(mdate.month()));
// list all customers
QString typeP;
for(int i=0; i<ilist.code.count(); i++){
ItemOfTable *item_ID = new ItemOfTable();
ItemOfTable *item_State = new ItemOfTable();
ItemOfTable *item_DATE = new ItemOfTable();
ItemOfTable *item_CODE = new ItemOfTable();
ItemOfTable *item_CUSTOMER = new ItemOfTable();
ItemOfTable *item_DESCRIPTION = new ItemOfTable();
ItemOfTable *item_PRICE = new ItemOfTable();
ItemOfTable *item_PRICE_TAX = new ItemOfTable();
ItemOfTable *item_TYPE_PAYMENT = new ItemOfTable();
item_ID->setData(Qt::DisplayRole, ilist.id.at(i));
item_State -> setData(Qt::CheckStateRole, Qt::Checked);
item_DATE->setData(Qt::DisplayRole, ilist.userDate.at(i)/*.toString(tr("dd/MM/yyyy"))*/);
item_CODE->setData(Qt::DisplayRole, ilist.code.at(i));
if(ilist.customerFirstName.at(i).isEmpty())
item_CUSTOMER->setData(Qt::DisplayRole, ilist.customerLastName.at(i));
else
item_CUSTOMER->setData(Qt::DisplayRole, ilist.customerFirstName.at(i) +" "+ilist.customerLastName.at(i));
item_DESCRIPTION->setData(Qt::DisplayRole, ilist.description.at(i));
item_PRICE->setData(Qt::DisplayRole, ilist.price.at(i) - ilist.part_payment.at(i));
item_PRICE_TAX->setData(Qt::DisplayRole, ilist.priceTax.at(i) - ilist.part_paymentTax.at(i));
typeP="";
if( ilist.typePayment.at(i) == MCERCLE::CASH) typeP = tr("Espece");
if( ilist.typePayment.at(i) == MCERCLE::CHECK) typeP = tr("Cheque");
if( ilist.typePayment.at(i) == MCERCLE::CREDIT_CARD) typeP = tr("CB");
if( ilist.typePayment.at(i) == MCERCLE::INTERBANK) typeP = tr("TIP");
if( ilist.typePayment.at(i) == MCERCLE::TRANSFER) typeP = tr("Virement");
if( ilist.typePayment.at(i) == MCERCLE::DEBIT) typeP = tr("Prelevement");
if( ilist.typePayment.at(i) == MCERCLE::OTHER) typeP = tr("Autre");
item_TYPE_PAYMENT->setData(Qt::DisplayRole, typeP);
//definir le tableau
ui->tableWidget_Invoices->setRowCount(i+1);
//remplir les champs
ui->tableWidget_Invoices->setItem(i, COL_ID, item_ID);
ui->tableWidget_Invoices->setItem(i, COL_STATE, item_State);
ui->tableWidget_Invoices->setItem(i, COL_DATE, item_DATE);
ui->tableWidget_Invoices->setItem(i, COL_CODE, item_CODE);
ui->tableWidget_Invoices->setItem(i, COL_CUSTOMER, item_CUSTOMER);
ui->tableWidget_Invoices->setItem(i, COL_DESCRIPTION, item_DESCRIPTION);
ui->tableWidget_Invoices->setItem(i, COL_PRICE, item_PRICE);
ui->tableWidget_Invoices->setItem(i, COL_PRICE_TAX, item_PRICE_TAX);
ui->tableWidget_Invoices->setItem(i, COL_TYPE_PAYMENT, item_TYPE_PAYMENT);
}
ui->tableWidget_Invoices->setSortingEnabled(true);
ui->tableWidget_Invoices->selectRow(0);
}
示例14: getTroopId
int CSVOldFormatConverter::getTroopId(
QString troopName, QString graduatedFromMilitaryDepartmentDate,
QString degreeEnrollmentNumber,
QString graduatedFromMilitaryDepartmentInYear) {
// TODO: refactor this stuff
QString enteredAtMilitaryDepartmentDate;
QString troopNamePrefix;
QString troopNamePostfix;
QRegExp shortPostfix = QRegExp("\\d\\d");
QRegExp longPostfix = QRegExp("\\d\\d/\\d\\d");
QRegExp degreeSplitter = QRegExp("№ ?\\d{1,4} ?(от)? ?");
QDate dateEnteredAt;
QDate dateGraduatedFrom;
QString queryString;
QSqlQuery query;
QString formattedTroopName;
int separatorPosition;
int difference;
troopName = troopName.toUpper().simplified();
if (troopName == "АШ32") {
troopName = "АШ-32";
} else if (troopName.isEmpty()) {
qDebug() << graduatedFromMilitaryDepartmentDate << degreeEnrollmentNumber <<
graduatedFromMilitaryDepartmentInYear;
return 0;
}
if (!graduatedFromMilitaryDepartmentDate.simplified().isEmpty()) {
graduatedFromMilitaryDepartmentDate =
graduatedFromMilitaryDepartmentDate.split(" ").at(0);
dateGraduatedFrom = QDate::fromString(graduatedFromMilitaryDepartmentDate,
"dd.MM.yyyy");
} else if (!graduatedFromMilitaryDepartmentInYear.isEmpty()) {
if (graduatedFromMilitaryDepartmentInYear != "0") {
dateGraduatedFrom.setDate(
graduatedFromMilitaryDepartmentInYear.toInt(), 9, 17);
}
}
if (!degreeEnrollmentNumber.isEmpty()) {
enteredAtMilitaryDepartmentDate = degreeEnrollmentNumber
.split(degreeSplitter).last().replace("ю", ".").replace(" ", ".");
if (enteredAtMilitaryDepartmentDate.endsWith("г.")) {
enteredAtMilitaryDepartmentDate.chop(2);
} else if (enteredAtMilitaryDepartmentDate.endsWith("г")) {
enteredAtMilitaryDepartmentDate.chop(1);
} else if (enteredAtMilitaryDepartmentDate.endsWith(".")) {
enteredAtMilitaryDepartmentDate.chop(1);
}
if (enteredAtMilitaryDepartmentDate.split(".").last().length() == 2) {
enteredAtMilitaryDepartmentDate = enteredAtMilitaryDepartmentDate.insert(
enteredAtMilitaryDepartmentDate.length() - 2, "20");
}
dateEnteredAt = QDate::fromString(enteredAtMilitaryDepartmentDate,
"d.MM.yyyy");
}
if (!dateGraduatedFrom.isValid() && !dateEnteredAt.isValid()) {
qDebug() << "invalid dates" << dateEnteredAt << dateGraduatedFrom;
return 0;
} else if (dateGraduatedFrom.isValid()) {
// guessing about entered date
dateEnteredAt.setDate(dateGraduatedFrom.year() - 3, 6, 29);
} else { // if (dateEnteredAt.isValid())
dateGraduatedFrom.setDate(dateEnteredAt.year() + 3, 9, 17);
// qDebug() << "invalid graduation date";
// return 0;
}
int cyear = QDate::currentDate().year();
if (cyear > dateGraduatedFrom.year()) {
cyear = dateGraduatedFrom.year();
}
difference = cyear - dateEnteredAt.year() - 1;
separatorPosition = troopName.indexOf('-');
troopNamePrefix = troopName.left(separatorPosition);
troopNamePostfix = troopName.mid(separatorPosition + 1);
formattedTroopName = troopNamePrefix + "-";
if (shortPostfix.exactMatch(troopNamePostfix)) {
// TODO: make that more cleaner and optimized
formattedTroopName +=
"<N:" +
QString::number(QString(troopNamePostfix.at(0)).toInt() - difference) +
">" + troopNamePostfix.at(1);
} else if (longPostfix.exactMatch(troopNamePostfix)) {
formattedTroopName +=
"<N:" +
QString::number(QString(troopNamePostfix.at(0)).toInt() - difference) +
">" + troopNamePostfix.at(1) + "/" + "<N:" +
QString::number(QString(troopNamePostfix.at(3)).toInt() - difference) +
">" + troopNamePostfix.at(4);
} else {
qDebug() << "asshole" << troopNamePostfix << troopName;
return 0;
}
troopName = formattedTroopName;
queryString = "SELECT id FROM troop WHERE name = ? AND"
" entered_at_military_department_date = ?";
query.prepare(queryString);
query.addBindValue(troopName);
query.addBindValue(dateEnteredAt);
if (!query.exec()) {
qDebug() << query.lastError().text();
return 0;
//.........这里部分代码省略.........
示例15: useStandardRange
void
DateSettingsEdit::setDateSettings()
{
if (active) return;
// first lets disable everything
active = true;
fromDateEdit->setEnabled(false);
toDateEdit->setEnabled(false);
startDateEdit->setEnabled(false);
thisperiod->setEnabled(false);
prevperiod->setEnabled(false);
lastn->setEnabled(false);
lastnx->setEnabled(false);
// the date selection types have changed
if (radioSelected->isChecked()) {
// current selection
emit useStandardRange();
} else if (radioCustom->isChecked()) {
// between x and y
fromDateEdit->setEnabled(true);
toDateEdit->setEnabled(true);
// set date range using custom values
emit useCustomRange(DateRange(fromDateEdit->date(), toDateEdit->date()));
} else if (radioToday->isChecked()) {
// current selected thru to today
emit useThruToday();
} else if (radioLast->isChecked()) {
// last n 'weeks etc'
lastn->setEnabled(true);
lastnx->setEnabled(true);
QDate from;
QDate today = QDate::currentDate();
// calculate range up to today...
switch(lastnx->currentIndex()) {
case 0 : // days
from = today.addDays(lastn->value() * -1);
break;
case 1 : // weeks
from = today.addDays(lastn->value() * -7);
break;
case 2 : // months
from = today.addMonths(lastn->value() * -1);
break;
case 3 : // years
from = today.addYears(lastn->value() * -1);
break;
}
emit useCustomRange(DateRange(from, today));
} else if (radioFrom->isChecked()) {
// from date - today
startDateEdit->setEnabled(true);
emit useCustomRange(DateRange(startDateEdit->date(), QDate::currentDate()));
} else if (radioThis->isChecked()) {
thisperiod->setEnabled(true);
prevperiod->setEnabled(true);
QDate today = QDate::currentDate();
QDate from, to;
switch(thisperiod->currentIndex()) {
case 0 : // weeks
{
int dow = today.dayOfWeek(); // 1-7, where 1=monday
from = today.addDays(-1 * (dow-1));
to = from.addDays(6);
// prevperiods
from = from.addDays(prevperiod->value() * -7);
to = to.addDays(prevperiod->value() * -7);
}
break;
case 1 : // months
from = QDate(today.year(), today.month(), 1);
to = from.addMonths(1).addDays(-1);
from = from.addMonths(prevperiod->value() * -1);
to = to.addMonths(prevperiod->value() * -1);
break;
case 2 : // years
//.........这里部分代码省略.........