本文整理汇总了C++中QDateTime::addMonths方法的典型用法代码示例。如果您正苦于以下问题:C++ QDateTime::addMonths方法的具体用法?C++ QDateTime::addMonths怎么用?C++ QDateTime::addMonths使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDateTime
的用法示例。
在下文中一共展示了QDateTime::addMonths方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: 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));
}
示例3: 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;
}
}
示例4: resetBeforeChange
void QgsDateTimeEdit::resetBeforeChange( int delta )
{
QDateTime dt = QDateTime::currentDateTime();
switch ( currentSection() )
{
case QDateTimeEdit::DaySection:
dt = dt.addDays( delta );
break;
case QDateTimeEdit::MonthSection:
dt = dt.addMonths( delta );
break;
case QDateTimeEdit::YearSection:
dt = dt.addYears( delta );
break;
default:
break;
}
if ( dt < minimumDateTime() )
{
dt = minimumDateTime();
}
else if ( dt > maximumDateTime() )
{
dt = maximumDateTime();
}
QDateTimeEdit::setDateTime( dt );
}
示例5: 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;
}
}
示例6: 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;
}
示例7: connect
void
NetworkActivityWidget::fetchMonthCharts()
{
QDateTime to = QDateTime::currentDateTime();
QDateTime monthAgo = to.addMonths( -1 );
DatabaseCommand_NetworkCharts* monthCharts = new DatabaseCommand_NetworkCharts( monthAgo, to );
monthCharts->setLimit( numberOfNetworkChartEntries );
connect( monthCharts, SIGNAL( done( QList<Tomahawk::track_ptr> ) ), SLOT( monthlyCharts( QList<Tomahawk::track_ptr> ) ) );
Database::instance()->enqueue( Tomahawk::dbcmd_ptr( monthCharts ) );
}
示例8: New
int Indications::New(int id_pok_old, QString value_home)
{
int id_new = -1;
int date_old = -1, id_ListApart=-1;
QString str;
QStringList column, value;
QSqlQuery query;
// найдём дату текущих показаний
str = "SELECT date_pokazanie, id_list_app_usluga FROM pokazanie WHERE id_pokazanie=%1";
str = str.arg(id_pok_old);
if (query.exec(str)){
if (query.next()){
date_old = query.value(0).toInt();
id_ListApart = query.value(1).toInt();
}else{
qDebug() << "not record" << "575af8aa8da14fec062ce2bc5ef9e1e8 " << str;
}
} else{
qDebug()<<query.lastError();
}
QDateTime time;
time = time.fromTime_t(date_old);
time = time.addMonths(1);
DateOfUnixFormat date(time.date());
//Проверим на существование показаний на след месяц
str = "SELECT id_pokazanie FROM pokazanie "
"WHERE date_pokazanie=%1 AND id_list_app_usluga=%2";
str = str.arg(date.Second())
.arg(QString::number(id_ListApart));
QString id_pok_var;
BD::SelectFromTable(str,&id_pok_var);
if(id_pok_var == ""){//если нет записей
//добавим новое показание на след месяц
column.clear();
column<<"id_list_app_usluga"<<"date_pokazanie"<<"pokazanie_home"<<"pokazanie_end";
value.append(QString::number(id_ListApart));
value.append(QString::number(date.Second()));
value.append(value_home);
value.append(QString::number(0));
if (BD::add("pokazanie",column,value).number() != 0){
return -1;
}
}else{//иначе
//Обновим запись
BD::UpdateTable("pokazanie","pokazanie_home",value_home,"id_pokazanie",id_pok_var);
return id_pok_var.toInt();
}
return id_new;
}
示例9: snoozeClicked
void AlarmView::snoozeClicked()
{
mAlarmTimer.stop();
/* Snooze for some amount of time (configured in settings, say) */
int snoozeindex = mSnoozeChoices->currentIndex();
int snoozedelay = 60;
// Make sure we set alarms on the minute by rounding
QDateTime now = QDateTime::currentDateTime();
int seconds = now.time().second();
if (seconds >= 30)
now = now.addSecs(60 - seconds);
else
now = now.addSecs(-seconds);
switch(snoozeindex) {
case 0: // 5 minutes
snoozedelay = 300;
break;
case 1: // 10 minutes
snoozedelay = 600;
break;
case 2: // 15 minutes
snoozedelay = 900;
break;
case 3: // 30 minutes
snoozedelay = 1800;
break;
case 4: // 1 hour
snoozedelay = 3600;
break;
case 5: // 1 day
snoozedelay = 24 * 60;
break;
case 6: // 1 week
snoozedelay = 7 * 24 * 60;
break;
case 7: // 1 month hmm
{
QDateTime then = now.addMonths(1);
snoozedelay = now.secsTo(then);
}
break;
}
QDateTime snoozeTime = now.addSecs(snoozedelay);
Qtopia::addAlarm(snoozeTime, "Calendar", "alarm(QDateTime,int)", snoozeTime.secsTo(mStartTime) / 60);
emit closeView();
}
示例10: paintMonthScaleHeader
/*! Paints the month scale header.
* \sa paintHeader()
*/
void DateTimeGrid::paintMonthScaleHeader( QPainter* painter, const QRectF& headerRect, const QRectF& exposedRect,
qreal offset, QWidget* widget )
{
QStyle* style = widget?widget->style():QApplication::style();
// Paint a section for each month
QDateTime sdt = d->chartXtoDateTime( offset+exposedRect.left() );
sdt.setTime( QTime( 0, 0, 0, 0 ) );
sdt = sdt.addDays( 1 - sdt.date().day() );
QDateTime dt = sdt;
for ( qreal x = d->dateTimeToChartX( dt ); x < exposedRect.right()+offset;
dt = dt.addMonths( 1 ),x=d->dateTimeToChartX( dt ) ) {
QStyleOptionHeader opt;
opt.init( widget );
opt.rect = QRectF( x-offset, headerRect.top()+headerRect.height()/2., dayWidth()*dt.date().daysInMonth(), headerRect.height()/2. ).toRect();
opt.text = QDate::shortMonthName( 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 );
}
}
// Paint a section for each year
dt = sdt;
for ( qreal x2 = d->dateTimeToChartX( dt ); x2 < exposedRect.right()+offset; x2=d->dateTimeToChartX( dt ) ) {
//qDebug()<<"paintMonthScaleHeader()"<<dt;
QDate next = dt.date().addYears( 1 );
next = next.addMonths( 1 - next.month() );
QStyleOptionHeader opt;
opt.init( widget );
opt.rect = QRectF( x2-offset, headerRect.top(), dayWidth()*dt.date().daysTo( next ), headerRect.height()/2. ).toRect();
opt.text = QString::number( dt.date().year() );
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 );
}
}
示例11: OnBulkMonth
void CDlgBulkRegister::OnBulkMonth( int nMonth )
{
QDateTimeEdit* pDt = NULL;
QDateTime dtStart;
for ( int nRow = 0; nRow < ui->tabRecord->rowCount( ); nRow++ ) {
pDt = ( QDateTimeEdit* ) ui->tabRecord->cellWidget( nRow, 5 );
dtStart = pDt->dateTime( );
pDt = ( QDateTimeEdit* ) ui->tabRecord->cellWidget( nRow, 6 );
dtStart = dtStart.addMonths( nMonth );
//qDebug( ) << dtStart.toString( ) << endl;
pDt->setDateTime( dtStart );
}
}
示例12: onValueChanged
void DateTimePickerRecipe::onValueChanged(QDateTime value)
{
QDateTime today = QDateTime::currentDateTime();
// We compare the date that is set on the Picker to the current date and set different
// images depending on how far in the future (or past) that date is.
if (value < today.addDays(-1)) {
mTimeWarpFruit->setImageSource(QUrl("asset:///images/picker/banana_past.png"));
} else if (value >= today.addDays(-1) && value <= today.addDays(3)) {
mTimeWarpFruit->setImageSource(QUrl("asset:///images/picker/banana_new.png"));
} else if ( value < today.addMonths(1) ) {
mTimeWarpFruit->setImageSource(QUrl("asset:///images/picker/banana_old.png"));
} else {
mTimeWarpFruit->setImageSource(QUrl("asset:///images/picker/banana_ancient.png"));
}
}
示例13: AddMonthRow
void CDlgBulkRegister::AddMonthRow( const QString &strCardID )
{
ui->tabRecord->insertRow( 0 );
QDateTime dt = QDateTime::currentDateTime( );
QString strText;
for ( int nIndex = 0; nIndex < ui->tabRecord->columnCount( ); nIndex++ ) {
switch ( nIndex ) {
case 0 :
AddItem( strCardID, 0, nIndex, ui->tabRecord );
break;
case 1 :
case 2 :
case 3 :
AddCheckBoxItem( 0, nIndex, ui->tabRecord );
break;
case 4 :
case 7 :
AddComboBoxItem( 0, nIndex, 0, ( 7 == nIndex ), ui->tabRecord );
break;
case 5 :
case 6 :
if ( 6 == nIndex ) {
dt = dt.addMonths( nBulkEndMonth );
}
AddDateTimeItem( 0, nIndex, dt, ui->tabRecord );
break;
case 8 :
GetSelfNumber( strText );
AddItem( strText, 0, nIndex, ui->tabRecord );
break;
case 9 :
strText = "未知";
AddItem( strText, 0, nIndex, ui->tabRecord );
break;
case 10 :
AddItem( strCreator, 0, nIndex, ui->tabRecord );
break;
}
}
}
示例14: setDiff
void Validity::setDiff(const Validity *start, int number, int range)
{
QDateTime dt = start->dateTime();
switch (range) {
case 0: dt = dt.addDays(number); break;
case 1: dt = dt.addMonths(number); break;
case 2: dt = dt.addYears(number); break;
}
// one day less if we go from 0:00:00 to 23:59:59
if (midnight)
dt = dt.addDays(-1);
setDateTime(dt);
mytime = start->mytime;
}
示例15: purgeStuff
void databaseMain::purgeStuff() {
QSqlQuery databaseEntry;
QDateTime dateTime;
dateTime = dateTime.currentDateTime();
if(purgeUnits == "Minutes")
{
dateTime = dateTime.addSecs(-purgeNum*60);
}
if(purgeUnits == "Hours")
{
dateTime = dateTime.addSecs(-purgeNum*3600);
}
if(purgeUnits == "Days")
{
dateTime = dateTime.addDays(-purgeNum);
}
if(purgeUnits == "Months")
{
dateTime = dateTime.addMonths(-purgeNum);
}
if(purgeUnits == "Years")
{
dateTime = dateTime.addYears(-purgeNum);
}
QString testString = dateTime.toString();
//qDebug() << "Purgetime!!!!!!!" << testString;
databaseEntry.exec("SELECT Timestamp FROM packets");
while(databaseEntry.next()){
if(databaseEntry.value(0).toString() < testString)
{
qDebug() << "DatabaseTimeStamp: " << databaseEntry.value(0).toString();
databaseEntry.prepare("DELETE FROM packets WHERE Timestamp = :Time");
databaseEntry.bindValue(":Time",databaseEntry.value(0).toString());
qDebug() << dataBase.lastError() << "---------------";
databaseEntry.exec();
qDebug() << databaseEntry.lastError() << "---------------";
}
}
}