Commit 5ab2383de03415b763cfda58a98d90ccad53067f
- Diff rendering mode:
- inline
- side by side
src/expensesgraph.cpp
(20 / 19)
|   | |||
| 2 | 2 | #include <QPainter> | |
| 3 | 3 | #include <QListIterator> | |
| 4 | 4 | #include <QPen> | |
| 5 | #include <QDate> | ||
| 5 | 6 | ||
| 6 | 7 | #include "expensesgraph.h" | |
| 7 | 8 | #include "expense.h" | |
| … | … | ||
| 19 | 19 | { | |
| 20 | 20 | _padding = 10; | |
| 21 | 21 | _accumulated = true; | |
| 22 | _month = NULL; | ||
| 22 | _model = NULL; | ||
| 23 | 23 | } | |
| 24 | 24 | ||
| 25 | 25 | void ExpensesGraph::setPadding(int padding) | |
| … | … | ||
| 28 | 28 | repaint(); | |
| 29 | 29 | } | |
| 30 | 30 | ||
| 31 | void ExpensesGraph::setMonthData(MonthData *month) | ||
| 31 | void ExpensesGraph::setModel(ExpensesGraphModel *model) | ||
| 32 | 32 | { | |
| 33 | _month = month; | ||
| 33 | _model = model; | ||
| 34 | 34 | } | |
| 35 | 35 | ||
| 36 | 36 | void ExpensesGraph::setAccumulated(bool accumulated) | |
| … | … | ||
| 81 | 81 | ||
| 82 | 82 | drawScene(painter); | |
| 83 | 83 | ||
| 84 | if (_month) { | ||
| 84 | if (_model) { | ||
| 85 | 85 | /* labels in x axis */ | |
| 86 | xStepsPerLabel = _month->days() / qMin(sceneWidth / X_LABEL_WIDTH, _month->days()); | ||
| 86 | xStepsPerLabel = _model->xDivisions() / qMin(sceneWidth / X_LABEL_WIDTH, _model->xDivisions()); | ||
| 87 | 87 | /* labels in y axis. not more than 10 */ | |
| 88 | 88 | yStepsPerLabel = Y_DIVISIONS / qMin(sceneHeight / Y_LABEL_HEIGHT, Y_DIVISIONS); | |
| 89 | 89 | ||
| 90 | dailyExpense = _month->budget() / _month->days(); | ||
| 90 | dailyExpense = _model->budget() / _model->xDivisions(); | ||
| 91 | 91 | if (_accumulated) { | |
| 92 | if (_month->budget() >= _month->totalExpense()) { | ||
| 93 | yMaxValue = _month->budget(); | ||
| 92 | if (_model->budget() >= _model->totalExpense()) { | ||
| 93 | yMaxValue = _model->budget(); | ||
| 94 | 94 | } else { | |
| 95 | aux = _month->totalExpense() / 100; | ||
| 95 | aux = _model->totalExpense() / 100; | ||
| 96 | 96 | yMaxValue = (aux + 1) * 100; | |
| 97 | 97 | } | |
| 98 | 98 | } else { | |
| 99 | aux = qMax(_month->maxExpense(), dailyExpense) / 100; | ||
| 99 | aux = qMax(_model->maxExpense(), dailyExpense) / 100; | ||
| 100 | 100 | yMaxValue = (aux + 1) * 100; | |
| 101 | 101 | } | |
| 102 | 102 | yScale = sceneHeight / (double)yMaxValue; | |
| 103 | 103 | ||
| 104 | xStep = sceneWidth / (double)(_month->days()-1); | ||
| 104 | xStep = sceneWidth / (double)(_model->xDivisions()-1); | ||
| 105 | 105 | yStep = sceneHeight / (double)Y_DIVISIONS; | |
| 106 | 106 | ||
| 107 | 107 | painter.setRenderHint(QPainter::Antialiasing); | |
| … | … | ||
| 165 | 165 | QString("1")); | |
| 166 | 166 | painter.setPen(pen); | |
| 167 | 167 | x = xStart + (xStep *xStepsPerLabel); | |
| 168 | for (i = xStepsPerLabel + 1; i<=_month->days(); i+=xStepsPerLabel) { | ||
| 169 | if (i != _month->days()) { | ||
| 168 | for (i = xStepsPerLabel + 1; i<=_model->xDivisions(); i+=xStepsPerLabel) { | ||
| 169 | if (i != _model->xDivisions()) { | ||
| 170 | 170 | painter.drawLine (qRound(x), yStart, qRound(x), yEnd); | |
| 171 | 171 | } | |
| 172 | 172 | painter.setPen(Qt::white); | |
| … | … | ||
| 181 | 181 | } | |
| 182 | 182 | ||
| 183 | 183 | /* current */ | |
| 184 | if (_month->isCurrent()) { | ||
| 184 | if (_model->isCurrent()) { | ||
| 185 | 185 | i = QDate::currentDate().day() - 1; | |
| 186 | 186 | painter.setPen (Qt::yellow); | |
| 187 | 187 | painter.drawLine (qRound(xStart + (i * xStep)), | |
| … | … | ||
| 203 | 203 | painter.drawLine (xStart + 1, | |
| 204 | 204 | qRound(yStart - (dailyExpense * yScale)), | |
| 205 | 205 | xEnd, | |
| 206 | qRound(yStart - (_month->budget() * yScale))); | ||
| 206 | qRound(yStart - (_model->budget() * yScale))); | ||
| 207 | 207 | } else { | |
| 208 | 208 | painter.drawLine (xStart + 1, | |
| 209 | 209 | qRound(yStart - (dailyExpense * yScale)), | |
| … | … | ||
| 224 | 224 | y = yStart; | |
| 225 | 225 | path.moveTo (x, y); | |
| 226 | 226 | ||
| 227 | for (i=1; i<=_month->days(); i++) { | ||
| 227 | for (i=0; i<_model->xDivisions(); i++) { | ||
| 228 | 228 | if (_accumulated) { | |
| 229 | y -= _month->summary()[i] * yScale; | ||
| 229 | y -= _model->value(i) * yScale; | ||
| 230 | 230 | } else { | |
| 231 | y = yStart - (_month->summary()[i] * yScale); | ||
| 231 | y = yStart - (_model->value(i) * yScale); | ||
| 232 | 232 | } | |
| 233 | if (i == 1) { | ||
| 233 | if (i == 0) { | ||
| 234 | 234 | path.moveTo (x, y); | |
| 235 | 235 | } else { | |
| 236 | 236 | path.lineTo (x, y); |
src/expensesgraph.h
(3 / 3)
|   | |||
| 3 | 3 | ||
| 4 | 4 | #include <QWidget> | |
| 5 | 5 | #include <QList> | |
| 6 | #include "monthdata.h" | ||
| 6 | #include "expensesgraphmodel.h" | ||
| 7 | 7 | ||
| 8 | 8 | class ExpensesGraph : public QWidget | |
| 9 | 9 | { | |
| … | … | ||
| 15 | 15 | QSize sizeHint() const; | |
| 16 | 16 | ||
| 17 | 17 | void setPadding(int padding); | |
| 18 | void setMonthData(MonthData *month); | ||
| 18 | void setModel(ExpensesGraphModel *model); | ||
| 19 | 19 | void setAccumulated(bool accumulated); | |
| 20 | 20 | bool accumulated(); | |
| 21 | 21 | ||
| … | … | ||
| 33 | 33 | ||
| 34 | 34 | int _padding; | |
| 35 | 35 | bool _accumulated; | |
| 36 | MonthData *_month; | ||
| 36 | ExpensesGraphModel *_model; | ||
| 37 | 37 | int xStart, yStart; | |
| 38 | 38 | int sceneWidth, sceneHeight; | |
| 39 | 39 | int xEnd, yEnd; |
src/mainwindow.cpp
(1 / 1)
|   | |||
| 79 | 79 | { | |
| 80 | 80 | month = data; | |
| 81 | 81 | /* set data to the graph as well */ | |
| 82 | graph->setMonthData(data); | ||
| 82 | graph->setModel(data); | ||
| 83 | 83 | connect(month, SIGNAL(expensesChanged()), this, SLOT(expensesChanged())); | |
| 84 | 84 | connect(month, SIGNAL(budgetChanged()), this, SLOT(budgetChanged())); | |
| 85 | 85 |
src/monthdata.cpp
(12 / 7)
|   | |||
| 4 | 4 | MonthData::MonthData(QDate date, | |
| 5 | 5 | Account *account, | |
| 6 | 6 | QObject *parent) | |
| 7 | : QObject(parent) | ||
| 7 | : ExpensesGraphModel(parent) | ||
| 8 | 8 | { | |
| 9 | 9 | _date = date; | |
| 10 | 10 | _account = account; | |
| 11 | 11 | _budget = account->budget(); | |
| 12 | 12 | _maxExpense = 0; | |
| 13 | 13 | _totalExpense = 0; | |
| 14 | _summary.resize(_date.daysInMonth() + 1); | ||
| 14 | _summary.resize(_date.daysInMonth()); | ||
| 15 | 15 | _summary.fill(0); | |
| 16 | 16 | _expenses = new QStandardItemModel(0,5); | |
| 17 | 17 | } | |
| … | … | ||
| 53 | 53 | ||
| 54 | 54 | void MonthData::addExpense(Expense *e) | |
| 55 | 55 | { | |
| 56 | _summary[e->day()] += e->amount(); | ||
| 56 | _summary[e->day() - 1] += e->amount(); | ||
| 57 | 57 | _totalExpense += e->amount(); | |
| 58 | if (_summary[e->day()] > _maxExpense) { | ||
| 59 | _maxExpense = _summary[e->day()]; | ||
| 58 | if (_summary[e->day() - 1] > _maxExpense) { | ||
| 59 | _maxExpense = _summary[e->day() - 1]; | ||
| 60 | 60 | } | |
| 61 | 61 | ||
| 62 | 62 | QStandardItem *item; | |
| … | … | ||
| 124 | 124 | return _date; | |
| 125 | 125 | } | |
| 126 | 126 | ||
| 127 | const QVector<double>& MonthData::summary() | ||
| 127 | double MonthData::value(int index) | ||
| 128 | 128 | { | |
| 129 | return _summary; | ||
| 129 | return _summary[index]; | ||
| 130 | 130 | } | |
| 131 | 131 | ||
| 132 | 132 | void MonthData::clear() | |
| … | … | ||
| 137 | 137 | _totalExpense = 0; | |
| 138 | 138 | ||
| 139 | 139 | emit expensesChanged(); | |
| 140 | } | ||
| 141 | |||
| 142 | int MonthData::xDivisions() | ||
| 143 | { | ||
| 144 | return _date.daysInMonth(); | ||
| 140 | 145 | } |
src/monthdata.h
(4 / 4)
|   | |||
| 7 | 7 | #include <QStandardItemModel> | |
| 8 | 8 | #include <QDate> | |
| 9 | 9 | #include <QDebug> | |
| 10 | #include "expensesgraphmodel.h" | ||
| 10 | 11 | #include "expense.h" | |
| 11 | 12 | #include "global.h" | |
| 12 | 13 | #include "account.h" | |
| 13 | 14 | ||
| 14 | class MonthData : public QObject | ||
| 15 | class MonthData : public ExpensesGraphModel | ||
| 15 | 16 | { | |
| 16 | 17 | Q_OBJECT | |
| 17 | 18 | public: | |
| … | … | ||
| 31 | 31 | double maxExpense(); | |
| 32 | 32 | double totalExpense(); | |
| 33 | 33 | QStandardItemModel* expenses(); | |
| 34 | const QVector<double>& summary(); | ||
| 34 | double value(int i); | ||
| 35 | 35 | QDate next(); | |
| 36 | 36 | QDate previous(); | |
| 37 | 37 | bool isCurrent(); | |
| 38 | 38 | QDate date(); | |
| 39 | 39 | void clear(); | |
| 40 | int xDivisions(); | ||
| 40 | 41 | ||
| 41 | 42 | signals: | |
| 42 | void expensesChanged(); | ||
| 43 | void budgetChanged(); | ||
| 44 | 43 | ||
| 45 | 44 | private: | |
| 46 | 45 |
src/src.pro
(2 / 0)
|   | |||
| 15 | 15 | monthdata.h \ | |
| 16 | 16 | controller.h \ | |
| 17 | 17 | expensesgraph.h \ | |
| 18 | expensesgraphmodel.h \ | ||
| 18 | 19 | expensedetailsdialog.h \ | |
| 19 | 20 | budgetdialog.h \ | |
| 20 | 21 | conceptsdialog.h \ | |
| … | … | ||
| 41 | 41 | controller.cpp \ | |
| 42 | 42 | mainwindow.cpp \ | |
| 43 | 43 | expensesgraph.cpp \ | |
| 44 | expensesgraphmodel.cpp \ | ||
| 44 | 45 | expensedetailsdialog.cpp \ | |
| 45 | 46 | budgetdialog.cpp \ | |
| 46 | 47 | conceptsdialog.cpp \ |
src/summarydata.cpp
(26 / 2)
|   | |||
| 3 | 3 | SummaryData::SummaryData(int startYear, | |
| 4 | 4 | int startMonth, | |
| 5 | 5 | int endYear, | |
| 6 | int endMonth) | ||
| 6 | int endMonth, | ||
| 7 | QObject *parent) | ||
| 8 | : ExpensesGraphModel(parent) | ||
| 7 | 9 | { | |
| 8 | 10 | _startYear = startYear; | |
| 9 | 11 | _startMonth = startMonth; | |
| … | … | ||
| 55 | 55 | _totalExpense += expense; | |
| 56 | 56 | int saved = budget - expense; | |
| 57 | 57 | _totalSaved += saved; | |
| 58 | _monthCount ++; | ||
| 59 | 58 | ||
| 59 | _values.append(expense); | ||
| 60 | |||
| 60 | 61 | if (expense > _maxExpense) { | |
| 61 | 62 | _maxExpense = expense; | |
| 62 | 63 | } | |
| … | … | ||
| 73 | 73 | if (saved < _minSaved) { | |
| 74 | 74 | _minSaved = saved; | |
| 75 | 75 | } | |
| 76 | _monthCount ++; | ||
| 76 | 77 | } | |
| 77 | 78 | ||
| 78 | 79 | double SummaryData::totalBudget() | |
| … | … | ||
| 129 | 129 | const QList<Concept*>& SummaryData::concepts() | |
| 130 | 130 | { | |
| 131 | 131 | return _concepts; | |
| 132 | } | ||
| 133 | |||
| 134 | double SummaryData::budget() | ||
| 135 | { | ||
| 136 | return _totalBudget; | ||
| 137 | } | ||
| 138 | |||
| 139 | bool SummaryData::isCurrent() | ||
| 140 | { | ||
| 141 | return false; | ||
| 142 | } | ||
| 143 | |||
| 144 | int SummaryData::xDivisions() | ||
| 145 | { | ||
| 146 | return _monthCount; | ||
| 147 | } | ||
| 148 | |||
| 149 | double SummaryData::value(int index) | ||
| 150 | { | ||
| 151 | return _values.value(index); | ||
| 132 | 152 | } |
src/summarydata.h
(11 / 2)
|   | |||
| 3 | 3 | ||
| 4 | 4 | #include <QObject> | |
| 5 | 5 | #include <QList> | |
| 6 | #include "expensesgraphmodel.h" | ||
| 6 | 7 | #include "concept.h" | |
| 7 | 8 | ||
| 8 | class SummaryData : public QObject | ||
| 9 | class SummaryData : public ExpensesGraphModel | ||
| 9 | 10 | { | |
| 10 | 11 | Q_OBJECT | |
| 11 | 12 | public: | |
| 12 | 13 | SummaryData(int startYear, | |
| 13 | 14 | int startMonth, | |
| 14 | 15 | int endYear, | |
| 15 | int endMonth); | ||
| 16 | int endMonth, | ||
| 17 | QObject *parent = 0); | ||
| 16 | 18 | ~SummaryData(); | |
| 17 | 19 | ||
| 18 | 20 | int startYear(); | |
| … | … | ||
| 35 | 35 | void addMonthData(double budget, double expense); | |
| 36 | 36 | void addConcept(Concept *c); | |
| 37 | 37 | ||
| 38 | /* form ExpensesGraphModel */ | ||
| 39 | double budget(); | ||
| 40 | bool isCurrent(); | ||
| 41 | int xDivisions(); | ||
| 42 | double value(int i); | ||
| 43 | |||
| 38 | 44 | const QList<Concept*>& concepts(); | |
| 39 | 45 | ||
| 40 | 46 | private: | |
| … | … | ||
| 61 | 61 | int _monthCount; | |
| 62 | 62 | ||
| 63 | 63 | QList<Concept*> _concepts; | |
| 64 | QList<double> _values; | ||
| 64 | 65 | }; | |
| 65 | 66 | ||
| 66 | 67 | #endif |
src/summarywindow.cpp
(29 / 0)
|   | |||
| 21 | 21 | connect(statistics, SIGNAL(triggered()), this, SLOT(statisticsSelected())); | |
| 22 | 22 | QAction *items = new QAction(tr("Items"), actionGroup); | |
| 23 | 23 | connect(items, SIGNAL(triggered()), this, SLOT(itemsSelected())); | |
| 24 | QAction *evolution = new QAction(tr("Evolution"), actionGroup); | ||
| 25 | connect(evolution, SIGNAL(triggered()), this, SLOT(evolutionSelected())); | ||
| 24 | 26 | ||
| 25 | 27 | QMenuBar *menuBar = new QMenuBar(this); | |
| 26 | 28 | menuBar->addAction(statistics); | |
| 27 | 29 | menuBar->addAction(items); | |
| 30 | menuBar->addAction(evolution); | ||
| 28 | 31 | ||
| 29 | 32 | summaryData = NULL; | |
| 30 | 33 | ||
| 31 | 34 | statistics->setCheckable(true); | |
| 32 | 35 | items->setCheckable(true); | |
| 36 | evolution->setCheckable(true); | ||
| 33 | 37 | ||
| 34 | 38 | /* statistics mode stuff */ | |
| 35 | 39 | statsBox = new QFrame(); | |
| … | … | ||
| 79 | 79 | chart = new ConceptsChart(); | |
| 80 | 80 | vbox->addWidget(chart, 1); | |
| 81 | 81 | ||
| 82 | graph = new ExpensesGraph(); | ||
| 83 | vbox->addWidget(graph, 1); | ||
| 84 | |||
| 82 | 85 | /* set statistics mode by default */ | |
| 83 | 86 | statistics->setChecked(true); | |
| 84 | 87 | chart->hide(); | |
| 88 | graph->hide(); | ||
| 85 | 89 | } | |
| 86 | 90 | ||
| 87 | 91 | SummaryWindow::~SummaryWindow() | |
| … | … | ||
| 99 | 99 | { | |
| 100 | 100 | statsBox->show(); | |
| 101 | 101 | chart->hide(); | |
| 102 | graph->hide(); | ||
| 102 | 103 | } | |
| 103 | 104 | ||
| 104 | 105 | void SummaryWindow::itemsSelected() | |
| 105 | 106 | { | |
| 106 | 107 | statsBox->hide(); | |
| 107 | 108 | chart->show(); | |
| 109 | graph->hide(); | ||
| 108 | 110 | } | |
| 109 | 111 | ||
| 112 | void SummaryWindow::evolutionSelected() | ||
| 113 | { | ||
| 114 | statsBox->hide(); | ||
| 115 | chart->hide(); | ||
| 116 | graph->show(); | ||
| 117 | } | ||
| 118 | |||
| 110 | 119 | void SummaryWindow::setSummaryData(SummaryData *data) | |
| 111 | 120 | { | |
| 112 | 121 | if (summaryData != NULL) { | |
| … | … | ||
| 155 | 155 | chart->repaint(); | |
| 156 | 156 | } | |
| 157 | 157 | ||
| 158 | graph->setModel(summaryData); | ||
| 159 | if (graph->isVisible()) { | ||
| 160 | graph->repaint(); | ||
| 161 | } | ||
| 162 | |||
| 158 | 163 | if (summaryData->totalExpense() == 0) { | |
| 159 | 164 | QMaemo5InformationBox::information(this, tr("Warning: there are no expenses stored in the selected period")); | |
| 165 | } | ||
| 166 | } | ||
| 167 | |||
| 168 | void SummaryWindow::mousePressEvent(QMouseEvent *event) | ||
| 169 | { | ||
| 170 | if (graph->isVisible()) { | ||
| 171 | graph->changeView(); | ||
| 160 | 172 | } | |
| 161 | 173 | } |
src/summarywindow.h
(6 / 0)
|   | |||
| 7 | 7 | #include "periodwindow.h" | |
| 8 | 8 | #include "summarydata.h" | |
| 9 | 9 | #include "conceptschart.h" | |
| 10 | #include "expensesgraph.h" | ||
| 10 | 11 | #include <QAction> | |
| 11 | 12 | #include <QFrame> | |
| 12 | 13 | ||
| … | … | ||
| 23 | 23 | ~SummaryWindow(); | |
| 24 | 24 | void setSummaryData(SummaryData *data); | |
| 25 | 25 | ||
| 26 | protected: | ||
| 27 | void mousePressEvent(QMouseEvent *event); | ||
| 28 | |||
| 26 | 29 | private slots: | |
| 27 | 30 | void statisticsSelected(); | |
| 28 | 31 | void itemsSelected(); | |
| 32 | void evolutionSelected(); | ||
| 29 | 33 | ||
| 30 | 34 | private: | |
| 31 | 35 | QAction *statistics; | |
| … | … | ||
| 49 | 49 | ||
| 50 | 50 | /* items stuff */ | |
| 51 | 51 | ConceptsChart *chart; | |
| 52 | ExpensesGraph *graph; | ||
| 52 | 53 | ||
| 53 | 54 | SummaryData *summaryData; | |
| 54 | 55 |

