本文整理汇总了C++中QDateTime::addDays方法的典型用法代码示例。如果您正苦于以下问题:C++ QDateTime::addDays方法的具体用法?C++ QDateTime::addDays怎么用?C++ QDateTime::addDays使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDateTime
的用法示例。
在下文中一共展示了QDateTime::addDays方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
void
DiaryWindow::nextClicked()
{
#if 0
switch (viewMode->currentIndex()) {
case 0 : // monthly
{
#endif
int month = calendarModel->getMonth();
int year = calendarModel->getYear();
QDate when = QDate(year, month, 1).addMonths(1);
calendarModel->setMonth(when.month(), when.year());
title->setText(QString("%1 %2").arg(QDate::longMonthName(when.month())).arg(when.year()));
#if 0
}
break;
case 1 : // weekly
{
QDateTime when = weeklyView->getStartTime();
when = when.addDays(7);
weeklyView->setDateRange(when.date(), when.addDays(6).date());
weeklyView->setViewMode(QxtScheduleView::DayView);
title->setText(QString("Week %1 %2").arg(when.date().weekNumber()).arg(when.date().year()));
}
break;
}
#endif
}
示例2: paintMonthGrid
void DateTimeGrid::paintMonthGrid( QPainter* painter,
const QRectF& /*sceneRect*/,
const QRectF& exposedRect,
AbstractRowController* /*rowController*/,
QWidget* widget )
{
//qDebug()<<"paintMonthGrid()"<<scale()<<dayWidth();
QDateTime dt = d->chartXtoDateTime( exposedRect.left() );
dt.setTime( QTime( 0, 0, 0, 0 ) );
dt = dt.addDays( 1 - dt.date().day() );
for ( qreal x = d->dateTimeToChartX( dt ); x < exposedRect.right(); dt = dt.addDays( 1 ),x=d->dateTimeToChartX( dt ) ) {
QPen pen = painter->pen();
pen.setBrush( QApplication::palette().dark() );
if ( dt.date().addMonths( 1 ).month() == 1 && dt.date().addDays( 1 ).day() == 1 ) {
pen.setStyle( Qt::SolidLine );
} else if ( dt.date().addDays( 1 ).day() == 1 ) {
pen.setStyle( Qt::DashLine );
} else {
pen.setStyle( Qt::NoPen );
}
painter->setPen( pen );
paintFreeDay( painter, x, exposedRect, dt.date(), widget );
if ( pen.style() != Qt::NoPen ) {
//qDebug()<<"paintMonthGrid()"<<dt;
x += dayWidth() - 1;
painter->drawLine( QPointF( x, exposedRect.top() ), QPointF( x, exposedRect.bottom() ) );
}
}
}
示例3: computeFrequency
void RollingFileAppender::computeFrequency()
{
QMutexLocker locker(&m_rollingMutex);
const QDateTime startTime(QDate(1999, 1, 1), QTime(0, 0));
const QString startString = startTime.toString(m_datePatternString);
if (startString != startTime.addSecs(60).toString(m_datePatternString))
m_frequency = MinutelyRollover;
else if (startString != startTime.addSecs(60 * 60).toString(m_datePatternString))
m_frequency = HourlyRollover;
else if (startString != startTime.addSecs(60 * 60 * 12).toString(m_datePatternString))
m_frequency = HalfDailyRollover;
else if (startString != startTime.addDays(1).toString(m_datePatternString))
m_frequency = DailyRollover;
else if (startString != startTime.addDays(7).toString(m_datePatternString))
m_frequency = WeeklyRollover;
else if (startString != startTime.addMonths(1).toString(m_datePatternString))
m_frequency = MonthlyRollover;
else
{
Q_ASSERT_X(false, "DailyRollingFileAppender::computeFrequency", "The pattern '%1' does not specify a frequency");
return;
}
}
示例4: flushLogs
void HouseKeeper::flushLogs()
{
int numdays = gCoreContext->GetNumSetting("LogCleanDays", 14);
int maxdays = gCoreContext->GetNumSetting("LogCleanMax", 30);
QDateTime days = QDateTime::currentDateTime();
days = days.addDays(0 - numdays);
QDateTime max = QDateTime::currentDateTime();
max = max.addDays(0 - maxdays);
MSqlQuery result(MSqlQuery::InitCon());
if (result.isConnected())
{
result.prepare("DELETE FROM mythlog WHERE "
"acknowledged=1 and logdate < :DAYS ;");
result.bindValue(":DAYS", days);
if (!result.exec())
MythDB::DBError("HouseKeeper::flushLogs -- delete acknowledged",
result);
result.prepare("DELETE FROM mythlog WHERE logdate< :MAX ;");
result.bindValue(":MAX", max);
if (!result.exec())
MythDB::DBError("HouseKeeper::flushLogs -- delete old",
result);
}
}
示例5: getOccurrences
QStringList EventModel::getOccurrences(int range, QDate dateFrom)const
{
int securityCounter = 1000;
QStringList result;
QDateTime tmpDateTime = dateTime;
do
{
if ((tmpDateTime.date().daysTo(QDate::currentDate()) <=0) && (QDate::currentDate().daysTo(tmpDateTime.date()) <= range ))
result.push_back(tmpDateTime.toString(dateTimeFormatString));
switch(repeatPeriod)
{
case(1):
tmpDateTime = tmpDateTime.addDays(repeatEvery);
break;
case(7):
tmpDateTime = tmpDateTime.addDays(repeatEvery*7);
break;
case(30):
tmpDateTime = tmpDateTime.addMonths(repeatEvery);
break;
case(0):
default:
break;
}
securityCounter--;
} while ((securityCounter > 0) && (QDate::currentDate().daysTo(tmpDateTime.date()) <= range ) && (repeatPeriod!=0) );
return result;
}
示例6: addWallClockIntervalOptimized
/**
* @brief TTiming::addWallClockIntervalOptimized skips to long distances
* @param actual
* @param calculated
* @return
*/
QDateTime TTiming::addWallClockIntervalOptimized(QDateTime actual, QDateTime calculated)
{
if (wall_clock.period.years == 0)
calculated = calculated.addYears(actual.date().year()-calculated.date().year()); // should give 0 on iterations
else
calculated = calculated.addYears(wall_clock.period.years);
if (wall_clock.period.months == 0)
calculated = calculated.addMonths(actual.date().month()-calculated.date().month());
else
calculated = calculated.addMonths(wall_clock.period.months);
if (wall_clock.period.days == 0)
calculated = calculated.addDays(actual.date().day()-calculated.date().day());
else
calculated = calculated.addDays(wall_clock.period.days);
if (wall_clock.period.hours == 0)
calculated = calculated.addSecs((actual.time().hour()-calculated.time().hour())*3600);
else
calculated = calculated.addSecs(wall_clock.period.hours*3600);
if (wall_clock.period.minutes == 0)
calculated = calculated.addSecs((actual.time().minute()-calculated.time().minute())*60);
else
calculated = calculated.addSecs(wall_clock.period.minutes*60);
return calculated.addSecs(wall_clock.period.seconds);
}
示例7: metaData
virtual QNetworkCacheMetaData metaData(const QUrl &url)
{
QNetworkCacheMetaData metaData;
if (!cachedData.isEmpty()) {
metaData.setUrl(url);
QDateTime now = QDateTime::currentDateTime();
metaData.setLastModified(now.addDays(-1));
metaData.setExpirationDate(now.addDays(1));
metaData.setSaveToDisk(true);
}
return metaData;
}
示例8: paintWeekScaleHeader
/*! Paints the week scale header.
* \sa paintHeader()
*/
void DateTimeGrid::paintWeekScaleHeader( QPainter* painter, const QRectF& headerRect, const QRectF& exposedRect,
qreal offset, QWidget* widget )
{
QStyle* style = widget?widget->style():QApplication::style();
// Paint a section for each week
QDateTime sdt = d->chartXtoDateTime( offset+exposedRect.left() );
sdt.setTime( QTime( 0, 0, 0, 0 ) );
// Go backwards until start of week
while ( sdt.date().dayOfWeek() != d->weekStart ) sdt = sdt.addDays( -1 );
QDateTime dt = sdt;
for ( qreal x = d->dateTimeToChartX( dt ); x < exposedRect.right()+offset;
dt = dt.addDays( 7 ),x=d->dateTimeToChartX( dt ) ) {
QStyleOptionHeader opt;
opt.init( widget );
opt.rect = QRectF( x-offset, headerRect.top()+headerRect.height()/2., dayWidth()*7, headerRect.height()/2. ).toRect();
opt.text = QString::number( dt.date().weekNumber() );
opt.textAlignment = Qt::AlignCenter;
// NOTE:CE_Header does not honor clipRegion(), so we do the CE_Header logic here
style->drawControl( QStyle::CE_HeaderSection, &opt, painter, widget );
QStyleOptionHeader subopt = opt;
subopt.rect = style->subElementRect( QStyle::SE_HeaderLabel, &opt, widget );
if ( subopt.rect.isValid() ) {
style->drawControl( QStyle::CE_HeaderLabel, &subopt, painter, widget );
}
}
// Paint a section for each month
dt = sdt;
for ( qreal x2 = d->dateTimeToChartX( dt ); x2 < exposedRect.right()+offset; x2=d->dateTimeToChartX( dt ) ) {
//qDebug()<<"paintWeekScaleHeader()"<<dt;
QDate next = dt.date().addMonths( 1 );
next = next.addDays( 1 - next.day() );
QStyleOptionHeader opt;
opt.init( widget );
opt.rect = QRectF( x2-offset, headerRect.top(), dayWidth()*dt.date().daysTo( next ), headerRect.height()/2. ).toRect();
opt.text = QDate::longMonthName( dt.date().month() );
opt.textAlignment = Qt::AlignCenter;
// NOTE:CE_Header does not honor clipRegion(), so we do the CE_Header logic here
style->drawControl( QStyle::CE_HeaderSection, &opt, painter, widget );
QStyleOptionHeader subopt = opt;
subopt.rect = style->subElementRect( QStyle::SE_HeaderLabel, &opt, widget );
if ( subopt.rect.isValid() ) {
style->drawControl( QStyle::CE_HeaderLabel, &subopt, painter, widget );
}
dt.setDate( next );
}
}
示例9: timeUntilTomorrow
qint64 timeUntilTomorrow()
{
QDateTime now = QDateTime::currentDateTime();
QDateTime tomorrow = now.addDays(1); // Tomorrow.
tomorrow.setTime(QTime()); // Midnight.
return now.msecsTo(tomorrow);
}
示例10: shouldHaveCorrectStartEndDateTime
void EventEditTest::shouldHaveCorrectStartEndDateTime()
{
MessageViewer::EventEdit edit;
KMime::Message::Ptr msg(new KMime::Message);
QString subject = QStringLiteral("Test Note");
msg->subject(true)->fromUnicodeString(subject, "us-ascii");
edit.setMessage(msg);
QDateTime currentDateTime = QDateTime::currentDateTime();
MessageViewer::EventDateTimeWidget *startDateTime = edit.findChild<MessageViewer::EventDateTimeWidget *>(QStringLiteral("startdatetimeedit"));
startDateTime->setDateTime(currentDateTime);
QDateTime endDt = currentDateTime.addDays(1);
MessageViewer::EventDateTimeWidget *endDateTime = edit.findChild<MessageViewer::EventDateTimeWidget *>(QStringLiteral("enddatetimeedit"));
endDateTime->setDateTime(endDt);
QLineEdit *noteedit = edit.findChild<QLineEdit *>(QStringLiteral("eventedit"));
QVERIFY(noteedit);
QSignalSpy spy(&edit, SIGNAL(createEvent(KCalCore::Event::Ptr,Akonadi::Collection)));
QTest::keyClick(noteedit, Qt::Key_Enter);
QCOMPARE(spy.count(), 1);
KCalCore::Event::Ptr eventPtr = spy.at(0).at(0).value<KCalCore::Event::Ptr>();
QVERIFY(eventPtr);
QCOMPARE(eventPtr->dtStart().date(), currentDateTime.date());
QCOMPARE(eventPtr->dtStart().time().hour(), currentDateTime.time().hour());
QCOMPARE(eventPtr->dtStart().time().minute(), currentDateTime.time().minute());
QCOMPARE(eventPtr->dtEnd().date(), endDt.date());
QCOMPARE(eventPtr->dtEnd().time().hour(), endDt.time().hour());
QCOMPARE(eventPtr->dtEnd().time().minute(), endDt.time().minute());
}
示例11: on_buttonBox_accepted
void interplanetaryDialog::on_buttonBox_accepted()
{
// Create a new scenario
SpaceScenario* scenario = new SpaceScenario();
scenario->setName("This is a demo");
ScenarioSC* sc = new ScenarioSC();
sc->setName("my satellite demo");
sc->ElementIdentifier()->setName("my satellite demo");
// Create the initial position (Keplerian elements)
ScenarioKeplerianElementsType* elements = new ScenarioKeplerianElementsType();
elements->setSemiMajorAxis(87000.0);
elements->setEccentricity(0.0045);
elements->setInclination(27.456);
elements->setRAAN(132.34);
elements->setArgumentOfPeriapsis(231.34);
elements->setTrueAnomaly(45.32);
// Create the initial attitude (Euler elements)
ScenarioEulerType* initAtt = new ScenarioEulerType();
initAtt->setPhi(0.00000);
initAtt->setTheta(0.00000);
initAtt->setPsi(0.00000);
initAtt->setPhiDot(0.00000);
initAtt->setThetaDot(0.00000);
initAtt->setPsiDot(0.00000);
// Create the trajectory arc
ScenarioLoiteringType* loitering = new ScenarioLoiteringType();
loitering->ElementIdentifier()->setName("loitering");
loitering->ElementIdentifier()->setColorName("Yellow");
loitering->Environment()->CentralBody()->setName("Earth");
loitering->InitialPosition()->setCoordinateSystem("INERTIAL J2000");
loitering->PropagationPosition()->setTimeStep(60.0);
loitering->PropagationPosition()->setPropagator("TWO BODY");
loitering->PropagationPosition()->setIntegrator("RK4");
loitering->InitialAttitude()->setCoordinateSystem("EULER 123");
loitering->PropagationAttitude()->setIntegrator(""); // Not defined in STA yet
loitering->PropagationAttitude()->setTimeStep(60.0);
// Time-line
QDateTime TheCurrentDateAndTime = QDateTime::currentDateTime(); // Get the current epoch
loitering->TimeLine()->setStartTime(TheCurrentDateAndTime);
loitering->TimeLine()->setEndTime(TheCurrentDateAndTime.addDays(1));
loitering->TimeLine()->setStepTime(60.0);
loitering->InitialPosition()->setAbstract6DOFPosition(QSharedPointer<ScenarioAbstract6DOFPositionType>(elements));
//loitering->InitialAttitude()->setAbstract6DOFAttitude(initAtt);
loitering->InitialAttitude()->setAbstract6DOFAttitude(QSharedPointer<ScenarioAbstract6DOFAttitudeType>(initAtt));
// Create the spacecraft
sc->SCMission()->TrajectoryPlan()->AbstractTrajectory().append(QSharedPointer<ScenarioAbstractTrajectoryType>(loitering));
// Add it to the scenario
scenario->AbstractParticipant().append(QSharedPointer<ScenarioParticipantType>(sc));
mainwindow->setScenario(scenario);
return;
}
示例12: QStringLiteral
static inline QString jobHoldToString(const QCUPSSupport::JobHoldUntil jobHold, const QTime holdUntilTime)
{
switch (jobHold) {
case QCUPSSupport::Indefinite:
return QStringLiteral("indefinite");
case QCUPSSupport::DayTime:
return QStringLiteral("day-time");
case QCUPSSupport::Night:
return QStringLiteral("night");
case QCUPSSupport::SecondShift:
return QStringLiteral("second-shift");
case QCUPSSupport::ThirdShift:
return QStringLiteral("third-shift");
case QCUPSSupport::Weekend:
return QStringLiteral("weekend");
case QCUPSSupport::SpecificTime:
if (!holdUntilTime.isNull()) {
// CUPS expects the time in UTC, user has entered in local time, so get the UTS equivalent
QDateTime localDateTime = QDateTime::currentDateTime();
// Check if time is for tomorrow in case of DST change overnight
if (holdUntilTime < localDateTime.time())
localDateTime = localDateTime.addDays(1);
localDateTime.setTime(holdUntilTime);
return localDateTime.toUTC().time().toString(QStringLiteral("HH:mm"));
}
// else fall through:
case QCUPSSupport::NoHold:
return QString();
}
Q_UNREACHABLE();
return QString();
}
示例13: addWallClockInterval
QDateTime TTiming::addWallClockInterval(QDateTime calculated)
{
calculated = calculated.addYears(wall_clock.period.years);
calculated = calculated.addMonths(wall_clock.period.months);
calculated = calculated.addDays(wall_clock.period.days);
return calculated.addSecs((wall_clock.period.hours*3600) + (wall_clock.period.minutes*60) + (wall_clock.period.seconds));
}
示例14: update
void DateVariable::update()
{
QDateTime target;
switch (m_type) {
case Fixed:
target = m_time;
break;
case AutoUpdate:
target = QDateTime::currentDateTime();
break;
}
target = target.addSecs(m_secsOffset);
target = target.addDays(m_daysOffset);
target = target.addMonths(m_monthsOffset);
target = target.addYears(m_yearsOffset);
switch (m_displayType) {
case Custom:
setValue(target.toString(m_definition));
break;
case Time:
setValue(target.time().toString(Qt::LocalDate));
break;
case Date:
setValue(target.date().toString(Qt::LocalDate));
break;
}
}
示例15: calculate_next_periodic_timeout
void plugin::calculate_next_periodic_timeout(const plugin::EventTimeStructure& ts) {
QDateTime t;
QDateTime datetime = QDateTime::currentDateTime();
datetime.setTime ( ts.time );
int dow = QDate::currentDate().dayOfWeek() - 1;
int offsetdays = 0;
// If it is too late for the alarm today then
// try with the next weekday
if ( QTime::currentTime() > ts.time ) {
dow = ( dow+1 ) % 7;
++offsetdays;
}
// Search for the next activated weekday
for ( ; offsetdays < 8; ++offsetdays ) {
if ( ts.days.testBit(dow) ) break;
dow = ( dow+1 ) % 7;
}
if ( offsetdays < 8 ) {
addToEvents(datetime.addDays ( offsetdays ), ts);
}
}