X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fqt%2Ftransactionview.cpp;h=64891359d05b9c9a41a748ccdbc9fce64cd8d127;hb=2c8f88fc67af7916670ce0086e6a9078df8182f0;hp=0b2a3e6092067110b55b2f39f8f868b4bbca6ac8;hpb=856aacf388b2dd4c8213e699ff6377203a9194cc;p=novacoin.git diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 0b2a3e6..6489135 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -10,6 +10,7 @@ #include "transactiondescdialog.h" #include "editaddressdialog.h" #include "optionsmodel.h" +#include "guiutil.h" #include #include @@ -20,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -38,13 +38,20 @@ TransactionView::TransactionView(QWidget *parent) : QHBoxLayout *hlayout = new QHBoxLayout(); hlayout->setContentsMargins(0,0,0,0); +#ifdef Q_OS_MAC + hlayout->setSpacing(5); + hlayout->addSpacing(26); +#else hlayout->setSpacing(0); - hlayout->addSpacing(23); +#endif dateWidget = new QComboBox(this); - dateWidget->setMaximumWidth(120); - dateWidget->setMinimumWidth(120); +#ifdef Q_OS_MAC + dateWidget->setFixedWidth(121); +#else + dateWidget->setFixedWidth(120); +#endif dateWidget->addItem(tr("All"), All); dateWidget->addItem(tr("Today"), Today); dateWidget->addItem(tr("This week"), ThisWeek); @@ -55,14 +62,17 @@ TransactionView::TransactionView(QWidget *parent) : hlayout->addWidget(dateWidget); typeWidget = new QComboBox(this); - typeWidget->setMaximumWidth(120); - typeWidget->setMinimumWidth(120); +#ifdef Q_OS_MAC + typeWidget->setFixedWidth(121); +#else + typeWidget->setFixedWidth(120); +#endif typeWidget->addItem(tr("All"), TransactionFilterProxy::ALL_TYPES); typeWidget->addItem(tr("Received with"), TransactionFilterProxy::TYPE(TransactionRecord::RecvWithAddress) | - TransactionFilterProxy::TYPE(TransactionRecord::RecvFromIP)); + TransactionFilterProxy::TYPE(TransactionRecord::RecvFromOther)); typeWidget->addItem(tr("Sent to"), TransactionFilterProxy::TYPE(TransactionRecord::SendToAddress) | - TransactionFilterProxy::TYPE(TransactionRecord::SendToIP)); + TransactionFilterProxy::TYPE(TransactionRecord::SendToOther)); typeWidget->addItem(tr("To yourself"), TransactionFilterProxy::TYPE(TransactionRecord::SendToSelf)); typeWidget->addItem(tr("Mined"), TransactionFilterProxy::TYPE(TransactionRecord::Generated)); typeWidget->addItem(tr("Other"), TransactionFilterProxy::TYPE(TransactionRecord::Other)); @@ -71,23 +81,27 @@ TransactionView::TransactionView(QWidget *parent) : addressWidget = new QLineEdit(this); #if QT_VERSION >= 0x040700 - addressWidget->setPlaceholderText("Enter address or label to search"); + /* Do not move this to the XML file, Qt before 4.7 will choke on it */ + addressWidget->setPlaceholderText(tr("Enter address or label to search")); #endif hlayout->addWidget(addressWidget); amountWidget = new QLineEdit(this); #if QT_VERSION >= 0x040700 - amountWidget->setPlaceholderText("Min amount"); + /* Do not move this to the XML file, Qt before 4.7 will choke on it */ + amountWidget->setPlaceholderText(tr("Min amount")); +#endif +#ifdef Q_OS_MAC + amountWidget->setFixedWidth(97); +#else + amountWidget->setFixedWidth(100); #endif - amountWidget->setMaximumWidth(100); - amountWidget->setMinimumWidth(100); amountWidget->setValidator(new QDoubleValidator(0, 1e20, 8, this)); hlayout->addWidget(amountWidget); QVBoxLayout *vlayout = new QVBoxLayout(this); vlayout->setContentsMargins(0,0,0,0); vlayout->setSpacing(0); - //vlayout->addLayout(hlayout2); QTableView *view = new QTableView(this); vlayout->addLayout(hlayout); @@ -96,7 +110,11 @@ TransactionView::TransactionView(QWidget *parent) : vlayout->setSpacing(0); int width = view->verticalScrollBar()->sizeHint().width(); // Cover scroll bar width with spacing +#ifdef Q_OS_MAC + hlayout->addSpacing(width+2); +#else hlayout->addSpacing(width); +#endif // Always show scroll bar view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); view->setTabKeyNavigation(false); @@ -105,14 +123,18 @@ TransactionView::TransactionView(QWidget *parent) : transactionView = view; // Actions - QAction *copyAddressAction = new QAction("Copy address", this); - QAction *copyLabelAction = new QAction("Copy label", this); - QAction *editLabelAction = new QAction("Edit label", this); - QAction *showDetailsAction = new QAction("Show details...", this); + QAction *copyAddressAction = new QAction(tr("Copy address"), this); + QAction *copyLabelAction = new QAction(tr("Copy label"), this); + QAction *copyAmountAction = new QAction(tr("Copy amount"), this); + QAction *copyTxIDAction = new QAction(tr("Copy transaction ID"), this); + QAction *editLabelAction = new QAction(tr("Edit label"), this); + QAction *showDetailsAction = new QAction(tr("Show transaction details"), this); contextMenu = new QMenu(); contextMenu->addAction(copyAddressAction); contextMenu->addAction(copyLabelAction); + contextMenu->addAction(copyAmountAction); + contextMenu->addAction(copyTxIDAction); contextMenu->addAction(editLabelAction); contextMenu->addAction(showDetailsAction); @@ -123,14 +145,12 @@ TransactionView::TransactionView(QWidget *parent) : connect(amountWidget, SIGNAL(textChanged(QString)), this, SLOT(changedAmount(QString))); connect(view, SIGNAL(doubleClicked(QModelIndex)), this, SIGNAL(doubleClicked(QModelIndex))); - - connect(view, - SIGNAL(customContextMenuRequested(QPoint)), - this, - SLOT(contextualMenu(QPoint))); + connect(view, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextualMenu(QPoint))); connect(copyAddressAction, SIGNAL(triggered()), this, SLOT(copyAddress())); connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(copyLabel())); + connect(copyAmountAction, SIGNAL(triggered()), this, SLOT(copyAmount())); + connect(copyTxIDAction, SIGNAL(triggered()), this, SLOT(copyTxID())); connect(editLabelAction, SIGNAL(triggered()), this, SLOT(editLabel())); connect(showDetailsAction, SIGNAL(triggered()), this, SLOT(showDetails())); } @@ -138,36 +158,41 @@ TransactionView::TransactionView(QWidget *parent) : void TransactionView::setModel(WalletModel *model) { this->model = model; - - transactionProxyModel = new TransactionFilterProxy(this); - transactionProxyModel->setSourceModel(model->getTransactionTableModel()); - transactionProxyModel->setDynamicSortFilter(true); - - transactionProxyModel->setSortRole(Qt::EditRole); - - transactionView->setModel(transactionProxyModel); - transactionView->setAlternatingRowColors(true); - transactionView->setSelectionBehavior(QAbstractItemView::SelectRows); - transactionView->setSelectionMode(QAbstractItemView::ExtendedSelection); - transactionView->setSortingEnabled(true); - transactionView->sortByColumn(TransactionTableModel::Status, Qt::DescendingOrder); - transactionView->verticalHeader()->hide(); - - transactionView->horizontalHeader()->resizeSection( - TransactionTableModel::Status, 23); - transactionView->horizontalHeader()->resizeSection( - TransactionTableModel::Date, 120); - transactionView->horizontalHeader()->resizeSection( - TransactionTableModel::Type, 120); - transactionView->horizontalHeader()->setResizeMode( - TransactionTableModel::ToAddress, QHeaderView::Stretch); - transactionView->horizontalHeader()->resizeSection( - TransactionTableModel::Amount, 100); - + if(model) + { + transactionProxyModel = new TransactionFilterProxy(this); + transactionProxyModel->setSourceModel(model->getTransactionTableModel()); + transactionProxyModel->setDynamicSortFilter(true); + transactionProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); + transactionProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); + + transactionProxyModel->setSortRole(Qt::EditRole); + + transactionView->setModel(transactionProxyModel); + transactionView->setAlternatingRowColors(true); + transactionView->setSelectionBehavior(QAbstractItemView::SelectRows); + transactionView->setSelectionMode(QAbstractItemView::ExtendedSelection); + transactionView->setSortingEnabled(true); + transactionView->sortByColumn(TransactionTableModel::Status, Qt::DescendingOrder); + transactionView->verticalHeader()->hide(); + + transactionView->horizontalHeader()->resizeSection( + TransactionTableModel::Status, 23); + transactionView->horizontalHeader()->resizeSection( + TransactionTableModel::Date, 120); + transactionView->horizontalHeader()->resizeSection( + TransactionTableModel::Type, 120); + transactionView->horizontalHeader()->setResizeMode( + TransactionTableModel::ToAddress, QHeaderView::Stretch); + transactionView->horizontalHeader()->resizeSection( + TransactionTableModel::Amount, 100); + } } void TransactionView::chooseDate(int idx) { + if(!transactionProxyModel) + return; QDate current = QDate::currentDate(); dateRangeWidget->setVisible(false); switch(dateWidget->itemData(idx).toInt()) @@ -183,7 +208,7 @@ void TransactionView::chooseDate(int idx) TransactionFilterProxy::MAX_DATE); break; case ThisWeek: { - // Find last monday + // Find last Monday QDate startOfWeek = current.addDays(-(current.dayOfWeek()-1)); transactionProxyModel->setDateRange( QDateTime(startOfWeek), @@ -214,17 +239,23 @@ void TransactionView::chooseDate(int idx) void TransactionView::chooseType(int idx) { + if(!transactionProxyModel) + return; transactionProxyModel->setTypeFilter( typeWidget->itemData(idx).toInt()); } void TransactionView::changedPrefix(const QString &prefix) { + if(!transactionProxyModel) + return; transactionProxyModel->setAddressPrefix(prefix); } void TransactionView::changedAmount(const QString &amount) { + if(!transactionProxyModel) + return; qint64 amount_parsed = 0; if(BitcoinUnits::parse(model->getOptionsModel()->getDisplayUnit(), amount, &amount_parsed)) { @@ -239,10 +270,9 @@ void TransactionView::changedAmount(const QString &amount) void TransactionView::exportClicked() { // CSV is currently the only supported format - QString filename = QFileDialog::getSaveFileName( + QString filename = GUIUtil::getSaveFileName( this, - tr("Export Transaction Data"), - QDir::currentPath(), + tr("Export Transaction Data"), QString(), tr("Comma separated file (*.csv)")); if (filename.isNull()) return; @@ -251,13 +281,13 @@ void TransactionView::exportClicked() // name, column, role writer.setModel(transactionProxyModel); - writer.addColumn("Confirmed", 0, TransactionTableModel::ConfirmedRole); - writer.addColumn("Date", 0, TransactionTableModel::DateRole); - writer.addColumn("Type", TransactionTableModel::Type, Qt::EditRole); - writer.addColumn("Label", 0, TransactionTableModel::LabelRole); - writer.addColumn("Address", 0, TransactionTableModel::AddressRole); - writer.addColumn("Amount", 0, TransactionTableModel::FormattedAmountRole); - writer.addColumn("ID", 0, TransactionTableModel::TxIDRole); + writer.addColumn(tr("Confirmed"), 0, TransactionTableModel::ConfirmedRole); + writer.addColumn(tr("Date"), 0, TransactionTableModel::DateRole); + writer.addColumn(tr("Type"), TransactionTableModel::Type, Qt::EditRole); + writer.addColumn(tr("Label"), 0, TransactionTableModel::LabelRole); + writer.addColumn(tr("Address"), 0, TransactionTableModel::AddressRole); + writer.addColumn(tr("Amount"), 0, TransactionTableModel::FormattedAmountRole); + writer.addColumn(tr("ID"), 0, TransactionTableModel::TxIDRole); if(!writer.write()) { @@ -277,34 +307,42 @@ void TransactionView::contextualMenu(const QPoint &point) void TransactionView::copyAddress() { - QModelIndexList selection = transactionView->selectionModel()->selectedRows(); - if(!selection.isEmpty()) - { - QApplication::clipboard()->setText(selection.at(0).data(TransactionTableModel::AddressRole).toString()); - } + GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::AddressRole); } void TransactionView::copyLabel() { - QModelIndexList selection = transactionView->selectionModel()->selectedRows(); - if(!selection.isEmpty()) - { - QApplication::clipboard()->setText(selection.at(0).data(TransactionTableModel::LabelRole).toString()); - } + GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::LabelRole); +} + +void TransactionView::copyAmount() +{ + GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::FormattedAmountRole); +} + +void TransactionView::copyTxID() +{ + GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::TxIDRole); } void TransactionView::editLabel() { + if(!transactionView->selectionModel() ||!model) + return; QModelIndexList selection = transactionView->selectionModel()->selectedRows(); if(!selection.isEmpty()) { AddressTableModel *addressBook = model->getAddressTableModel(); + if(!addressBook) + return; QString address = selection.at(0).data(TransactionTableModel::AddressRole).toString(); if(address.isEmpty()) { // If this transaction has no associated address, exit return; } + // Is address in address book? Address book can miss address when a transaction is + // sent from outside the UI. int idx = addressBook->lookupAddress(address); if(idx != -1) { @@ -326,6 +364,8 @@ void TransactionView::editLabel() // Add sending address EditAddressDialog dlg(EditAddressDialog::NewSendingAddress, this); + dlg.setModel(addressBook); + dlg.setAddress(address); dlg.exec(); } } @@ -333,6 +373,8 @@ void TransactionView::editLabel() void TransactionView::showDetails() { + if(!transactionView->selectionModel()) + return; QModelIndexList selection = transactionView->selectionModel()->selectedRows(); if(!selection.isEmpty()) { @@ -349,7 +391,7 @@ QWidget *TransactionView::createDateRangeWidget() QHBoxLayout *layout = new QHBoxLayout(dateRangeWidget); layout->setContentsMargins(0,0,0,0); layout->addSpacing(23); - layout->addWidget(new QLabel("Range:")); + layout->addWidget(new QLabel(tr("Range:"))); dateFrom = new QDateTimeEdit(this); dateFrom->setDisplayFormat("dd/MM/yy"); @@ -357,7 +399,7 @@ QWidget *TransactionView::createDateRangeWidget() dateFrom->setMinimumWidth(100); dateFrom->setDate(QDate::currentDate().addDays(-7)); layout->addWidget(dateFrom); - layout->addWidget(new QLabel("to")); + layout->addWidget(new QLabel(tr("to"))); dateTo = new QDateTimeEdit(this); dateTo->setDisplayFormat("dd/MM/yy"); @@ -379,7 +421,19 @@ QWidget *TransactionView::createDateRangeWidget() void TransactionView::dateRangeChanged() { + if(!transactionProxyModel) + return; transactionProxyModel->setDateRange( QDateTime(dateFrom->date()), QDateTime(dateTo->date()).addDays(1)); } + +void TransactionView::focusTransaction(const QModelIndex &idx) +{ + if(!transactionProxyModel) + return; + QModelIndex targetIdx = transactionProxyModel->mapFromSource(idx); + transactionView->scrollTo(targetIdx); + transactionView->setCurrentIndex(targetIdx); + transactionView->setFocus(); +}