Skip to content

Commit

Permalink
Primary subdivisions working
Browse files Browse the repository at this point in the history
  • Loading branch information
ea4k committed Aug 9, 2024
1 parent 1c1251a commit ae35b37
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 45 deletions.
1 change: 1 addition & 0 deletions src/Changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
BUG: When entering/modifying a QSO thre is an error related to awarddxcc table not existing
TODO: Include the primary subdivisions table in the update of the DB, not just in creation

TODO: Update the DB (modes table) updateToLatest() => updateTo026
WIP: Try to optimize bool DataProxy_SQLite::fillEmptyDXCCInTheLog()
Expand Down
16 changes: 15 additions & 1 deletion src/dataproxy_sqlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5610,16 +5610,22 @@ QList<PrimarySubdivision> DataProxy_SQLite::getPrimarySubDivisions(const int _en

QSqlQuery query;
QString queryString;
if (!_pref.isEmpty())
if ((_pref.length()>0))
{
qDebug() << Q_FUNC_INFO << " - Running for no pref, delivering ALL for the entity";
queryString = QString("SELECT name, shortname, cqz, ituz FROM primary_subdivisions WHERE prefix = :prefix");
query.prepare(queryString);
query.bindValue(":prefix", _pref);
}
else
{
qDebug() << Q_FUNC_INFO << " - Running with a pref, delivering just for the prefix";
qDebug() << Q_FUNC_INFO << QString("If the entity is <=0 The list will be empty. Entity: %1").arg(_entity);
if (_entity<=0)
{
qDebug() << Q_FUNC_INFO << " - END: entity <= 0";
return list;
}
queryString = QString("SELECT name, shortname, cqz, ituz FROM primary_subdivisions WHERE dxcc = :dxcc");
query.prepare(queryString);
query.bindValue(":dxcc", _entity);
Expand All @@ -5629,6 +5635,8 @@ QList<PrimarySubdivision> DataProxy_SQLite::getPrimarySubDivisions(const int _en

if (sqlOK)
{
qDebug() << Q_FUNC_INFO << ": sqlOK true";

while (query.next())
{
if (query.isValid())
Expand All @@ -5641,10 +5649,16 @@ QList<PrimarySubdivision> DataProxy_SQLite::getPrimarySubDivisions(const int _en
list.append(ps);
qDebug() << Q_FUNC_INFO << " : " << ps.name ;
}
else
{
qDebug() << Q_FUNC_INFO << ": query not valid";
}
}
qDebug() << Q_FUNC_INFO << ": query not next";
}
else
{
qDebug() << Q_FUNC_INFO << ": sqlOK FALSE";
emit queryError(Q_FUNC_INFO, query.lastError().databaseText(), query.lastError().nativeErrorCode(), query.lastQuery());
list.clear();
}
Expand Down
96 changes: 86 additions & 10 deletions src/inputwidgets/mainwindowinputothers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ MainWindowInputOthers::MainWindowInputOthers(DataProxy_SQLite *dp, QWidget *pare
dataProxy = dp;

util = new Utilities(Q_FUNC_INFO);
util->setLongPrefixes(dataProxy->getLongPrefixes());
util->setSpecialCalls(dataProxy->getSpecialCallsigns());

//QLabel *entityPrimLabel, *entitySecLabel, *iotaAwardLabel, *entityNameLabel, *propModeLabel;
iotaContinentComboBox = new QComboBox();
Expand All @@ -44,6 +46,7 @@ MainWindowInputOthers::MainWindowInputOthers(DataProxy_SQLite *dp, QWidget *pare
propModeComboBox = new QComboBox();
iotaNumberLineEdit = new QLineEdit();
keepPropCheckBox = new QCheckBox();
showAllCheckBox = new QCheckBox();
userDefinedADIFComboBox = new QComboBox();
userDefinedADIFValueLineEdit = new QLineEdit();

Expand All @@ -52,7 +55,9 @@ MainWindowInputOthers::MainWindowInputOthers(DataProxy_SQLite *dp, QWidget *pare
//connect(satTabWidget, SIGNAL(setPropModeSat(QString)), this, SLOT(slotSetPropMode(QString)) ) ;
connect(propModeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotPropModeComboBoxChanged() ) ) ;
connect(userDefinedADIFComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUSerDefinedADIFComboBoxChanged() ) ) ;
connect(userDefinedADIFValueLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotSetCurrentUSerData() ) );
connect(userDefinedADIFValueLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotSetCurrentUserData() ) );
connect(entityPrimDivComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotPrimarySubdivisionsComboBoxChanged()) ) ;
connect(showAllCheckBox, SIGNAL(stateChanged(int)), this, SLOT(slotShowAllChecBoxChanged() ) ) ;

createUI();
setInitialADIFValues ();
Expand All @@ -78,6 +83,8 @@ void MainWindowInputOthers::createUI()
sota_ref = QString();
distance = 0;
age = 0;
currentInt = 0;
currentPref = QString();
pota_ref = QString();
sig = QString();
sig_info= QString();
Expand All @@ -102,6 +109,7 @@ void MainWindowInputOthers::createUI()
userSelectLabel->setAlignment(Qt::AlignVCenter| Qt::AlignRight);

keepPropCheckBox->setText(tr("Keep propagation mode"));
showAllCheckBox->setText(tr("Show All"));

entityPrimDivComboBox->setToolTip(tr("Select the primary division for this QSO."));
entitySecDivComboBox->setToolTip(tr("Select the secondary division for this QSO."));
Expand All @@ -110,6 +118,7 @@ void MainWindowInputOthers::createUI()
iotaContinentComboBox->setToolTip(tr("Select the IOTA continent for this QSO."));
iotaNumberLineEdit->setToolTip(tr("Select the IOTA reference number for this QSO."));
keepPropCheckBox->setToolTip(tr("Keeps the same propagation mode for next QSO."));
showAllCheckBox->setToolTip(tr("Show all subdivisions for the current DXCC Entity."));

userDefinedADIFComboBox->setToolTip(tr("Select the appropriate ADIF field for this QSO."));
userDefinedADIFValueLineEdit->setToolTip (tr("Value for the selected ADIF field."));
Expand All @@ -119,17 +128,20 @@ void MainWindowInputOthers::createUI()
entityNameComboBox->setEnabled(true);
propModeComboBox->setEnabled(true);
keepPropCheckBox->setEnabled(true);
showAllCheckBox->setEnabled(true);

QHBoxLayout *keepLayout = new QHBoxLayout;
keepLayout->addWidget(propModeComboBox);
//keepLayout->addWidget(keepPropCheckBox);
keepLayout->setSizeConstraint(QLayout::SetFixedSize);


QGridLayout *tabLayout = new QGridLayout;
tabLayout->addWidget(entityNameLabel, 0, 0);
tabLayout->addWidget(entityNameComboBox, 0, 1, 1, 2);
tabLayout->addWidget(entityPrimLabel, 1, 0);
tabLayout->addWidget(entityPrimDivComboBox, 1, 1, 1, 2);
tabLayout->addWidget(showAllCheckBox, 1, 3);
tabLayout->addWidget(entitySecLabel, 2, 0);
tabLayout->addWidget(entitySecDivComboBox, 2, 1, 1, 2);
tabLayout->addWidget(iotaAwardLabel, 3, 0);
Expand Down Expand Up @@ -172,8 +184,13 @@ void MainWindowInputOthers::clear(bool _full)
logEvent (Q_FUNC_INFO, "Start", Debug);
entityNameComboBox->setCurrentIndex(0);
userDefinedADIFComboBox->setCurrentIndex (0);
entityPrimDivComboBox->clear();
entityPrimDivComboBox->addItem("00-" + tr("None Identified") + " (000)");

userDefinedADIFValueLineEdit->clear ();
sota_ref = QString();
currentPref = QString();
currentInt = 0;

distance = 0.0;
age = 0;
Expand Down Expand Up @@ -691,9 +708,37 @@ bool MainWindowInputOthers::setInitialADIFValues()
return true;
}

