本文整理汇总了C++中QDate::addDays方法的典型用法代码示例。如果您正苦于以下问题:C++ QDate::addDays方法的具体用法?C++ QDate::addDays怎么用?C++ QDate::addDays使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDate
的用法示例。
在下文中一共展示了QDate::addDays方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fromTime_t
// Use this replacement for QDateTime::setTime_t(uint) since our time
// values are signed.
static QDateTime fromTime_t(qint32 seconds)
{
static const QDate epochDate(1970,1,1);
static const QTime epochTime(0,0,0);
int days = seconds / 86400;
seconds -= days * 86400;
if (seconds < 0)
{
--days;
seconds += 86400;
}
return QDateTime(epochDate.addDays(days), epochTime.addSecs(seconds), Qt::UTC);
}
示例2: getRayTime
QDateTime Dorade::getRayTime(int& ray)
{
int year = vptr->year;
int jd = ryptr[ray].julian_day;
QDate date = QDate(year,1,1);
date = date.addDays(jd-1);
int hour = ryptr[ray].hour;
int min = ryptr[ray].min;
int sec = ryptr[ray].sec;
int msec = ryptr[ray].msec;
QTime time = QTime(hour, min, sec, msec);
return QDateTime(date, time, Qt::UTC);
}
示例3:
QVector<Event> EventPool::eventsByWeek( const QDate date )
{
QDate firstOfRange = date;
// @fixme: explicit week start
firstOfRange = firstOfRange.addDays( 1 - firstOfRange.dayOfWeek() );
QDate lastOfRange = firstOfRange.addDays( 6 );
QVector<Event> events = m_eventMap.value( date.year() );
// load other years, if we overlap a year-boundary
if( firstOfRange.year() < date.year() )
events.append( m_eventMap.value( firstOfRange.year() ) );
if( lastOfRange.year() > date.year() )
events.append( m_eventMap.value( lastOfRange.year() ) );
QVector<Event> eventsWeeks;
for( const Event e : events )
{
if( e.m_endDt.date() >= firstOfRange and e.m_startDt.date() <= lastOfRange )
eventsWeeks.append( e );
}
return eventsWeeks;
}
示例4: buildGui
void NYBOT::buildGui ()
{
setCaption(tr("NYBOT Quotes"));
QLabel *label = new QLabel(tr("Date"), baseWidget);
grid->addWidget(label, 0, 0);
date = new QDateEdit(QDate::currentDate(), baseWidget);
date->setAutoAdvance(TRUE);
date->setOrder(QDateEdit::YMD);
grid->addWidget(date, 0, 1);
QDate dt = QDate::currentDate();
if (dt.dayOfWeek() == 6)
dt = dt.addDays(-1);
else
{
if (dt.dayOfWeek() == 7)
dt = dt.addDays(-2);
}
date->setDate(dt);
}
示例5: updateEvents
void ComingUpViewItemModel::updateEvents()
{
modelEventList->clear();
theData.clear();
QList<CalendarEvent*>& eventList = viewManager.GetEvents();
//int eventsLimitedTo = 3, comingUpEventCnt=0;
int cntr = eventList.count();
QDate today = QDate::currentDate();
KDateTime daysLaterDate = KDateTime(today.addDays(7));
for ( int i=0;i<cntr;i++ ) {
CalendarEvent* event = eventList.at(i);
bool addEvent = false;
//Bug#7244 Author: [email protected]
//Fixed the issue with display of "coming up" "Later" event list
if ( restrictEventCount == true ) {
if ( today == event->StartDate().date() )
{
addEvent = true;
}
} else {
if(event->StartDate().date() > daysLaterDate.date()) {
break;
} else if ( event->StartDate().date() > today )
{
addEvent = true;
}
}
if ( addEvent ) {
modelEventList->append(event);
QString dateString;
//Bug#7320 Author: [email protected]
//This piece of code fixes the issue with display of event
//If today: Display time followed by event
//Else Display Date-time followed by event
if(today == event->StartDate().date()) {
dateString = event->StartDate().toString ( "hh:mm AP" );
} else {
dateString = event->StartDate().toString ( "ddd dd hh:mm AP" );
}
QString alarmsString("alarmOFF");
if ( event->Alarm() ) {
alarmsString = "alarmON";
}
theData.append( QStringList() << dateString << event->Description() << alarmsString );
}
}
}
示例6: parseEntry
bool RuleSet::parseEntry(RULE &ret, QString s, int year) {
if(s.contains(QRegExp("^[0-9]+/[0-9]+$"))) {
int d, m;
sscanf(s.toAscii(), "%d/%d", &m, &d);
ret.type = 1;
ret.date.from = QDate(year, m, d);
ret.date.until = QDate(year, m, d);
return true;
}
if(s.contains(QRegExp("^[0-9]+\\.[0-9]+$"))) {
int d, m;
sscanf(s.toAscii(), "%d.%d", &d, &m);
ret.type = 1;
ret.date.from = QDate(year, m, d);
ret.date.until = QDate(year, m, d);
return true;
}
if(s.right(3) == "day") {
int d = dayNameToInt(s.toAscii());
if(d != -1) {
ret.type = 2;
ret.weekday.from = d;
ret.weekday.until = d;
return true;
}
}
if(s.left(6) == "easter") {
QDate d = get_easter(year);
int off;
bool ok = true;
QString val = s.mid(6, 1000);
if(val.isEmpty())
off = 0;
else
off = val.toInt(&ok);
if(ok) {
d = d.addDays(off);
ret.type = 1;
ret.date.from = d;
ret.date.until = d;
return true;
}
}
ret.type = 0;
return false;
}
示例7: chooseDate
void TransactionView::chooseDate(int idx)
{
if (!transactionProxyModel)
return;
QDate current = QDate::currentDate();
dateRangeWidget->setVisible(false);
switch (dateWidget->itemData(idx).toInt()) {
case All:
transactionProxyModel->setDateRange(
TransactionFilterProxy::MIN_DATE,
TransactionFilterProxy::MAX_DATE);
break;
case Today:
transactionProxyModel->setDateRange(
QDateTime(current),
TransactionFilterProxy::MAX_DATE);
break;
case ThisWeek: {
// Find last Monday
QDate startOfWeek = current.addDays(-(current.dayOfWeek() - 1));
transactionProxyModel->setDateRange(
QDateTime(startOfWeek),
TransactionFilterProxy::MAX_DATE);
} break;
case ThisMonth:
transactionProxyModel->setDateRange(
QDateTime(QDate(current.year(), current.month(), 1)),
TransactionFilterProxy::MAX_DATE);
break;
case LastMonth:
transactionProxyModel->setDateRange(
QDateTime(QDate(current.year(), current.month() - 1, 1)),
QDateTime(QDate(current.year(), current.month(), 1)));
break;
case ThisYear:
transactionProxyModel->setDateRange(
QDateTime(QDate(current.year(), 1, 1)),
TransactionFilterProxy::MAX_DATE);
break;
case Range:
dateRangeWidget->setVisible(true);
dateRangeChanged();
break;
}
// Persist settings
if (dateWidget->itemData(idx).toInt() != Range) {
QSettings settings;
settings.setValue("transactionDate", idx);
}
}
示例8: createEventList
void HtmlExport::createEventList(QTextStream *ts)
{
int columns = 3;
*ts << "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">" << endl;
*ts << " <tr>" << endl;
*ts << " <th class=\"sum\">" << i18nc("@title:column event start time",
"Start Time") << "</th>" << endl;
*ts << " <th>" << i18nc("@title:column event end time",
"End Time") << "</th>" << endl;
*ts << " <th>" << i18nc("@title:column event description",
"Event") << "</th>" << endl;
if (d->mSettings->eventLocation()) {
*ts << " <th>" << i18nc("@title:column event locatin",
"Location") << "</th>" << endl;
++columns;
}
if (d->mSettings->eventCategories()) {
*ts << " <th>" << i18nc("@title:column event categories",
"Categories") << "</th>" << endl;
++columns;
}
if (d->mSettings->eventAttendees()) {
*ts << " <th>" << i18nc("@title:column event attendees",
"Attendees") << "</th>" << endl;
++columns;
}
*ts << " </tr>" << endl;
for (QDate dt = fromDate(); dt <= toDate(); dt = dt.addDays(1)) {
qCDebug(KCALUTILS_LOG) << "Getting events for" << dt.toString();
Event::List events = d->mCalendar->events(dt, d->mCalendar->timeSpec(),
EventSortStartDate,
SortDirectionAscending);
if (events.count()) {
*ts << " <tr><td colspan=\"" << QString::number(columns)
<< "\" class=\"datehead\"><i>"
<< QLocale().toString(dt)
<< "</i></td></tr>" << endl;
Event::List::ConstIterator it;
for (it = events.constBegin(); it != events.constEnd(); ++it) {
if (checkSecrecy(*it)) {
createEvent(ts, *it, dt);
}
}
}
}
*ts << "</table>" << endl;
}
示例9: paintEvent
void ListWidget::paintEvent(QPaintEvent *) {
int height = 1;
for (QDate day = firstDay; day <= lastDay; day = day.addDays(1))
{
QVector <Event*> events = manager->getEvents(day);
if (events.size()) {
height += 20 * (events.size() + 1);
}
}
resize(this->width(), height);
QPainter painter (this);
QRect textRect(rect().left(), rect().top(), rect().width() - 1, 19);
for (QDate day = firstDay; day <= lastDay; day = day.addDays(1))
{
QVector <Event*> events = manager->getEvents(day);
if (events.size()) {
painter.setBrush(Qt::white);
painter.setPen(Qt::black);
painter.drawRect(textRect);
painter.drawText(textRect, " Date: " + day.toString());
textRect.setTop(textRect.top() + 20);
textRect.setHeight(19);
for (auto event: events) {
if (event->isRegular()) {
painter.setBrush(QColor(Qt::blue).lighter());
} else {
painter.setBrush(event->color());
}
painter.drawRect(textRect);
painter.drawText(textRect, Qt::AlignCenter, event->info() + " (" + event->begin().toString() + ")");
textRect.setTop(textRect.top() + 20);
textRect.setHeight(19);
}
}
}
}
示例10: set
void RecurrenceWidget::set(bool recurring, int frequency, QString period, QDate startDate, QDate endDate, int max)
{
if (DEBUG)
qDebug() << objectName() << "::set(" << recurring << ", "
<< frequency << ", " << period << ", "
<< startDate << ", " << endDate << ", "
<< max << ") entered";
// run from the beginning of the start date to the end of the end date
QDateTime startDateTime(startDate);
QDateTime endDateTime(endDate.addDays(1));
endDateTime = endDateTime.addMSecs(-1);
set(recurring, frequency, period, startDateTime, endDateTime, max);
}
示例11: CPrealert
QList<CPrealert> *CSinglePrealertEdit::setupNewPrealerts()
{
QList<CPrealert> *lPre = new QList<CPrealert>();
for(QDate i = ui->dteFrom->date(); i <= ui->dteTo->date(); i = i.addDays(1))
{
CPrealert * lAlert = new CPrealert();
lAlert->setDate(i);
lAlert->setPers(m_actPers);
lPre->append(*lAlert);
}
return lPre;
}
示例12: generateEmptyLine
QString CrCalendar::generateEmptyLine() {
QString str;
QDate dayIterator;
for(dayIterator = _dateFirst; dayIterator <= _dateLast; dayIterator = dayIterator.addDays(1))
if(dayIterator.dayOfWeek() == Qt::Saturday
|| dayIterator.dayOfWeek() == Qt::Sunday) {
str += "<td class=\"" +Cell::getCssClassAsString(Cell::non_work_day)+ "\"></td>";
} else {
str += "<td> </td>";
}
return str;
}
示例13: 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 );
}
}
示例14: addDays
QDate KCalendarSystem::addDays( const QDate &date, int numDays ) const
{
// QDate only holds a uint and has no boundary checking in addDays(), so we need to check
if ( isValid( date ) && (long) date.toJulianDay() + (long) numDays > 0 ) {
// QDate adds straight to jd
QDate temp = date.addDays( numDays );
if ( isValid( temp ) ) {
return temp;
}
}
//Is QDate's way of saying is invalid
return QDate::fromJulianDay( 0 );
}
示例15: loadBudgetView
void KForecastView::loadBudgetView()
{
MyMoneyFile* file = MyMoneyFile::instance();
MyMoneyForecast forecast = KMyMoneyGlobalSettings::forecast();
//get the settings from current page and calculate this year based on last year
QDate historyEndDate = QDate(QDate::currentDate().year() - 1, 12, 31);
QDate historyStartDate = historyEndDate.addDays(-m_accountsCycle->value() * m_forecastCycles->value());
QDate forecastStartDate = QDate(QDate::currentDate().year(), 1, 1);
QDate forecastEndDate = QDate::currentDate().addDays(m_forecastDays->value());
forecast.setHistoryMethod(m_historyMethod->checkedId());
MyMoneyBudget budget;
forecast.createBudget(budget, historyStartDate, historyEndDate, forecastStartDate, forecastEndDate, false);
m_budgetList->clear();
m_budgetList->setIconSize(QSize(22, 22));
m_budgetList->setSortingEnabled(true);
m_budgetList->sortByColumn(0, Qt::AscendingOrder);
//add columns
QStringList headerLabels;
headerLabels << i18n("Account");
{
QDate forecastStartDate = forecast.forecastStartDate();
QDate forecastEndDate = forecast.forecastEndDate();
//add cycle interval columns
QDate f_date = forecastStartDate;
for (; f_date <= forecastEndDate; f_date = f_date.addMonths(1)) {
headerLabels << QDate::longMonthName(f_date.month());
}
}
//add total column
headerLabels << i18nc("Total balance", "Total");
//set the columns
m_budgetList->setHeaderLabels(headerLabels);
//add default rows
addTotalRow(m_budgetList, forecast);
addIncomeExpenseRows(forecast);
//load income and expense budget accounts
loadAccounts(forecast, file->income(), m_incomeItem, eBudget);
loadAccounts(forecast, file->expense(), m_expenseItem, eBudget);
adjustHeadersAndResizeToContents(m_budgetList);
}