本文整理汇总了C++中QDate::addYears方法的典型用法代码示例。如果您正苦于以下问题:C++ QDate::addYears方法的具体用法?C++ QDate::addYears怎么用?C++ QDate::addYears使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDate
的用法示例。
在下文中一共展示了QDate::addYears方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: update
void update()
{
QFile dataFile(fileName);
if((!dataFile.open(QFile::ReadOnly))){
qDebug() << "Could not open file " + fileName;
}
else{
QFile dataFileTemp("temp.dat");
if((!dataFileTemp.open(QFile::WriteOnly))){
qDebug() << "Could not open file " + fileName;
}
QTextStream in(&dataFile);
QTextStream out(&dataFileTemp);
QDate currentDate = QDate::currentDate();
while(!in.atEnd()){
QString line = in.readLine(); //read one line at a time
QStringList lineItems = line.split('|');
for (QStringList::iterator it = lineItems.begin();it != lineItems.end(); ++it){
QString current = *it;
QDate date = QDate::fromString(current,Qt::ISODate);
if(date.isValid()){
if(currentDate.year() > date.year()){
date.setDate(currentDate.year(),date.month(),date.day());
lineItems[0] = date.toString(Qt::ISODate);
}
if(date < currentDate){
if(QDate::isLeapYear(date.year())){
date = date.addYears(4);
}
else{
date = date.addYears(1);
}
lineItems[0] = date.toString(Qt::ISODate);
line = lineItems.join("|");
out << line << endl;
}
else{
line = lineItems.join("|");
out << line << endl;
}
}
}
}
dataFile.remove();
if(!dataFileTemp.rename("temp.dat",fileName)){
qDebug() << "Unable to change file name";
}
}
}
示例3: fromOutlookCsvParsed
Schedule Schedule::fromOutlookCsvParsed(const QList<QStringList>& parsedCsv,
const QTimeZone& timeZone,
QString dateFormat,
QString timeFormat)
{
const int START_DATE_POS = 0;
const int START_TIME_POS = 1;
const int START_SUBJECT_POS = 3;
const int START_LOCATION_POS = 4;
if (dateFormat.isEmpty())
dateFormat = "MM/dd/yyyy";
if (timeFormat.isEmpty())
timeFormat = "hh:mm AP";
Schedule schedule;
for (int i = 0; i < parsedCsv.size(); ++i) {
const QStringList& row = parsedCsv.at(i);
QDate date = QDate::fromString(row.at(START_DATE_POS), dateFormat);
QTime time = QTime::fromString(row.at(START_TIME_POS), timeFormat);
if (date.year() < 2000)
date = date.addYears(100);
schedule.addEvent(date,
time,
row.at(START_SUBJECT_POS),
row.at(START_LOCATION_POS),
timeZone);
}
return schedule;
}
示例4: firstFiscalDate
QDate KMyMoneyGlobalSettings::firstFiscalDate()
{
QDate date = QDate(QDate::currentDate().year(), firstFiscalMonth(), firstFiscalDay());
if (date > QDate::currentDate())
date.addYears(-1);
return date;
}
示例5: selectMeasurement
QList<QString> ImportExport::months(quint8 aType, const QDate& aYear)
{
QList<QString> dataList;
QSqlQuery selectMeasurement(mDataBase);
quint64 startTimeStamp = QDateTime(aYear).toMSecsSinceEpoch();
quint64 endTimeStamp = QDateTime(aYear.addYears(1)).toMSecsSinceEpoch();
selectMeasurement.prepare(
"SELECT "
"timestamp "
"FROM "
"Measurement "
"WHERE "
"type = :type "
"AND "
"timestamp >= :startTimeStamp "
"AND "
"timestamp <= :endTimeStamp "
"ORDER BY "
"timestamp "
"ASC;"
);
selectMeasurement.bindValue(":type", aType);
selectMeasurement.bindValue(":startTimeStamp", startTimeStamp);
selectMeasurement.bindValue(":endTimeStamp", endTimeStamp);
if (!selectMeasurement.exec())
{
qDebug() << "FATAL selectMeasurement.exec(): " << selectMeasurement.lastError().databaseText() << " - " << selectMeasurement.lastError().driverText();
qDebug() << "Executed Query: " << selectMeasurement.executedQuery();
return dataList;
}
quint64 timestamp;
QString monthStr;
while (selectMeasurement.next())
{
timestamp = selectMeasurement.value(0).toLongLong();
QDateTime monthDate = QDateTime::fromMSecsSinceEpoch(timestamp);
monthStr = monthDate.toString("MMMM");
if (!dataList.contains(monthStr))
{
dataList.push_back(monthStr);
}
}
selectMeasurement.finish();
return dataList;
}
示例6: QWidget
QtDcm::QtDcm ( QWidget *parent )
: QWidget ( parent ), d ( new QtDcmPrivate )
{
QTextCodec::setCodecForLocale( QTextCodec::codecForName ( "iso" ) );
setupUi ( this );
d->mode = QtDcm::CD_MODE;
//Initialize QTreeWidgetPatients
treeWidgetPatients->setColumnWidth ( 0, 400 );
treeWidgetPatients->setColumnWidth ( 1, 100 );
treeWidgetPatients->setColumnWidth ( 2, 100 );
const QStringList labelsPatients = QStringList()
<< "Patients name"
<< "ID"
<< "Birthdate"
<< "Sex";
treeWidgetPatients->setHeaderLabels ( labelsPatients );
treeWidgetPatients->setContextMenuPolicy ( Qt::CustomContextMenu );
//Initialize QTreeWidgetSeries
treeWidgetStudies->setColumnWidth ( 0, 200 );
treeWidgetStudies->setColumnWidth ( 1, 100 );
const QStringList labelsStudies = QStringList()
<< "Studies description"
<< "Date"
<< "ID";
treeWidgetStudies->setHeaderLabels ( labelsStudies );
treeWidgetStudies->setContextMenuPolicy ( Qt::CustomContextMenu );
//Initialize QTreeWidgetSeries
treeWidgetSeries->setColumnWidth ( 0, 230 );
treeWidgetSeries->setColumnWidth ( 1, 100 );
treeWidgetSeries->setColumnWidth ( 2, 100 );
const QStringList labelsSeries = QStringList()
<< "Series description"
<< "Modality"
<< "Date"
<< "ID";
treeWidgetSeries->setHeaderLabels ( labelsSeries );
treeWidgetSeries->setContextMenuPolicy ( Qt::CustomContextMenu );
//Initialize widgets
QDate currentDate = QDate::currentDate();
startDateEdit->setDate ( currentDate.addYears(-100) );
endDateEdit->setDate ( currentDate );
QtDcmManager::instance()->setPatientsTreeWidget ( treeWidgetPatients );
QtDcmManager::instance()->setStudiesTreeWidget ( treeWidgetStudies );
QtDcmManager::instance()->setSeriesTreeWidget ( treeWidgetSeries );
QtDcmManager::instance()->setStartDate ( startDateEdit->date() );
QtDcmManager::instance()->setEndDate ( endDateEdit->date() );
initConnections();
}
示例7: QWidget
ConfigureSessionsWidget::ConfigureSessionsWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::ConfigureSessionsWidget)
{
ui->setupUi(this);
QDate defaultDate = QDate::currentDate().addMonths(-1);
defaultDate = defaultDate.addYears(-1);
ui->dateLimit->setDate(defaultDate);
}
示例8: highestVersionDate
QDate FileName::highestVersionDate() const {
QString fileQDatePattern = fileNameQDatePattern();
QPair<int, int> truncateRange(-1, -1);
if (fileQDatePattern.contains("?")) {
QString trueLengthName = name().replace(QRegExp("[{}]"), "");
truncateRange.first = trueLengthName.indexOf("?");
truncateRange.second = trueLengthName.lastIndexOf("?");
fileQDatePattern = fileQDatePattern.replace("?", "");
}
QString file = name();
QDate result;
QDate sputnikLaunch(1957, 10, 4);
QString before = file.mid(0, file.indexOf("{"));
QString after = file.mid(file.lastIndexOf("}") + 1);
QStringList nameFilters;
nameFilters.append(before + "*" + after);
QStringList files = dir().entryList(nameFilters);
// We can't sort the files to get our answer, so we need to go through every possible file.
foreach (QString foundFile, files) {
// Toss any numerical versioning sequence
if (truncateRange.first >= 0 && truncateRange.second > truncateRange.first) {
foundFile = foundFile.mid(0, truncateRange.first) +
foundFile.mid(truncateRange.second + 1);
}
QDate fileDate = QDate::fromString(foundFile, fileQDatePattern);
if (fileDate.isValid()) {
// No missions before Sputnik 1, so we must be in the new millenium
if (fileDate < sputnikLaunch)
fileDate = fileDate.addYears(100);
if (!result.isValid() || fileDate > result) {
result = fileDate;
}
}
}
if (!result.isValid()) {
throw IException(IException::Unknown,
QObject::tr("No existing files found with a date version matching [%1] in "
"[%2]")
.arg(FileName(expanded()).name()).arg(path()),
_FILEINFO_);
}
return result;
}
示例9: date_by_amount_and_unit
static QDate date_by_amount_and_unit( int inAmount, int inUnit ) {
const QDate current = QDate::currentDate();
switch ( inUnit ) {
case Days: return current.addDays( inAmount ); break;
case Weeks: return current.addDays( 7*inAmount ); break;
case Months: return current.addMonths( inAmount ); break;
case Years: return current.addYears( inAmount ); break;
default:
assert( !"Should not reach here" );
}
return QDate();
}
示例10: setPmhData
void PmhEpisodeViewer::setPmhData(Internal::PmhData *pmh)
{
Q_ASSERT(pmh);
if (!pmh)
return;
if (patient()) {
// Create date delegates
Utils::DateTimeDelegate *start = new Utils::DateTimeDelegate(this, true);
Utils::DateTimeDelegate *end = new Utils::DateTimeDelegate(this, true);
ui->tableView->tableView()->setItemDelegateForColumn(PmhEpisodeModel::DateStart, start);
ui->tableView->tableView()->setItemDelegateForColumn(PmhEpisodeModel::DateEnd, end);
QDate birth = patient()->data(Core::IPatient::DateOfBirth).toDate();
if (birth.isValid()) {
start->setDateRange(birth, birth.addYears(150));
end->setDateRange(birth, birth.addYears(150));
}
}
d->m_Pmh = pmh;
// If SimpleView -> test pmhepisodedata -> create a default one
if (pmh->episodeModel()->rowCount()==0) {
pmh->episodeModel()->insertRow(0);
}
ui->tableView->setModel(pmh->episodeModel());
ui->tableView->hideColumn(PmhEpisodeModel::IcdXml);
ui->tableView->hideColumn(PmhEpisodeModel::Contact);
ui->tableView->hideColumn(PmhEpisodeModel::EmptyColumn);
#if QT_VERSION < 0x050000
ui->tableView->horizontalHeader()->setResizeMode(PmhEpisodeModel::Label, QHeaderView::Stretch);
ui->tableView->horizontalHeader()->setResizeMode(PmhEpisodeModel::DateEnd, QHeaderView::Stretch);
ui->tableView->horizontalHeader()->setResizeMode(PmhEpisodeModel::DateStart, QHeaderView::Stretch);
#else
// Qt5
ui->tableView->horizontalHeader()->setSectionResizeMode(PmhEpisodeModel::Label, QHeaderView::Stretch);
ui->tableView->horizontalHeader()->setSectionResizeMode(PmhEpisodeModel::DateEnd, QHeaderView::Stretch);
ui->tableView->horizontalHeader()->setSectionResizeMode(PmhEpisodeModel::DateStart, QHeaderView::Stretch);
#endif
}
示例11: createDBFile
bool CoreData::createDBFile(QString dbname)
{
if (QFile::exists(dbname)) {
QFile::remove(dbname);
}
db.setDatabaseName(dbname);
if (!db.open()) {
QMessageBox::critical(0, QString::fromUtf8("出错了!"), QString::fromUtf8("无法打开数据库文件"));
return false;
}
QSqlQuery query;
query.exec("drop table people ");
query.exec("create table people (id int primary key, name varchar(64), gender char(8), join_date date, status tinyint, comment text)");
qDebug() << db.lastError().type() << " + " << db.lastError().text();
query.exec("drop table date");
query.exec("create table date (id int primary key, date date)");
query.exec("pragma synchronous=0");
qDebug() << db.lastError().type() << " + " << db.lastError().text();
QDate date = QDate::currentDate();
date = date.addYears(-1);
query.prepare("insert into date (id, date) values (?,?)");
int i = 0;
QVariantList ids;
QStringList dateStrings;
for (i=0; i<3000; ++i) {
ids<<i;
date = date.addDays(1);
dateStrings<<date.toString("yyyy-MM-dd");
}
query.addBindValue(ids);
query.addBindValue(dateStrings);
if (!query.execBatch())
qDebug() << query.lastError();
query.exec("pragma synchronous=2");
qDebug()<<query.lastError();
query.exec("create table person_date (id int primary key, person_id integer, date_id integer, foreign key(person_id) references people(id), foreign key(date_id) references date(id))");
qDebug() << query.lastError();
personModel = new QSqlTableModel(0, db);
setPersonModel();
signInModel = new SignInModel(0);
setSignInModel(QDate::currentDate(), db);
query.exec("create table contact (id int primary key, person_id integer, method varchar(64), value varchar(128), foreign key(person_id) references people(id))");
qDebug() << query.lastError();
return true;
}
示例12: on_rangeCombo_activated
void Overview::on_rangeCombo_activated(int index)
{
p_profile->general->setLastOverviewRange(index);
ui->dateStart->setMinimumDate(p_profile->FirstDay());
ui->dateEnd->setMaximumDate(p_profile->LastDay());
QDate end = p_profile->LastDay();
QDate start;
if (index == 8) { // Custom
ui->dateStartLabel->setEnabled(true);
ui->dateEndLabel->setEnabled(true);
ui->dateEnd->setEnabled(true);
ui->dateStart->setEnabled(true);
ui->dateStart->setMaximumDate(ui->dateEnd->date());
ui->dateEnd->setMinimumDate(ui->dateStart->date());
return;
}
ui->dateEnd->setEnabled(false);
ui->dateStart->setEnabled(false);
ui->dateStartLabel->setEnabled(false);
ui->dateEndLabel->setEnabled(false);
if (index == 0) {
start = end.addDays(-6);
} else if (index == 1) {
start = end.addDays(-13);
} else if (index == 2) {
start = end.addMonths(-1).addDays(1);
} else if (index == 3) {
start = end.addMonths(-2).addDays(1);
} else if (index == 4) {
start = end.addMonths(-3).addDays(1);
} else if (index == 5) {
start = end.addMonths(-6).addDays(1);
} else if (index == 6) {
start = end.addYears(-1).addDays(1);
} else if (index == 7) { // Everything
start = p_profile->FirstDay();
}
if (start < p_profile->FirstDay()) { start = p_profile->FirstDay(); }
setRange(start, end);
}
示例13: qwhereaboutsupdate_readRmcSentence
static void qwhereaboutsupdate_readRmcSentence(const QByteArray &sentence, QWhereaboutsUpdate *update, QWhereaboutsUpdate::PositionFixStatus *fixStatus)
{
QList<QByteArray> parts = sentence.split(',');
if (parts.count() > 9) {
QTime time;
qwhereaboutsupdate_getTimeString(parts[1], &time);
update->setUpdateTime(time);
if (time.isValid()) {
QDate date = QDate::fromString(parts[9], "ddMMyy");
date = date.addYears(100); // otherwise starts from 1900
update->setUpdateDateTime(QDateTime(date, time, Qt::UTC));
}
}
if (parts.count() > 6) {
QWhereaboutsCoordinate coord;
qwhereaboutsupdate_getUpdateCoordinate(&coord, parts[3], parts[4], parts[5], parts[6]);
if (coord.type() != QWhereaboutsCoordinate::InvalidCoordinate)
update->setCoordinate(coord);
}
if (parts.count() > 7) {
bool hasSpeed = false;
float speed = parts[7].toFloat(&hasSpeed);
if (hasSpeed)
update->setGroundSpeed(speed * 1.852 / 3.6);
}
if (parts.count() > 8) {
bool hasCourse = false;
float course = parts[8].toFloat(&hasCourse);
if (hasCourse)
update->setCourse(course);
}
if (fixStatus && parts.count() > 2)
*fixStatus = qwhereaboutsupdate_fixStatusFromValidityFlag(parts[2]);
}
示例14: okButtonClicked
void ReaderInfoDialog::okButtonClicked()
{
QString ID = IDLineEdit->text();
QString sql = "select * from reader where ID='" + ID + "'";
QSqlDatabase db = QSqlDatabase::database();
QSqlQuery query = db.exec(sql);
if (query.isActive() && query.next())
{
QMessageBox::information(this, tr("Error"), tr("The ID has use."));
return;
}
sql = "select * from admin where user_name='" + ID + "'";
db = QSqlDatabase::database();
query = db.exec(sql);
if (query.isActive() && query.next())
{
QMessageBox::information(this, tr("Error"), tr("The ID has use."));
return;
}
QString password1 = passwordLineEdit->text();
QString password2 = againPasswordLineEdit->text();
if (password1 != password2)
{
QMessageBox::information(this, tr("Error"), tr("Password error."));
return;
}
QString name = nameLineEdit->text();
QString sex = sexComboBox->currentText();
QString birthday = birthdayDateEdit->date().toString(Qt::ISODate);
QDate date = cardDateEdit->date();
QString cardDate = date.toString(Qt::ISODate);
QString validDate = validDateEdit->date().toString(Qt::ISODate);
QString IDCard = IDCardLineEdit->text();
QString phone = phoneLineEdit->text();
int index = stateComboBox->currentIndex();
QString state = QString::fromLocal8Bit("ÆÕͨ");
if (index)
{
state = QString::fromLocal8Bit("×¢Ïú");
}
index = typeComboBox->currentIndex();
QString type = QString::fromLocal8Bit("ÆÕͨ");
if (index)
{
type = "VIP";
}
sql = "insert into reader values('" + ID + "','" + name + "','" + sex + "','"
+ birthday + "','" + cardDate + "','" + validDate + "','" + IDCard + "','" + phone + "','"
+ state + "','" + type + "')";
query = db.exec(sql);
if (!query.isActive())
{
QMessageBox::information(this, tr("Error"), query.lastError().text());
return;
}
sql = "insert into admin values('" + ID + "','" + password1 + "','0','0')";
query = db.exec(sql);
sql = "insert into reader_log_info(ID,reader_ID,operation,operation_date) values('"
+ user_name + "','" + ID + "','add','" + QDateTime::currentDateTime().toString(Qt::ISODate)
+ "')";
query = db.exec(sql);
if (query.isActive())
{
QMessageBox::information(this, tr("Succeed"), tr("Add data succeed."));
IDLineEdit->clear();
passwordLineEdit->clear();
againPasswordLineEdit->clear();
nameLineEdit->clear();
sexComboBox->setCurrentIndex(0);
QDate date = QDate::currentDate();
cardDateEdit->setDate(date);
validDateEdit->setDate(date.addYears(1));
IDCardLineEdit->clear();
phoneLineEdit->clear();
}
else
{
QMessageBox::information(this, tr("Error"), query.lastError().text());
}
}
示例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
//.........这里部分代码省略.........