bool MainWindowInputOthers::setState(const QString &_op)
{ // Sets a subdivision/State
qDebug() << Q_FUNC_INFO << ": " << _op;
if (_op.length()<1)
return false;

int indexC = entityPrimDivComboBox->findText(QString("%1-").arg(_op), Qt::MatchStartsWith);

qDebug() << Q_FUNC_INFO << _op << "/" << QString::number(indexC) << " / (6): " << entityPrimDivComboBox->itemText(6);
if (indexC<0)
return false;

entityPrimDivComboBox->setCurrentIndex(indexC);
return true;
}

QString MainWindowInputOthers::getState()
{// Reads the subdivision. It return just the shortname/code for the subdivision/State
qDebug() << Q_FUNC_INFO << ": " << ((entityPrimDivComboBox->currentText()).split("-")).at(0);

QString aux = entityPrimDivComboBox->currentText();
if ((aux.startsWith("00-")) && (aux.endsWith("(000)")) )
return QString();

return ((entityPrimDivComboBox->currentText()).split("-")).at(0);
}

void MainWindowInputOthers::updatePrimarySubdivisionsComboBox(QList<PrimarySubdivision> _subdivisions)
{
//qDebug() << Q_FUNC_INFO << " - count: " << QString::number(_subdivisions.count());
entityPrimDivComboBox->clear();
if (_subdivisions.count()<1)
return;

Expand All @@ -707,30 +752,40 @@ void MainWindowInputOthers::updatePrimarySubdivisionsComboBox(QList<PrimarySubdi
}
if (listOfSubdivisions.count()<1)
return;
entityPrimDivComboBox->clear();

listOfSubdivisions.prepend("00-" + tr("Not selected") + " (000)");

entityPrimDivComboBox->addItems(listOfSubdivisions);
//qDebug() << Q_FUNC_INFO << " - END";
}

