File: statsfieldperbandwidget.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 (149 lines) | stat: -rw-r--r-- 6,351 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
/***************************************************************************
                          statsfieldperbandwidget.cpp  -  description
                             -------------------
    begin                : jul 2021
    copyright            : (C) 2021 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 "statsfieldperbandwidget.h"

StatsFieldPerBandWidget::StatsFieldPerBandWidget(DataProxy_SQLite *dp, ValidFieldsForStats _field, QWidget *parent)
{
     //qDebug() << "StatsFieldPerBandWidget::StatsFieldPerBandWidget";
    Q_UNUSED(parent);
    dataProxy = dp;
    util = new Utilities(Q_FUNC_INFO);
    selectedField = _field;
    modeComboBox = new QComboBox;

    createUI();
    //prepareChart();
}

StatsFieldPerBandWidget::~StatsFieldPerBandWidget()
{
    delete(util);
   //delete(dataProxy);
}

void StatsFieldPerBandWidget::createUI()
{
    modeInUse = "ALL";
    log = -1;
    QString allString = tr("All");
    modeComboBox->clear ();
    modeComboBox->addItem (allString);
    modeComboBox->addItems (dataProxy->getModesInLog (-1));

    dataProxy->getModesInLog (-1);

    tableWidget = new QTableWidget(this);
    tableWidget->setRowCount(0);
    tableWidget->setColumnCount(3);

    tableWidget->resizeRowsToContents();
    tableWidget->sortByColumn(0, Qt::AscendingOrder);
    tableWidget->horizontalHeader()->setStretchLastSection(true);

    QLabel *textLabel = new QLabel;
    textLabel->setText(tr("Mode: "));
    textLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);

    QHBoxLayout *labelLayout = new QHBoxLayout;
    labelLayout->addWidget(textLabel);
    labelLayout->addWidget(modeComboBox);

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addLayout(labelLayout);
    layout->addWidget(tableWidget);
    setLayout(layout);

    connect(modeComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(slotModeComboBoxChanged() ) ) ;
}

void StatsFieldPerBandWidget::prepareChart(const int _log)
{
    //qDebug() << Q_FUNC_INFO << "Log = " << QString::number(_log);

    while(tableWidget->rowCount()>0)
    {
        tableWidget->removeRow(tableWidget->rowCount()-1);
    }

    log = _log;

    tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("Band")));
    tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Worked")));
    tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem(tr("Confirmed")));
    tableWidget->setStyleSheet("QHeaderView::section { background-color:cornflowerblue }");

    QStringList bands;
    bands << dataProxy->getBandsInLog (_log);
    QString aux;
    int gridsCount;
    foreach (aux, bands)
    {
        tableWidget->insertRow(tableWidget->rowCount());
        tableWidget->setItem(tableWidget->rowCount()-1, 0, new QTableWidgetItem((aux)) );
        QTableWidgetItem *item = tableWidget->item (tableWidget->rowCount()-1, 0);
        item->setTextAlignment( Qt::AlignCenter );
        gridsCount = dataProxy->getFieldInBand (selectedField, aux, false, modeInUse, _log);
        tableWidget->setItem(tableWidget->rowCount()-1, 1, new QTableWidgetItem(QString::number(gridsCount)) );
        item = tableWidget->item (tableWidget->rowCount()-1, 1);
        item->setTextAlignment( Qt::AlignCenter );
        gridsCount = dataProxy->getFieldInBand (selectedField, aux, true, modeInUse, _log);
        tableWidget->setItem(tableWidget->rowCount()-1, 2, new QTableWidgetItem(QString::number(gridsCount)) );
        item = tableWidget->item (tableWidget->rowCount()-1, 2);
        item->setTextAlignment( Qt::AlignCenter );
    }
    // Now we add the "All" row.
    tableWidget->insertRow(tableWidget->rowCount());
    tableWidget->setItem(tableWidget->rowCount()-1, 0, new QTableWidgetItem(tr("All")) );
    QTableWidgetItem *item = tableWidget->item (tableWidget->rowCount()-1, 0);
    item->setTextAlignment( Qt::AlignCenter );
    gridsCount = dataProxy->getFieldInBand (selectedField, "ALL", false, modeInUse, _log);
    tableWidget->setItem(tableWidget->rowCount()-1, 1, new QTableWidgetItem(QString::number(gridsCount)) );
    item = tableWidget->item (tableWidget->rowCount()-1, 1);
    item->setTextAlignment( Qt::AlignCenter );
    gridsCount = dataProxy->getFieldInBand (selectedField, "ALL", true, modeInUse, _log);
    tableWidget->setItem(tableWidget->rowCount()-1, 2, new QTableWidgetItem(QString::number(gridsCount)) );
    item = tableWidget->item (tableWidget->rowCount()-1, 2);
    item->setTextAlignment( Qt::AlignCenter );
}

void StatsFieldPerBandWidget::slotConfirmedClicked()
{
    prepareChart(log);
}

void StatsFieldPerBandWidget::slotModeComboBoxChanged()
{
    //qDebug() << Q_FUNC_INFO << ": " << modeComboBox->currentText() << "/" << QString::number(modeComboBox->currentIndex ());
    if (modeComboBox->currentIndex ()==0)
    {
        modeInUse = "ALL";
    }
    else
    {
        modeInUse = modeComboBox->currentText ();
    }
    prepareChart (log);
}