File: showadifimportwidget.cpp

package info (click to toggle)
klog 2.4.2-3
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 12,228 kB
  • sloc: cpp: 51,678; makefile: 15
file content (203 lines) | stat: -rw-r--r-- 7,570 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/***************************************************************************
                          showadifimportwidget.cpp  -  description
                             -------------------
    begin                : July 2020
    copyright            : (C) 2020 by Jaime Robles
    email                : jaime@robles.es
 ***************************************************************************/

/*****************************************************************************
 * This file is part of KLog.                                                *
 *                                                                           *
 *    KLog is free software: you can redistribute it and/or modify           *
 *    it under the terms of the GNU General Public License as published by   *
 *    the Free Software Foundation, either version 3 of the License, or      *
 *    (at your option) any later version.                                    *
 *                                                                           *
 *    KLog is distributed in the hope that it will be useful,                *
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 *    GNU General Public License for more details.                           *
 *                                                                           *
 *    You should have received a copy of the GNU General Public License      *
 *    along with KLog.  If not, see <https://www.gnu.org/licenses/>.         *
 *                                                                           *
 *****************************************************************************/

#include "showadifimportwidget.h"
#include "../callsign.h"
#include "../utilities.h"


ShowAdifImportWidget::ShowAdifImportWidget(DataProxy_SQLite *dp, const QString &_parentFunction, QWidget *parent) : QWidget(parent)
{
    Q_UNUSED(_parentFunction);
    dataProxy = dp;
    //util = new Utilities(Q_FUNC_INFO);
    okButton = new QPushButton;
    //cancelButton = new QPushButton;
    tableWidget = new QTableWidget;
    qsosList.clear();
    setWindowTitle("ShowAdif");
    createUI();
    //util->setLongPrefixes(dataProxy->getLongPrefixes());
    //util->setSpecialCalls(dataProxy->getSpecialCallsigns());
}

ShowAdifImportWidget::~ShowAdifImportWidget()
{
   //delete(dataProxy);
}

void ShowAdifImportWidget::createUI()
{
    QLabel *msgLabel = new QLabel;
    msgLabel->setText(tr("The following QSOs are those QSOs that you have received the LoTW confirmation."));
    okButton->setText(tr("Ok"));
    //cancelButton->setText(tr("Cancel"));

    hv = tableWidget->verticalHeader();
    hv->hide();
    hv->setStretchLastSection(true);
    hh = tableWidget->horizontalHeader();

    QStringList header;
    header.clear();
    header << tr("DX") << tr("Date/Time") << tr("Band") << tr("Mode");
    tableWidget->setColumnCount(header.length());
    tableWidget->setHorizontalHeaderLabels(header);

    QGridLayout *mainLayout = new QGridLayout;
    mainLayout->addWidget(msgLabel, 0, 0, 1, -1);
    mainLayout->addWidget(tableWidget, 1, 0, 1, -1);

    mainLayout->addWidget(okButton, 2, 1);
   // mainLayout->addWidget(cancelButton, 2, 2);

    setLayout(mainLayout);

    connect(okButton, SIGNAL(clicked()), this, SLOT(slotOKPushButtonClicked() ) );
   // connect(cancelButton, SIGNAL(clicked()), this, SLOT(slotCancelPushButtonClicked() ) );
}

void ShowAdifImportWidget::fillTable()
{
    //qDebug() << "ShowAdifImportWidget::fillTable ";
    //header << tr("DX") << tr("Date/Time") << tr("Band") << tr("Mode");

    //QList<int> qsos;
    //qsos.clear();
    //qsos.append(dataProxy->getQSOsListLoTWToSend(stationCallsignComboBox->currentText(), startDate->date(), endDate->date(), true));
    //qDebug() << "ShowAdifImportWidget::fillTable QSOS: " << QString::number(qsosList.length());

    //QString aux, prefix;
    //qDebug() << "ShowAdifImportWidget::fillTable: -3" ;
    tableWidget->clearContents();
    tableWidget->setRowCount(0);
    if (tableWidget->columnCount()>0)
    {
       //qDebug() << "ShowAdifImportWidget::fillTable pre FOR";
        for (int i=0; i<qsosList.length(); i++)
        {
            //qDebug() << "ShowAdifImportWidget::fillTable in FOR " << QString::number(i);
            addQSO(qsosList.at(i));
        }
    }
    //qDebug() << "ShowAdifImportWidget::fillTable END";
}

