From 1febb18495a1f45cacb38cf811a4cdae0df5f12b Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Sun, 10 Mar 2019 23:48:56 -0400 Subject: [PATCH] Added log details to the call activity menu --- logbook/adif.cpp | 21 +++++++++++++----- logbook/adif.h | 11 ++++++--- logbook/logbook.cpp | 54 ++++++++++++++++++++++++++++++++++----------- logbook/logbook.h | 9 +++++++- mainwindow.cpp | 52 ++++++++++++++++++++++++++++++++++--------- mainwindow.ui | 15 +++++++++---- 6 files changed, 125 insertions(+), 37 deletions(-) diff --git a/logbook/adif.cpp b/logbook/adif.cpp index 20ef842..ba46ef5 100644 --- a/logbook/adif.cpp +++ b/logbook/adif.cpp @@ -101,14 +101,17 @@ void ADIF::load() , extractField (record, "BAND") , extractField (record, "MODE") , extractField (record, "SUBMODE") - , extractField (record, "QSO_DATE")); + , extractField (record, "QSO_DATE") + , extractField (record, "NAME") + , extractField (record, "COMMENT") + ); } inputFile.close (); } } -void ADIF::add(QString const& call, QString const& band, QString const& mode, QString const& submode, QString const& date) +void ADIF::add(QString const& call, QString const& band, QString const& mode, QString const& submode, QString const& date, QString const& name, QString const& comment) { QSO q; q.call = call; @@ -116,6 +119,9 @@ void ADIF::add(QString const& call, QString const& band, QString const& mode, QS q.mode = mode; q.submode = submode; q.date = date; + q.name = name; + q.comment = comment; + if (q.call.size ()) { _data.insert(q.call,q); @@ -135,13 +141,18 @@ bool ADIF::match(QString const& call, QString const& band) const if ( (band.compare(q.band,Qt::CaseInsensitive) == 0) || (band=="") || (q.band=="")) - { + { return true; } } } return false; -} +} + +QList ADIF::find(QString const& call) const +{ + return _data.values(call); +} QList ADIF::getCallList() const { @@ -154,8 +165,6 @@ QList ADIF::getCallList() const } return p; } - - int ADIF::getCount() const { diff --git a/logbook/adif.h b/logbook/adif.h index dbee8bb..74539e1 100644 --- a/logbook/adif.h +++ b/logbook/adif.h @@ -21,10 +21,14 @@ class QDateTime; class ADIF { public: + + struct QSO; + void init(QString const& filename); void load(); - void add(QString const& call, QString const& band, QString const& mode, const QString &submode, QString const& date); + void add(QString const& call, QString const& band, QString const& mode, const QString &submode, QString const& date, const QString &name, const QString &comment); bool match(QString const& call, QString const& band) const; + QList find(QString const& call) const; QList getCallList() const; int getCount() const; @@ -38,12 +42,13 @@ class ADIF , QString const& operator_call); -private: + struct QSO { - QString call,band,mode,submode,date; + QString call,band,mode,submode,date,name,comment; }; + private: QMultiHash _data; QString _filename; diff --git a/logbook/logbook.cpp b/logbook/logbook.cpp index ad62f4f..2bdac0d 100644 --- a/logbook/logbook.cpp +++ b/logbook/logbook.cpp @@ -59,25 +59,53 @@ void LogBook::match(/*in*/const QString call, bool &callWorkedBefore, bool &countryWorkedBefore) const { - if (call.length() > 0) - { - QString currentBand = ""; // match any band - callWorkedBefore = _log.match(call,currentBand); - countryName = _countries.find(call); + if(call.isEmpty()){ + return; + } - if (countryName.length() > 0) // country was found + QString currentBand = ""; // match any band + callWorkedBefore = _log.match(call, currentBand); + countryName = _countries.find(call); + + if (countryName.length() > 0){ // country was found countryWorkedBefore = _worked.getHasWorked(countryName); - else - { - countryName = "where?"; //error: prefix not found - countryWorkedBefore = false; - } + } else { + countryName = "where?"; //error: prefix not found + countryWorkedBefore = false; } } -void LogBook::addAsWorked(const QString call, const QString band, const QString mode, const QString submode, const QString date) +bool LogBook::findCallDetails( + /*in*/ + const QString call, + /*out*/ + QString &date, + QString &name, + QString &comment) const { - _log.add(call,band,mode,submode,date); + qDebug() << "looking for call" << call; + if(call.isEmpty()){ + return false; + } + + auto qsos = _log.find(call); + qDebug() << "found" << qsos.length() << "qsos for call" << call; + if(qsos.isEmpty()){ + return false; + } + + foreach(auto qso, qsos){ + if(date.isEmpty() && !qso.date.isEmpty()) date = qso.date; + if(name.isEmpty() && !qso.name.isEmpty()) name = qso.name; + if(comment.isEmpty() && !qso.comment.isEmpty()) comment = qso.comment; + } + + return true; +} + +void LogBook::addAsWorked(const QString call, const QString band, const QString mode, const QString submode, const QString date, const QString name, const QString comment) +{ + _log.add(call,band,mode,submode,date,name,comment); QString countryName = _countries.find(call); if (countryName.length() > 0) _worked.setAsWorked(countryName); diff --git a/logbook/logbook.h b/logbook/logbook.h index ce85eba..cc9000a 100644 --- a/logbook/logbook.h +++ b/logbook/logbook.h @@ -25,7 +25,14 @@ public: /*out*/ QString &countryName, bool &callWorkedBefore, bool &countryWorkedBefore) const; - void addAsWorked(const QString call, const QString band, const QString mode, const QString submode, const QString date); + bool findCallDetails( + /*in*/ + const QString call, + /*out*/ + QString &date, + QString &name, + QString &comment) const; + void addAsWorked(const QString call, const QString band, const QString mode, const QString submode, const QString date, const QString name, const QString comment); private: CountryDat _countries; diff --git a/mainwindow.cpp b/mainwindow.cpp index 29e3c26..8be62f9 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1261,7 +1261,11 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple, connect(ui->tableWidgetRXAll->horizontalHeader(), &QHeaderView::customContextMenuRequested, this, [this](QPoint const &point){ QMenu * menu = new QMenu(ui->tableWidgetRXAll); - buildBandActivitySortByMenu(menu); + QMenu * sortByMenu = menu->addMenu("Sort By..."); + buildBandActivitySortByMenu(sortByMenu); + + QMenu * showColumnsMenu = menu->addMenu("Show Columns..."); + buildShowColumnsMenu(showColumnsMenu, "band"); menu->popup(ui->tableWidgetRXAll->horizontalHeader()->mapToGlobal(point)); }); @@ -1475,7 +1479,11 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple, connect(ui->tableWidgetCalls->horizontalHeader(), &QHeaderView::customContextMenuRequested, this, [this](QPoint const &point){ QMenu * menu = new QMenu(ui->tableWidgetCalls); - buildCallActivitySortByMenu(menu); + QMenu * sortByMenu = menu->addMenu("Sort By..."); + buildCallActivitySortByMenu(sortByMenu); + + QMenu * showColumnsMenu = menu->addMenu("Show Columns..."); + buildShowColumnsMenu(showColumnsMenu, "call"); menu->popup(ui->tableWidgetCalls->horizontalHeader()->mapToGlobal(point)); }); @@ -6414,7 +6422,7 @@ void MainWindow::acceptQSO (QDateTime const& QSO_date_off, QString const& call, , QString const& my_call, QString const& my_grid, QByteArray const& ADIF) { QString date = QSO_date_on.toString("yyyyMMdd"); - m_logBook.addAsWorked (m_hisCall, m_config.bands ()->find (m_freqNominal), mode, submode, date); + m_logBook.addAsWorked (m_hisCall, m_config.bands ()->find (m_freqNominal), mode, submode, date, name, comments); sendNetworkMessage("LOG.QSO", QString(ADIF), { {"UTC.ON", QVariant(QSO_date_on.toMSecsSinceEpoch())}, @@ -7276,7 +7284,9 @@ void MainWindow::buildShowColumnsMenu(QMenu *menu, QString tableKey){ columnKeys.append({ {"Grid Locator", "grid"}, {"Distance", "distance"}, - {"Log Details", "log"} + {"Worked Before", "log"}, + {"Logged Name", "logName"}, + {"Logged Comment", "logComment"}, }); } @@ -11262,7 +11272,7 @@ void MainWindow::displayCallActivity() { displayItem->setToolTip(generateCallDetail(displayCall)); ui->tableWidgetCalls->setItem(row, col++, displayItem); - if(d.utcTimestamp.isValid()){ + if(1){ //d.utcTimestamp.isValid()){ auto ageItem = new QTableWidgetItem(since(d.utcTimestamp)); ageItem->setTextAlignment(Qt::AlignCenter | Qt::AlignVCenter); ageItem->setToolTip(d.utcTimestamp.toString()); @@ -11283,16 +11293,32 @@ void MainWindow::displayCallActivity() { auto distanceItem = new QTableWidgetItem(calculateDistance(d.grid)); distanceItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); - ui->tableWidgetCalls->setItem(ui->tableWidgetCalls->rowCount() - 1, col++, distanceItem); + ui->tableWidgetCalls->setItem(row, col++, distanceItem); QString flag; if(m_logBook.hasWorkedBefore(d.call, "")){ // unicode checkmark flag = "\u2713"; } - auto logDetailsItem = new QTableWidgetItem(flag); - logDetailsItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); - ui->tableWidgetCalls->setItem(row, col++, logDetailsItem); + auto workedBeforeItem = new QTableWidgetItem(flag); + workedBeforeItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + ui->tableWidgetCalls->setItem(row, col++, workedBeforeItem); + + QString logDetailDate; + QString logDetailName; + QString logDetailComment; + + if(showColumn("call", "log") || showColumn("call", "logName") || showColumn("call", "logComment")){ + m_logBook.findCallDetails(d.call, logDetailDate, logDetailName, logDetailComment); + } + + auto logNameItem = new QTableWidgetItem(logDetailName); + logNameItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + ui->tableWidgetCalls->setItem(row, col++, logNameItem); + + auto logCommentItem = new QTableWidgetItem(logDetailComment); + logCommentItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + ui->tableWidgetCalls->setItem(row, col++, logCommentItem); } else { ui->tableWidgetCalls->setItem(row, col++, new QTableWidgetItem("")); // age @@ -11301,7 +11327,9 @@ void MainWindow::displayCallActivity() { ui->tableWidgetCalls->setItem(row, col++, new QTableWidgetItem("")); // tdrift ui->tableWidgetCalls->setItem(row, col++, new QTableWidgetItem("")); // grid ui->tableWidgetCalls->setItem(row, col++, new QTableWidgetItem("")); // distance - ui->tableWidgetCalls->setItem(row, col++, new QTableWidgetItem("")); // log details + ui->tableWidgetCalls->setItem(row, col++, new QTableWidgetItem("")); // worked before + ui->tableWidgetCalls->setItem(row, col++, new QTableWidgetItem("")); // log name + ui->tableWidgetCalls->setItem(row, col++, new QTableWidgetItem("")); // log comment } if (isCallSelected) { @@ -11351,6 +11379,8 @@ void MainWindow::displayCallActivity() { ui->tableWidgetCalls->setColumnHidden(6, !showColumn("call", "grid", false)); ui->tableWidgetCalls->setColumnHidden(7, !showColumn("call", "distance", false)); ui->tableWidgetCalls->setColumnHidden(8, !showColumn("call", "log")); + ui->tableWidgetCalls->setColumnHidden(9, !showColumn("call", "logName")); + ui->tableWidgetCalls->setColumnHidden(10, !showColumn("call", "logComment")); // Resize the table columns ui->tableWidgetCalls->resizeColumnToContents(0); @@ -11361,6 +11391,8 @@ void MainWindow::displayCallActivity() { ui->tableWidgetCalls->resizeColumnToContents(5); ui->tableWidgetCalls->resizeColumnToContents(6); ui->tableWidgetCalls->resizeColumnToContents(7); + ui->tableWidgetCalls->resizeColumnToContents(8); + ui->tableWidgetCalls->resizeColumnToContents(9); // Reset the scroll position ui->tableWidgetCalls->verticalScrollBar()->setValue(currentScrollPos); diff --git a/mainwindow.ui b/mainwindow.ui index 9b90729..b48fc41 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -1274,13 +1274,20 @@ QTextEdit[transmitting="true"] { - Log Details + - + Worked Before - - AlignCenter + + + + Name + + + + + Comment