File: dxclusterassistant.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 (131 lines) | stat: -rw-r--r-- 4,573 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
/***************************************************************************
    dxclusterassistant.h  -  description
       -------------------
begin                : mar 2024
copyright            : (C) 2024 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 "dxclusterassistant.h"

DXClusterAssistant::DXClusterAssistant(const QString &_parentFunction, QWidget *parent)
    : QWidget{parent}
{
#ifdef QT_DEBUG
    //qDebug() << ": " << _parentFunction;
#else
#endif
    (void)_parentFunction;
    //qDebug() << Q_FUNC_INFO << " - Start: " + _parentFunction;

    tableWidget = new QTableWidget;
}

DXClusterAssistant::~DXClusterAssistant(){};

bool DXClusterAssistant::init()
{
    list.clear();
    return createUI();
}

bool DXClusterAssistant::createUI()
{
    //qDebug() << Q_FUNC_INFO << " - Start";
    tableWidget->setSortingEnabled (true);

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

    QStringList header;
    header.clear();
    header << tr("DX") << tr("Freq") << tr("Status"); // tr("Mode");
    tableWidget->setColumnCount(header.length());
    tableWidget->setHorizontalHeaderLabels(header);

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


    setLayout(mainLayout);
    return true;

    //connect(cancelButton, SIGNAL(clicked()), this, SLOT(slotCancelPushButtonClicked() ) );
    //qDebug() << Q_FUNC_INFO << " - END";
}

void DXClusterAssistant::newDXClusterSpot(proposedQSOs _q)
{
    list.append(_q);
    //qDebug() << Q_FUNC_INFO << " - 50";
    //qDebug() << Q_FUNC_INFO << " - 60";
    //qDebug() << Q_FUNC_INFO << QString("Data received: Call: %1 - Freq: %2 - Status: %3").arg(_call).arg(_freq).arg(getStringFromStatus(_status));
    addCall();
}

QString DXClusterAssistant::getStringFromStatus(QSOStatus _s)
{
    switch (_s) {
    case unknown:
        return "unknown";
        break;
    case ATNO:
        return "ATNO";
        break;
    case needed:
        return "needed";
        break;
    case worked:
        return "worked";
        break;
    case confirmed:
        return "confirmed";
        break;
    default:
        return "unknown";
        break;
    }
}

void DXClusterAssistant::addCall()
{
    //qDebug() << Q_FUNC_INFO << " - Start";
    tableWidget->clearContents();
    tableWidget->setRowCount(0);

    proposedQSOs aux;

    foreach(aux, list)
    {
        //qDebug() << Q_FUNC_INFO << "Call: " << aux.call;
        QTableWidgetItem *newItemCall = new QTableWidgetItem(aux.call, QTableWidgetItem::Type);
        QTableWidgetItem *newItemFreq = new QTableWidgetItem(aux.freq.toQString(), QTableWidgetItem::Type);
        QTableWidgetItem *newItemStatus = new QTableWidgetItem(getStringFromStatus(aux.status), QTableWidgetItem::Type);

        tableWidget->insertRow(tableWidget->rowCount());
        int row = tableWidget->rowCount();
        tableWidget->setItem(row-1, 0, newItemCall);
        tableWidget->setItem(row-1, 1, newItemFreq);
        tableWidget->setItem(row-1, 2, newItemStatus);
    }
    //qDebug() << Q_FUNC_INFO << " - END";
}