diff --git a/src/addressbook.h b/src/addressbook.h index 41f9ff9..e7a45fc 100644 --- a/src/addressbook.h +++ b/src/addressbook.h @@ -10,9 +10,9 @@ class AddressBookModel : public QAbstractTableModel { public: AddressBookModel(QTableView* parent); ~AddressBookModel(); - - void addNewLabel(QString label, QString addr); - void removeItemAt(int row); + + void addNewLabel(QString label, QString addr); + void removeItemAt(int row); QPair itemAt(int row); int rowCount(const QModelIndex &parent) const; diff --git a/src/recurring.cpp b/src/recurring.cpp index 2f1178e..e01afbd 100644 --- a/src/recurring.cpp +++ b/src/recurring.cpp @@ -38,6 +38,7 @@ RecurringPaymentInfo RecurringPaymentInfo::fromJson(QJsonObject j) { item.paymentNumber = h.toObject()["paymentnumber"].toInt(); item.date = QDateTime::fromSecsSinceEpoch(h.toObject()["date"].toString().toLongLong()); item.txid = h.toObject()["txid"].toString(); + item.status = h.toObject()["status"].toString(); r.history.append(item); } @@ -56,7 +57,8 @@ QJsonObject RecurringPaymentInfo::toJson() { historyJson.append(QJsonObject{ {"paymentnumber", h.paymentNumber}, {"date", QString::number(h.date.toSecsSinceEpoch())}, - {"txid", h.txid} + {"txid", h.txid}, + {"status", h.status} }); } @@ -79,8 +81,12 @@ QJsonObject RecurringPaymentInfo::toJson() { return j; } +QString RecurringPaymentInfo::getAmountPretty() { + return currency == "USD" ? Settings::getUSDFormat(amt) : Settings::getZECDisplayFormat(amt); +} + QString RecurringPaymentInfo::getScheduleDescription() { - return "Pay " % (currency == "USD" ? Settings::getUSDFormat(amt) : Settings::getZECDisplayFormat(amt)) + return "Pay " % getAmountPretty() % " every " % schedule_desc(schedule) % ", starting " % startDate.toString("yyyy-MMM-dd") % ", for " % QString::number(numPayments) % " payments"; } @@ -150,12 +156,7 @@ RecurringPaymentInfo* Recurring::getNewRecurringFromTx(QWidget* parent, MainWind ui.txtMemo->setPlainText(rpi->memo); ui.cmbCurrency->setCurrentText(rpi->currency); - if (rpi->currency == "USD") { - ui.txtAmt->setText(Settings::getUSDFormat(rpi->amt)); - } - else { - ui.txtAmt->setText(Settings::getDecimalString(rpi->amt)); - } + ui.txtAmt->setText(rpi->getAmountPretty()); ui.cmbFromAddress->setCurrentText(rpi->fromAddr); ui.txtNumPayments->setText(QString::number(rpi->numPayments)); ui.cmbSchedule->setCurrentIndex(rpi->schedule); @@ -250,4 +251,37 @@ void Recurring::writeToStorage() { } // Singleton -Recurring* Recurring::instance = nullptr; \ No newline at end of file +Recurring* Recurring::instance = nullptr; + + +RecurringListViewModel::RecurringListViewModel(QTableView* parent) { + this->parent = parent; + headers << tr("To") << tr("Amount") << tr("Schedule") << tr("Payments Left"); +} + + +int RecurringListViewModel::rowCount(const QModelIndex &parent) const { + return Recurring::getInstance()->getAsList().size(); +} + +int RecurringListViewModel::columnCount(const QModelIndex &parent) const { + return headers.size(); +} + +QVariant RecurringListViewModel::data(const QModelIndex &index, int role) const { + auto rpi = Recurring::getInstance()->getAsList().at(index.row()); + if (role == Qt::DisplayRole) { + switch (index.column()) { + case 0: return rpi.toAddr; + case 1: return rpi.getAmountPretty(); + case 2: return schedule_desc(rpi.schedule); + case 3: return rpi.numPayments - rpi.completedPayments; + } + } + + return QVariant(); +} + +QVariant RecurringListViewModel::headerData(int section, Qt::Orientation orientation, int role) const { + return QVariant(); +} \ No newline at end of file diff --git a/src/recurring.h b/src/recurring.h index 4eceae2..2ea1ca2 100644 --- a/src/recurring.h +++ b/src/recurring.h @@ -33,9 +33,10 @@ struct RecurringPaymentInfo { int completedPayments; struct HistoryItem { - int paymentNumber; - QDateTime date; - QString txid; + int paymentNumber; + QDateTime date; + QString txid; + QString status; }; QList history; @@ -44,6 +45,9 @@ struct RecurringPaymentInfo { QString getScheduleDescription(); QJsonObject toJson(); + + QString getAmountPretty(); + static RecurringPaymentInfo fromJson(QJsonObject j); }; @@ -61,6 +65,8 @@ public: void addRecurringInfo(const RecurringPaymentInfo& rpi); void writeToStorage(); + + QList getAsList() { return payments.values(); } private: Recurring() = default; QMap payments; @@ -69,4 +75,20 @@ private: }; +class RecurringListViewModel : public QAbstractTableModel { + +public: + RecurringListViewModel(QTableView* parent); + ~RecurringListViewModel() = default; + + int rowCount(const QModelIndex &parent) const; + int columnCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + +private: + QTableView* parent; + QStringList headers; +}; + #endif // RECURRING_H \ No newline at end of file