void Tracker::removeItem() { if(detailList->currentItem() == NULL) return; QString toRemove = detailList->currentItem()->text(); if(searchFlag == 0){ if(toRemove.toStdString().compare("EXPENSE: ") != 0 && toRemove.toStdString().compare("INCOME: ") != 0){ std::string Rname(toRemove.toStdString(), 0 ,17); std::string Rlabel(toRemove.toStdString(), 17, 14); std::string sign(toRemove.toStdString(),31 ,1); std::string Ramount(toRemove.toStdString(), 32, 15); double RVamount = atof(Ramount.c_str()); // std::cout<<toRemove.toStdString().c_str()<<"\n"; // std::cout<<Rname<<" |"<<RLabel<<" |"<<Ramount<<" |"<<RVamount<<std::endl; if(sign == "-") searchToRemove(expenseItems, Rname, Rlabel, RVamount); else searchToRemove(incomeItems, Rname, Rlabel, RVamount); selectedDateChanged(); } } else detailList->addItem("Remove in search is not allowed!"); double ratioValue = report_sum_M(QDate::currentDate().month(),QDate::currentDate().year(),expenseItems)/budgetAmount; if(ratioValue < 1){ ratio->setValue(100*ratioValue); } else ratio->setValue(100); }
void DCalendar::selectDate(const QDate &date) { // qDebug() << m_showDate << date; const QDate oldDate = m_showDate; m_showDate = date; if (date.year() < oldDate.year()) aniToPrev(); else if (date.year() > oldDate.year()) aniToNext(); else if (date.month() < oldDate.month()) aniToPrev(); else if (date.month() > oldDate.month()) aniToNext(); if (date == m_currentDate) m_resetBtn->hide(); else m_resetBtn->show(); m_monEdt->setText(QString::number(date.month())); m_yearEdt->setText(QString::number(date.year())); m_viewCurrent->setCurrentDate(m_showDate); emit selectedDateChanged(date); }
void DateSelector::setSelectedDate(const QDate &date) { if (m_selectedDate == date) return; m_selectedDate = date; Q_EMIT selectedDateChanged(); }
void Window::createDatesGroupBox() { /* QGroupBox *datesGroupBox; QLabel *currentDateLabel; QLabel *minimumDateLabel; QLabel *maximumDateLabel; QDateEdit *currentDateEdit; QDateEdit *minimumDateEdit; QDateEdit *maximumDateEdit; */ datesGroupBox = new QGroupBox(tr("Date")); currentDateEdit = new QDateEdit; currentDateEdit->setDisplayFormat("MMM d yyyy"); currentDateEdit->setDate(calendar->selectedDate()); currentDateEdit->setDateRange(calendar->minimumDate(), calendar->maximumDate()); currentDateLabel = new QLabel(tr("CurrentDate")); currentDateLabel->setBuddy(currentDateEdit); maximumDateEdit = new QDateEdit; maximumDateEdit->setDisplayFormat("MMM d yyyy"); maximumDateEdit->setDate(calendar->maximumDate()); maximumDateEdit->setDateRange(calendar->minimumDate(), calendar->maximumDate()); maximumDateLabel = new QLabel(tr("MaximumDate")); maximumDateLabel->setBuddy(maximumDateEdit); minimumDateEdit = new QDateEdit; minimumDateEdit->setDisplayFormat("MMM d yyyy"); minimumDateEdit->setDate(calendar->minimumDate()); minimumDateEdit->setDateRange(calendar->minimumDate(), calendar->maximumDate()); minimumDateLabel = new QLabel(tr("MinimumDate")); minimumDateLabel->setBuddy(minimumDateEdit); connect(currentDateEdit, SIGNAL(dateChanged(const QDate &)), calendar, SLOT(setSelectedDate(const QDate &))); connect(maximumDateEdit, SIGNAL(dateChanged(const QDate &)), calendar, SLOT(maximumDateChanged(const QDate &date))); connect(minimumDateEdit, SIGNAL(dateChanged(const QDate &)), calendar, SLOT(minimumDateChanged(const QDate &date))); // connect(calendar, SIGNAL(selectionChanged()), currentDateEdit, SLOT(selectedDateChanged())); connect(calendar, SIGNAL(selectionChanged()), this, SLOT(selectedDateChanged())); QGridLayout *dateLayout = new QGridLayout; dateLayout->addWidget(minimumDateLabel, 0, 0); dateLayout->addWidget(minimumDateEdit, 0, 1); dateLayout->addWidget(currentDateLabel, 1, 0); dateLayout->addWidget(currentDateEdit, 1, 1); dateLayout->addWidget(maximumDateLabel, 2, 0); dateLayout->addWidget(maximumDateEdit, 2, 1); dateLayout->setRowStretch(3, 0); datesGroupBox->setLayout(dateLayout); }
//! [13] void Window::createDatesGroupBox() { datesGroupBox = new QGroupBox(tr("Dates")); minimumDateEdit = new QDateEdit; minimumDateEdit->setDisplayFormat("MMM d yyyy"); minimumDateEdit->setDateRange(calendar->minimumDate(), calendar->maximumDate()); minimumDateEdit->setDate(calendar->minimumDate()); minimumDateLabel = new QLabel(tr("&Minimum Date:")); minimumDateLabel->setBuddy(minimumDateEdit); currentDateEdit = new QDateEdit; currentDateEdit->setDisplayFormat("MMM d yyyy"); currentDateEdit->setDate(calendar->selectedDate()); currentDateEdit->setDateRange(calendar->minimumDate(), calendar->maximumDate()); currentDateLabel = new QLabel(tr("&Current Date:")); currentDateLabel->setBuddy(currentDateEdit); maximumDateEdit = new QDateEdit; maximumDateEdit->setDisplayFormat("MMM d yyyy"); maximumDateEdit->setDateRange(calendar->minimumDate(), calendar->maximumDate()); maximumDateEdit->setDate(calendar->maximumDate()); maximumDateLabel = new QLabel(tr("Ma&ximum Date:")); maximumDateLabel->setBuddy(maximumDateEdit); //! [13] //! [14] connect(currentDateEdit, SIGNAL(dateChanged(QDate)), calendar, SLOT(setSelectedDate(QDate))); connect(calendar, SIGNAL(selectionChanged()), this, SLOT(selectedDateChanged())); connect(minimumDateEdit, SIGNAL(dateChanged(QDate)), this, SLOT(minimumDateChanged(QDate))); connect(maximumDateEdit, SIGNAL(dateChanged(QDate)), this, SLOT(maximumDateChanged(QDate))); //! [14] QGridLayout *dateBoxLayout = new QGridLayout; dateBoxLayout->addWidget(currentDateLabel, 1, 0); dateBoxLayout->addWidget(currentDateEdit, 1, 1); dateBoxLayout->addWidget(minimumDateLabel, 0, 0); dateBoxLayout->addWidget(minimumDateEdit, 0, 1); dateBoxLayout->addWidget(maximumDateLabel, 2, 0); dateBoxLayout->addWidget(maximumDateEdit, 2, 1); dateBoxLayout->setRowStretch(3, 1); datesGroupBox->setLayout(dateBoxLayout); //! [15] }
//Throw the dialog to input the expense information void Tracker::addexpensewindow() { addExpenseWindow = new addExpenseDialog(); // Be sure to destroy you window somewhere addExpenseWindow->setMaximumSize(300,250); addExpenseWindow->setMinimumSize(300,250); addExpenseWindow->setWindowTitle("Add Expense Item on This Day"); //******Add labels******// for(unsigned i = 0; i < expenseLabels->size(); i++){ addExpenseWindow->categoryBox->addItem(tr((*expenseLabels)[i].c_str())); } //addExpenseWindow->categoryBox->addItem(tr("Add new label...")); //***if save***// if(addExpenseWindow->exec() == QDialog::Accepted){ //***check if new label***// unsigned i; for(i = 0; i < expenseLabels->size(); i++){ if(addExpenseWindow->expenseLabel.toStdString() == (*expenseLabels)[i]){ break; } } if(i == expenseLabels->size()){ expenseLabels->push_back(addExpenseWindow->expenseLabel.toStdString()); } //*************************// date testDate(calendar->selectedDate().year(),calendar->selectedDate().month(),calendar->selectedDate().day()); item toAdd(addExpenseWindow->expensename.toStdString(), addExpenseWindow->expenseamount, testDate, addExpenseWindow->expenseLabel.toStdString()); //std::cout<<toAdd.getName().c_str()<<" "<<toAdd.getAmount()<<" "<<toAdd.getLabel().c_str()<<" "<<toAdd.getDate().month<<"/"<<toAdd.getDate().day<<"/"<<toAdd.getDate().year<<std::endl; expenseItems->push_back(toAdd); //std::cout<<"clicked SAVE"<<std::endl; selectedDateChanged(); } //***if not save***// else{ //std::cout<<"clicked CANCLE"<<std::endl; } double ratioValue = report_sum_M(QDate::currentDate().month(),QDate::currentDate().year(),expenseItems)/budgetAmount; if(ratioValue < 1){ ratio->setValue(100*ratioValue); } else ratio->setValue(100); }
//Throw the dialog to input the income information void Tracker::addincomewindow() { addIncomeWindow = new addIncomeDialog(); // Be sure to destroy you window somewhere addIncomeWindow->setMaximumSize(300,250); addIncomeWindow->setMinimumSize(300,250); addIncomeWindow->setWindowTitle("Add Income Item on This Day"); //******Add labels******// for(unsigned i = 0; i < incomeLabels->size(); i++){ addIncomeWindow->categoryBox->addItem(tr((*incomeLabels)[i].c_str())); } //addIncomeWindow->categoryBox->addItem(tr("Add new label...")); //***if save***// if(addIncomeWindow->exec() == QDialog::Accepted){ //***check if new label***// unsigned i; for(i = 0; i < incomeLabels->size(); i++){ if(addIncomeWindow->incomeLabel.toStdString() == (*incomeLabels)[i]){ break; } } if(i == incomeLabels->size()){ incomeLabels->push_back(addIncomeWindow->incomeLabel.toStdString()); } //*************************// date testDate(calendar->selectedDate().year(),calendar->selectedDate().month(),calendar->selectedDate().day()); item toAdd(addIncomeWindow->incomename.toStdString(), addIncomeWindow->incomeamount, testDate, addIncomeWindow->incomeLabel.toStdString()); //std::cout<<toAdd.getName().c_str()<<" "<<toAdd.getAmount()<<" "<<toAdd.getLabel().c_str()<<" "<<toAdd.getDate().month<<"/"<<toAdd.getDate().day<<"/"<<toAdd.getDate().year<<std::endl; incomeItems->push_back(toAdd); //std::cout<<"clicked SAVE"<<std::endl; selectedDateChanged(); } //***if not save***// else{ //std::cout<<"clicked CANCLE"<<std::endl; } }
Tracker::Tracker(QWidget *parent) : QWidget(parent) { //****************construct putton and widget************************// //Calendar Setting calendar = new QCalendarWidget; calendar->setGridVisible(true); QLabel *listname=new QLabel(" Detail Table"); listname->setFont(QFont("Times", 16, QFont::Bold)); listname->setStyleSheet("QLabel { background-color : rgb(255, 165, 0); color : black; }"); detailList=new QListWidget; detailList->setStyleSheet( "QListWidget::item { background-color: white;border-bottom: 1px solid black; }" "QListWidget::item:selected{color: #333538;background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #cdcdcd, stop: 1 #ababab); border-top: 1px solid;border-top-color: #a8abad;border-bottom: 1px solid;border-bottom-color: #bfc7ce;}"); removeButton=new QPushButton(tr("&REMOVE")); removeButton->setFont(QFont("Cambria", 14, QFont::Bold)); QVBoxLayout *LayoutRight=new QVBoxLayout; LayoutRight->addWidget(listname,1); LayoutRight->addWidget(detailList,12); LayoutRight->setSpacing(3); LayoutRight->addWidget(removeButton,2); QHBoxLayout *Layout1=new QHBoxLayout; Layout1->addWidget(calendar,3); Layout1->addLayout(LayoutRight,2); //Background Setting QString newpath (":/image/images/2.jpg"); QPixmap pixmap = QPixmap(newpath).scaled(this->size()); QPalette palette(this->palette()); palette.setBrush(QPalette::Background, QBrush(pixmap)); this->setPalette(palette); //pushbutton declaration addExpenseButton = new QPushButton(tr("&Expense")); addExpenseButton->setFont(QFont("Cambria", 13, QFont::Bold)); addIncomeButton= new QPushButton(tr("&Income")); addIncomeButton->setFont(QFont("Cambria", 13, QFont::Bold)); shoppingListButton= new QPushButton(tr("&Shopping List")); shoppingListButton->setFont(QFont("Cambria", 13, QFont::Bold)); reportButton = new QPushButton(tr("&Report")); reportButton->setFont(QFont("Cambria", 13, QFont::Bold)); searchButton = new QPushButton(tr("&Search")); searchButton->setFont(QFont("Cambria", 13, QFont::Bold)); searchLine = new QLineEdit; // Button horizontal layout QHBoxLayout *buttonLayout1 = new QHBoxLayout; buttonLayout1->addWidget(addExpenseButton,1); buttonLayout1->addWidget(addIncomeButton,1); buttonLayout1->addWidget(reportButton,1); buttonLayout1->addWidget(shoppingListButton,1); QHBoxLayout *searcharea = new QHBoxLayout; searcharea->addWidget(searchLine,3); searcharea->addWidget(searchButton,1); QVBoxLayout *left = new QVBoxLayout; left->addLayout(buttonLayout1); left->addLayout(searcharea); //right area settingbudget=new QPushButton(tr("Monthly Budget")); settingbudget->setFont(QFont("Times", 15, QFont::Bold)); budget=new QLCDNumber; budget->setSegmentStyle(QLCDNumber::Filled); //budget->display(budgetAmount); QPushButton *ratiobar=new QPushButton(tr("Expense Ratio")); ratiobar->setFont(QFont("Times", 15, QFont::Bold)); ratio=new QProgressBar; QGridLayout *showarea=new QGridLayout; showarea->setSpacing(20); showarea->addWidget(settingbudget,0,0); showarea->addWidget(budget,0,1); showarea->addWidget(ratiobar,1,0); showarea->addWidget(ratio,1,1); QHBoxLayout *Layout2=new QHBoxLayout; Layout2->addLayout(left,3); Layout2->addLayout(showarea,2); QVBoxLayout *mainLayout=new QVBoxLayout; mainLayout->addLayout(Layout1,10); mainLayout->addLayout(Layout2,3); setLayout(mainLayout); setWindowTitle("Basic Model"); //! [grid layout] setLayout(mainLayout); setWindowTitle(tr("Basic Model")); //****************construct items and labels************************// // QDir currentDir; // QString path = currentDir.currentPath(); // QString filePathE = path + "/../../../expense_data.csv"; // QString filePathI = path + "/../../../income_data.csv"; // QString filePathEL = path + "/../../../expense_labels.txt"; // QString filePathIL = path + "/../../../income_labels.txt"; QString homePath = QString(getenv("HOME")); //std::cout<<homePath.toStdString().c_str()<<std::endl; QDir *temp = new QDir; bool exist = temp->exists(homePath + "/.ExpenseTracker_withData"); if(exist == 0) temp->mkdir(homePath + "/.ExpenseTracker_withData"); QString filePathE = homePath + "/.ExpenseTracker_withData/expense_data.csv"; QString filePathI = homePath + "/.ExpenseTracker_withData/income_data.csv"; QString filePathEL = homePath + "/.ExpenseTracker_withData/expense_labels.txt"; QString filePathIL = homePath + "/.ExpenseTracker_withData/income_labels.txt"; QString filePathB = homePath + "/.ExpenseTracker_withData/budget.txt"; QString filePathSL = homePath + "/.ExpenseTracker_withData/shoppingList.csv"; std::ifstream fin(filePathE.toStdString().c_str()); if(!fin){ QString dataPath (":/data/resource"); QString filePathEd = dataPath + "/expense_data.csv"; QString filePathId = dataPath + "/income_data.csv"; QString filePathELd = dataPath + "/expense_labels.txt"; QString filePathILd = dataPath + "/income_labels.txt"; QString filePathBd = dataPath + "/budget.txt"; QString filePathSLd = dataPath + "/shoppingList.csv"; expenseItems = readData(filePathEd); incomeItems = readData(filePathId); expenseLabels = readLabel(filePathELd); incomeLabels = readLabel(filePathILd); budgetAmount = readBudget(filePathBd); shoppingItems = readShoppingList(filePathSLd); writeData(expenseItems, filePathE.toStdString().c_str()); writeData(incomeItems, filePathI.toStdString().c_str()); writeLabel(expenseLabels, filePathEL.toStdString().c_str()); writeLabel(incomeLabels, filePathIL.toStdString().c_str()); writeBudget(budgetAmount, filePathB.toStdString().c_str()); writeShoppingList(shoppingItems, filePathSL.toStdString().c_str()); } else{ expenseItems = readData(filePathE.toStdString().c_str()); incomeItems = readData(filePathI.toStdString().c_str()); expenseLabels = readLabel(filePathEL.toStdString().c_str()); incomeLabels = readLabel(filePathIL.toStdString().c_str()); budgetAmount = readBudget(filePathB.toStdString().c_str()); std::ifstream finSL(filePathSL.toStdString().c_str()); if(finSL){ shoppingItems = readShoppingList(filePathSL.toStdString().c_str()); } else{ shoppingItems = NULL; } } budget->display(budgetAmount); selectedDateChanged(); double ratioValue = report_sum_M(QDate::currentDate().month(),QDate::currentDate().year(),expenseItems)/budgetAmount; if(ratioValue < 1){ ratio->setValue(100*ratioValue); } else ratio->setValue(100); searchFlag = 0; //******************connecting signals and slots***************************// connect(addExpenseButton, SIGNAL(clicked()), this, SLOT(addexpensewindow())); connect(addIncomeButton, SIGNAL(clicked()), this, SLOT(addincomewindow())); connect(reportButton, SIGNAL(clicked()), this, SLOT(report())); connect(calendar, SIGNAL(selectionChanged()), this, SLOT(selectedDateChanged())); connect(settingbudget, SIGNAL(clicked()), this, SLOT(settingBudget())); connect(removeButton, SIGNAL(clicked()), this, SLOT(removeItem())); connect(shoppingListButton, SIGNAL(clicked()), this, SLOT(checkShoppingList())); connect(searchButton, SIGNAL(clicked()), this, SLOT(searchItem())); connect(searchLine, SIGNAL(returnPressed()), this, SLOT(searchItem())); }