void ShowAdifImportWidget::addQSO(const QStringList &_qso)
{
    //qDebug() << "ShowAdifImportWidget::addQSO: " << QString::number(_qsoID);
    // QRZ-DX, Date-Time, Band, Mode

    QStringList qsoToAdd;
    qsoToAdd.clear();
    qsoToAdd << _qso;

    //qDebug() << "ShowAdifImportWidget::addQSO: Columns: " << QString::number(tableWidget->columnCount());
    //qDebug() << "ShowAdifImportWidget::addQSO: qsoToAdd-length: " << QString::number(qsoToAdd.length());

    if (qsoToAdd.length() == tableWidget->columnCount())
    {
        tableWidget->insertRow(tableWidget->rowCount());

        for (int i = 0; i<qsoToAdd.length(); i++)
        {
            //qDebug() << "ShowAdifImportWidget::addQSO: qsoToAdd.at(i): " << qsoToAdd.at(i);
            QTableWidgetItem *newItemID = new QTableWidgetItem(qsoToAdd.at(i));
            newItemID->setTextAlignment(Qt::AlignCenter);
            newItemID->setFlags(Qt::NoItemFlags);
            tableWidget->setItem(tableWidget->rowCount()-1, i, newItemID);
        }
        //QTableWidgetItem *newItem = new QTableWidgetItem(tr("%1").arg(pow(row, column+1)));
        //tableWidget->setItem(row, column, newItem);
    }

    //qDebug() << "ShowAdifImportWidget::addQSO: - END" ;
}


void ShowAdifImportWidget::slotOKPushButtonClicked()
{
    this->hide();
    //emit selection(stationCallsignComboBox->currentText(), startDate->date(), endDate->date());
    close();
}


void ShowAdifImportWidget::closeEvent(QCloseEvent *event)
{
    //qDebug() << "ShowAdifImportWidget::closeEvent";
    event->accept();
}

void ShowAdifImportWidget::showEvent(QShowEvent *event)
{
    //qDebug() << "ShowAdifImportWidget::showEvent";
    fillTable();
    event->accept();
}

void ShowAdifImportWidget::addQSOToTheList(const QStringList _qso)
{
    //qDebug() << "ShowAdifImportWidget::addQSOToTheList - Start";
    // QRZ-DX, Date-Time(yyyyMMdd-hhmmss), Band, Mode
    if (_qso.length()!=4)
    {
        //qDebug() << "ShowAdifImportWidget::addQSOToTheList - NO valid qso list received";
        return;
    }
    Callsign callsign(_qso.at(0));
    if (!callsign.isValid())
    {
        //qDebug() << "ShowAdifImportWidget::addQSOToTheList - NO valid QRZ received";
        return;
    }
    if (dataProxy->getIdFromBandName(_qso.at(2))<0)
    {
        //qDebug() << "ShowAdifImportWidget::addQSOToTheList - NO valid BAND received";
        return;
    }
    if (dataProxy->getIdFromModeName(_qso.at(3))<0)
    {
        //qDebug() << "ShowAdifImportWidget::addQSOToTheList - NO valid Mode received";
        return;
    }

    Utilities util(Q_FUNC_INFO);
    QDateTime _dateTime = util.getDateTimeFromSQLiteString(_qso.at(1));
    if (!_dateTime.isValid())
    {
        //qDebug() << "ShowAdifImportWidget::addQSOToTheList - NO valid DateTime received";
        return;
    }

    QStringList _newQSO;
    _newQSO.clear();

    _newQSO << _qso.at(0) << util.getDateTimeSQLiteStringFromDateTime(_dateTime) << _qso.at(2) << _qso.at(3);
    qsosList << _newQSO;
    //qDebug() << "ShowAdifImportWidget::addQSOToTheList QSO Added! - "<< _qso.at(0) <<" - END";
}