void MainWindowInputOthers::updatePrimarySubDivisions(const int _n, const QString &_pref)
void MainWindowInputOthers::updatePrimarySubDivisions(const int _n, const QString &_qrz)
{
qDebug() << Q_FUNC_INFO << " - Start: " << QString::number(_n) << "/" << _pref;
//qDebug() << Q_FUNC_INFO << " - Start: " << QString::number(_n) << "/" << _qrz;
currentPref = _qrz;
QString currentPrefTMP = util->getPrefixFromCall(_qrz, !showAllCheckBox->isChecked());
qDebug() << Q_FUNC_INFO << " - currentPref: " << QString::number(_n) << "/" << currentPrefTMP;
if (_n<1)
return;
currentInt = _n;
setEntity(_n);
if (_pref.isEmpty())
if (currentPrefTMP.isEmpty())
return;

QList<PrimarySubdivision> subdivisions;
subdivisions.clear();
subdivisions.append(dataProxy->getPrimarySubDivisions(_n, _pref));
subdivisions.append(dataProxy->getPrimarySubDivisions(currentInt, currentPrefTMP));
if (subdivisions.isEmpty())
subdivisions.append(dataProxy->getPrimarySubDivisions(_n, QString()));
{
qDebug() << Q_FUNC_INFO << " - Subdivisions is empty, running just with the entity";
subdivisions.append(dataProxy->getPrimarySubDivisions(currentInt, QString()));
}

qDebug() << Q_FUNC_INFO << " - count: " << QString::number(subdivisions.count());
//qDebug() << Q_FUNC_INFO << " - count: " << QString::number(subdivisions.count());
if (subdivisions.count()<1)
return;
updatePrimarySubdivisionsComboBox(subdivisions);
qDebug() << Q_FUNC_INFO << " - END";
//qDebug() << Q_FUNC_INFO << " - END";
}

void MainWindowInputOthers::slotUSerDefinedADIFComboBoxChanged()
Expand Down Expand Up @@ -887,7 +942,7 @@ double MainWindowInputOthers::getDistance()
return distance;
}

void MainWindowInputOthers::slotSetCurrentUSerData()
void MainWindowInputOthers::slotSetCurrentUserData()
{
logEvent (Q_FUNC_INFO, "Start", Debug);
QString currentTag = getUserADIFTypeComboBox ();
Expand Down Expand Up @@ -932,6 +987,27 @@ void MainWindowInputOthers::slotSetCurrentUSerData()
logEvent (Q_FUNC_INFO, "END", Debug);
}


