void MyMoneyStorageXML::writeBudgets(QDomElement& parent) { const QList<MyMoneyBudget> list = m_storage->budgetList(); QList<MyMoneyBudget>::ConstIterator it; parent.setAttribute("count", list.count()); signalProgress(0, list.count(), i18n("Saving budgets...")); unsigned i = 0; for (it = list.constBegin(); it != list.constEnd(); ++it) { writeBudget(parent, (*it)); signalProgress(++i, 0); } }
//Maindow destructor Tracker::~Tracker() { // 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 filePathE = path + "/expense_data.csv"; // QString filePathI = path + "/income_data.csv"; // QString filePathEL = path + "/expense_labels.txt"; // QString filePathIL = path + "/income_labels.txt"; // QString filePathB = path + "/budget.txt"; // QString filePathSL = path + "/shoppingList.csv"; QString homePath = QString(getenv("HOME")); //std::cout<<homePath.toStdString().c_str()<<std::endl; 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"; 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()); if(shoppingItems != NULL){ writeShoppingList(shoppingItems, filePathSL.toStdString().c_str()); } delete expenseItems; delete incomeItems; delete expenseLabels; delete incomeLabels; delete shoppingItems; }
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())); }