void MainWindowInputOthers::slotPrimarySubdivisionsComboBoxChanged()
{
logEvent (Q_FUNC_INFO, "Start", Debug);
//qDebug() << Q_FUNC_INFO << entityPrimDivComboBox->currentText();

logEvent (Q_FUNC_INFO, "END", Debug);
}

void MainWindowInputOthers::slotShowAllChecBoxChanged()
{
updatePrimarySubDivisions(currentInt, currentPref);
//if (showAllCheckBox->isChecked())
// updatePrimarySubDivisions(currentInt, QString());
//else
// updatePrimarySubDivisions(currentInt, currentPref);
//emit showAll(showAllCheckBox->isChecked());
}



bool MainWindowInputOthers::getDarkMode()
{
logEvent (Q_FUNC_INFO, "Start-END", Debug);
Expand Down
18 changes: 15 additions & 3 deletions src/inputwidgets/mainwindowinputothers.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MainWindowInputOthers : public QWidget
int getEntity();
QString getEntityPrefix();

void updatePrimarySubDivisions(const int _n, const QString &_pref); // Receives the entity & prefix of the call to check if
void updatePrimarySubDivisions(const int _n, const QString &_qrz); // Receives the entity & prefix of the call to check if
// It is possible to focus the primary
// subdivision

Expand Down Expand Up @@ -88,38 +88,47 @@ class MainWindowInputOthers : public QWidget
void setKeep(const bool _b);
bool getKeep();

bool setState(const QString &_op); // Sets a subdivision / State
QString getState(); // Reads the subdivision / State

void createUI();
void clear(bool _full = false); //full= false leaves the "keep this data"; full = true clears everything
void setLogLevel (const DebugLogLevel _l);

signals:
void setPropMode(const QString _p);
void debugLog (QString _func, QString _msg, DebugLogLevel _level);
//void showAll(bool _showAll);

private slots:
//void slotSetPropMode(const QString &_p); // To receive the signal from the SAT widget and set "SAT" propagation mode, of needed.
void slotPropModeComboBoxChanged();
void slotUSerDefinedADIFComboBoxChanged();
void slotSetCurrentUSerData();
void slotSetCurrentUserData();
void slotPrimarySubdivisionsComboBoxChanged();
void slotShowAllChecBoxChanged();


private:
QString checkIfValidIOTA(const QString &_tiota); //TODO: There is an equivalent function in the Awards class. I should use only one!
void setColorsForUserDefinedADIFValueLineEdit();
bool checkVUCC_GRIDS(const QString &_string);
bool setInitialADIFValues();
void updateShowAll();

void updatePrimarySubdivisionsComboBox(QList<PrimarySubdivision> _subdivisions);
bool getDarkMode();
void logEvent(const QString &_func, const QString &_msg, DebugLogLevel _level);


Utilities *util;
DataProxy_SQLite *dataProxy;

QStringList entitiesList, propModeList;
//QLabel *entityPrimLabel, *entitySecLabel, *iotaAwardLabel, *entityNameLabel, *propModeLabel;
QComboBox *iotaContinentComboBox, *entityPrimDivComboBox, *entitySecDivComboBox, *entityNameComboBox, *propModeComboBox;
QLineEdit *iotaNumberLineEdit;
QCheckBox *keepPropCheckBox;
QCheckBox *keepPropCheckBox, *showAllCheckBox;

QPalette palRed, palBlack, palWhite;
bool autoUpdating;
Expand All @@ -128,6 +137,9 @@ private slots:
QLineEdit *userDefinedADIFValueLineEdit;
QStringList adifValidTypes;

QString currentPref; // Just a cache to be able to rewrite the subdivisions combobox
int currentInt; // if the showAllCheckBox is toggled

QString sota_ref, vucc_grids, pota_ref, sig, sig_info, wwff_ref;
double age, distance;
DebugLogLevel logLevel;
Expand Down
Loading

0 comments on commit ae35b37

Please sign in to comment.