Skip to content

Commit

Permalink
Mods for v0.9.27
Browse files Browse the repository at this point in the history
  • Loading branch information
rklasky committed Aug 8, 2021
1 parent d5ba02c commit 2e5355c
Show file tree
Hide file tree
Showing 22 changed files with 577 additions and 110 deletions.
96 changes: 81 additions & 15 deletions MSSPM_GuiEstimation/nmfEstimationTab01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ nmfEstimation_Tab1::nmfEstimation_Tab1(QTabWidget* tabs,
m_SpeciesGuild.clear();
m_ModelName = "";
m_ProjectName = "";
m_NumSignificantDigits = -1;

m_Logger->logMsg(nmfConstants::Normal,"nmfEstimation_Tab1::nmfEstimation_Tab1");

Expand Down Expand Up @@ -65,6 +66,11 @@ nmfEstimation_Tab1::nmfEstimation_Tab1(QTabWidget* tabs,
noBoldFont.setBold(false);
Estimation_Tab1_SpeciesPopulationTV->setFont(noBoldFont);

// Hide these for now. Maybe add them later.
Estimation_Tab1_ModifySL->hide();
Estimation_Tab1_ModifyRunPB->hide();
Estimation_Tab1_ModifyRunCB->hide();

connect(Estimation_Tab1_PopulationTabW, SIGNAL(currentChanged(int)),
this, SLOT(callback_CurrentTabChanged(int)));
connect(Estimation_Tab1_NextPB, SIGNAL(clicked()),
Expand Down Expand Up @@ -180,14 +186,18 @@ nmfEstimation_Tab1::callback_ModifyMovingSL(int sliderValue)
double origValue;
QStandardItem *item;
QStandardItemModel* smodel = qobject_cast<QStandardItemModel*>(Estimation_Tab1_SpeciesPopulationTV->model());
QLocale locale(QLocale::English);
QString valueWithComma;

sliderValue -= m_StartPosSL;

// Modify selected data
foreach (const QModelIndex &index, m_selIndexes) {
origValue = m_originalValuesSelected[i++];
tableValue = origValue + origValue*(sliderValue/50.0);
item = new QStandardItem(QString::number(tableValue,'f',2));
valueWithComma = nmfUtilsQt::checkAndCalculateWithSignificantDigits(
tableValue,m_NumSignificantDigits,2);
item = new QStandardItem(valueWithComma);
item->setTextAlignment(Qt::AlignCenter);
smodel->setItem(index.row(),index.column(),item);

Expand Down Expand Up @@ -261,13 +271,17 @@ void
nmfEstimation_Tab1::callback_SelectionChangedTV(const QItemSelection& selection,
const QItemSelection& deselection)
{
QString valueWithoutComma;

// Store the selected indexes in class variable
getSelectedIndexes();

// Save the values of the selected indexes in case user wants to undo mods from last save
m_originalValuesSelected.clear();
foreach (const QModelIndex &index, m_selIndexes){
m_originalValuesSelected.push_back(index.data(Qt::DisplayRole).toDouble());
valueWithoutComma = index.data(Qt::DisplayRole).toString().remove(",");
m_originalValuesSelected.push_back(valueWithoutComma.toDouble());
// m_originalValuesSelected.push_back(index.data(Qt::DisplayRole).toDouble());
}

}
Expand Down Expand Up @@ -314,7 +328,9 @@ nmfEstimation_Tab1::callback_RestorePB()
for (int i=0; i<numRows; ++i) {
for (int j=0; j<numCols; ++j) {
if (j > 0) {
valueWithComma = locale.toString(m_originalSpeciesValuesAll[m++].toDouble());
// valueWithComma = locale.toString(m_originalSpeciesValuesAll[m++].toDouble());
valueWithComma = nmfUtilsQt::checkAndCalculateWithSignificantDigits(
m_originalSpeciesValuesAll[m++].toDouble(),m_NumSignificantDigits,6);
item = new QStandardItem(valueWithComma);
} else {
item = new QStandardItem(m_originalSpeciesValuesAll[m++]);
Expand Down Expand Up @@ -465,17 +481,18 @@ nmfEstimation_Tab1::callback_SavePB()
if (reply == QMessageBox::No) {
return;
}

if (onGuildTab()) {
ok = savePopulationParametersGuilds(nmfConstantsMSSPM::ShowPopupError);
} else { // if on Species tab
ok = savePopulationParametersSpecies(nmfConstantsMSSPM::ShowPopupError);
if (ok) {
savePopulationParameterGuildK();
}
}
if (ok) {
loadWidgets();
}
resetSelection();

}

void
Expand Down Expand Up @@ -738,17 +755,22 @@ nmfEstimation_Tab1::saveGuildDataRange(bool showPopup)
index = m_GuildModel->index(i,3);
GrowthRateMax = index.data().toString();
cmd += "GrowthRateMax=" + GrowthRateMax + ",";

// This shouldn't be set here. It should be set automatically when user saves Species data.
index = m_GuildModel->index(i,4);
valueWithoutComma = index.data().toString().remove(",");
GuildK = valueWithoutComma;

index = m_GuildModel->index(i,5);
valueWithoutComma = index.data().toString().remove(",");
GuildKMin = valueWithoutComma;
cmd += "GuildKMin=" + GuildKMin + ",";

index = m_GuildModel->index(i,6);
valueWithoutComma = index.data().toString().remove(",");
GuildKMax = valueWithoutComma;
cmd += "GuildKMax=" + GuildKMax;

cmd += " WHERE GuildName = '" + GuildName + "'";
if (nmfUtilsQt::emptyField({GuildName,GrowthRateMin,GrowthRateMax,GuildKMin,GuildKMax})) {
checkAndShowEmptyFieldError(showPopup,"saveGuildDataRange");
Expand Down Expand Up @@ -938,6 +960,17 @@ nmfEstimation_Tab1::isInitBiomassLessThanSpeciesKMin()
return true;
}

bool
nmfEstimation_Tab1::savePopulationParameterGuildK()
{
// Calculate and save the guildk values and write them to the Guilds file
// Make sure the user can then save the Guild Parameters in Estimation Tab 1

std::cout << "nmfEstimation_Tab1::savePopulationParameterGuildK tbd" << std::endl;

return true;
}

bool
nmfEstimation_Tab1::saveSpeciesDataPrimary(bool showPopup)
{
Expand Down Expand Up @@ -1586,6 +1619,8 @@ nmfEstimation_Tab1::setupHelpSpecies()
bool
nmfEstimation_Tab1::loadWidgets()
{
readSettings();

bool okSpecies = loadSpecies();
bool okGuilds = loadGuilds();

Expand All @@ -1596,6 +1631,11 @@ nmfEstimation_Tab1::loadWidgets()
if (okGuilds) {
setupHelpGuilds();
}

if (Estimation_Tab1_SpeciesRangeSB->isEnabled()) {
callback_SpeciesRangeSB(Estimation_Tab1_SpeciesRangeSB->value());
}

return true;
}

Expand Down Expand Up @@ -1632,7 +1672,9 @@ nmfEstimation_Tab1::loadGuilds()
col = 0;
for (QString field : PopulationFieldList) {
if (PopulationFieldList[col].contains("GuildK")) {
valueWithComma = locale.toString(field.toDouble());
// valueWithComma = locale.toString(field.toDouble());
valueWithComma = nmfUtilsQt::checkAndCalculateWithSignificantDigits(
field.toDouble(),m_NumSignificantDigits,6);
value = valueWithComma;
} else {
value = QString::fromStdString(dataMap[field.toStdString()][row]);
Expand Down Expand Up @@ -1700,7 +1742,9 @@ nmfEstimation_Tab1::loadSpecies()
m_originalSpeciesValuesAll.push_back(value);
if ((fields[col].find("InitBiomass") != std::string::npos) ||
(fields[col].find("SpeciesK") != std::string::npos)) {
valueWithComma = locale.toString(value.toDouble());
// valueWithComma = locale.toString(value.toDouble());
valueWithComma = nmfUtilsQt::checkAndCalculateWithSignificantDigits(
value.toDouble(),m_NumSignificantDigits,6);
item = new QStandardItem(valueWithComma);
} else {
item = new QStandardItem(value);
Expand Down Expand Up @@ -1784,7 +1828,6 @@ nmfEstimation_Tab1::callback_SpeciesRangeSB(int pct)
int col;
int row;
double pctVal = double(pct)/100.0;
double parameterValue;
QModelIndex index;
std::set<int> selectedParameters;
QStandardItem* minItem;
Expand All @@ -1793,6 +1836,10 @@ nmfEstimation_Tab1::callback_SpeciesRangeSB(int pct)
// Column number of parameters that have min/max values associated with them
// Update this as necessary when implementing supplemental parameters.
std::vector<int> parameters = {1,4,8,12,15}; // RSK - shouldn't be hard-coded.
QLocale locale(QLocale::English);
QString valueWithoutComma;
QString valueWithComma;
double newValue;

QModelIndexList indexes = getSelectedVisibleCells();

Expand All @@ -1801,14 +1848,20 @@ nmfEstimation_Tab1::callback_SpeciesRangeSB(int pct)
for (int row=0; row<numRows; ++row) {
for (int col : parameters) {
index = m_SpeciesModel->index(row,col);
parameterValue = index.data().toDouble();
valueWithoutComma = index.data().toString().remove(",");
if ((rangeType == "min/max") || (rangeType == "min only")) {
minItem = new QStandardItem(QString::number(parameterValue*(1.0-pctVal),'f',6));
newValue = valueWithoutComma.toDouble()*(1.0-pctVal);
valueWithComma = nmfUtilsQt::checkAndCalculateWithSignificantDigits(
newValue,m_NumSignificantDigits,6);
minItem = new QStandardItem(valueWithComma);
minItem->setTextAlignment(Qt::AlignCenter);
m_SpeciesModel->setItem(row,col+1,minItem);
}
if ((rangeType == "min/max") || (rangeType == "max only")) {
maxItem = new QStandardItem(QString::number(parameterValue*(1.0+pctVal),'f',6));
newValue = valueWithoutComma.toDouble()*(1.0+pctVal);
valueWithComma = nmfUtilsQt::checkAndCalculateWithSignificantDigits(
newValue,m_NumSignificantDigits,6);
maxItem = new QStandardItem(valueWithComma);
maxItem->setTextAlignment(Qt::AlignCenter);
m_SpeciesModel->setItem(row,col+2,maxItem);
}
Expand All @@ -1826,8 +1879,11 @@ nmfEstimation_Tab1::callback_SpeciesRangeSB(int pct)
case 13:
case 16:
index = m_SpeciesModel->index(row,col-1);
parameterValue = index.data().toDouble();
minItem = new QStandardItem(QString::number(parameterValue*(1.0-pctVal),'f',6));
valueWithoutComma = index.data().toString().remove(",");
newValue = valueWithoutComma.toDouble()*(1.0-pctVal);
valueWithComma = nmfUtilsQt::checkAndCalculateWithSignificantDigits(
newValue,m_NumSignificantDigits,6);
minItem = new QStandardItem(valueWithComma);
minItem->setTextAlignment(Qt::AlignCenter);
m_SpeciesModel->setItem(row,col,minItem);
break;
Expand All @@ -1837,8 +1893,11 @@ nmfEstimation_Tab1::callback_SpeciesRangeSB(int pct)
case 14:
case 17:
index = m_SpeciesModel->index(row,col-2);
parameterValue = index.data().toDouble();
maxItem = new QStandardItem(QString::number(parameterValue*(1.0+pctVal),'f',6));
valueWithoutComma = index.data().toString().remove(",");
newValue = valueWithoutComma.toDouble()*(1.0+pctVal);
valueWithComma = nmfUtilsQt::checkAndCalculateWithSignificantDigits(
newValue,m_NumSignificantDigits,6);
maxItem = new QStandardItem(valueWithComma);
maxItem->setTextAlignment(Qt::AlignCenter);
m_SpeciesModel->setItem(row,col,maxItem);
break;
Expand All @@ -1848,11 +1907,14 @@ nmfEstimation_Tab1::callback_SpeciesRangeSB(int pct)
}
reselectVisibleCells(indexes);
}
Estimation_Tab1_SpeciesPopulationTV->resizeColumnsToContents();
}

void
nmfEstimation_Tab1::readSettings()
{
m_Logger->logMsg(nmfConstants::Normal,"nmfEstimation_Tab1::readSettings");

QSettings* settings = nmfUtilsQt::createSettings(nmfConstantsMSSPM::SettingsDirWindows,"MSSPM");

settings->beginGroup("Settings");
Expand All @@ -1863,6 +1925,10 @@ nmfEstimation_Tab1::readSettings()
m_ProjectName = settings->value("ProjectName","").toString().toStdString();
settings->endGroup();

settings->beginGroup("Preferences");
m_NumSignificantDigits = settings->value("NumSignificantDigits",-1).toInt();
settings->endGroup();

delete settings;
}

3 changes: 3 additions & 0 deletions MSSPM_GuiEstimation/nmfEstimationTab01.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class nmfEstimation_Tab1: public QObject
Q_OBJECT

bool m_runFromModifySlider;
int m_NumSignificantDigits;
nmfLogger* m_Logger;
nmfDatabase* m_DatabasePtr;
QStandardItemModel* m_GuildModel;
Expand Down Expand Up @@ -108,6 +109,7 @@ class nmfEstimation_Tab1: public QObject
void resetModifySlider();
void resetSelection();
void resetVisibleColumns();
bool savePopulationParameterSpeciesK();
void showNoColumns(QTableView* tv);
void showAllColumns(QTableView* tv);
void showPrimaryColumns(QTableView* tv);
Expand All @@ -125,6 +127,7 @@ class nmfEstimation_Tab1: public QObject
QList<QString>& SpeciesGrowthRate,
QList<QString>& SpeciesK);
bool savePopulationParametersGuilds(bool showPopup);
bool savePopulationParameterGuildK();
bool saveGuildDataPrimary(bool showPopup);
bool saveGuildDataSupplemental(bool showPopup);
bool saveGuildDataRange(bool showPopup);
Expand Down
9 changes: 7 additions & 2 deletions MSSPM_GuiEstimation/nmfEstimationTab02.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ nmfEstimation_Tab2::nmfEstimation_Tab2(QTabWidget *tabs,
m_ProjectDir = projectDir;
m_ModelName.clear();
m_ProjectName.clear();
m_NumSignificantDigits = -1;

m_Logger->logMsg(nmfConstants::Normal,"nmfEstimation_Tab2::nmfEstimation_Tab2");

Expand Down Expand Up @@ -325,6 +326,10 @@ nmfEstimation_Tab2::readSettings()
m_ProjectName = settings->value("ProjectName","").toString().toStdString();
settings->endGroup();

settings->beginGroup("Preferences");
m_NumSignificantDigits = settings->value("NumSignificantDigits",-1).toInt();
settings->endGroup();

delete settings;
}

Expand Down Expand Up @@ -397,9 +402,9 @@ nmfEstimation_Tab2::loadWidgets()
for (int j=0; j<NumSpecies; ++j) {
for (int i=0; i<=RunLength; ++i) {
if ((m < NumRecords) && (SpeciesNames[j].toStdString() == dataMap["SpeName"][m])) {
valueWithComma = locale.toString(std::stod(dataMap["Value"][m++]));
valueWithComma = nmfUtilsQt::checkAndCalculateWithSignificantDigits(
std::stod(dataMap["Value"][m++]),m_NumSignificantDigits,2);
item = new QStandardItem(valueWithComma);
// item = new QStandardItem(QString::fromStdString(dataMap["Value"][m++]));
} else {
item = new QStandardItem(QString(""));
}
Expand Down
1 change: 1 addition & 0 deletions MSSPM_GuiEstimation/nmfEstimationTab02.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class nmfEstimation_Tab2: public QObject
std::string m_HarvestType;
std::map<std::string,std::string> m_GroupBoxTitle;
QStandardItemModel* m_SModel;
int m_NumSignificantDigits;

QTabWidget* Estimation_Tabs;
QWidget* Estimation_Tab2_Widget;
Expand Down
14 changes: 10 additions & 4 deletions MSSPM_GuiEstimation/nmfEstimationTab05.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ nmfEstimation_Tab5::nmfEstimation_Tab5(QTabWidget *tabs,
m_SModelCovariates = nullptr;
// assuming that the default is light.
m_IsDark = false;
m_NumSignificantDigits = -1;

m_Logger->logMsg(nmfConstants::Normal,"nmfEstimation_Tab5::nmfEstimation_Tab5");

Expand Down Expand Up @@ -303,7 +304,7 @@ nmfEstimation_Tab5::saveAbsoluteBiomass()
QString msg;
QString valueWithoutComma;

if ((m_SModelAbsoluteBiomass == NULL)||(m_SModelCovariates == NULL)) {
if ((m_SModelAbsoluteBiomass == NULL) || (m_SModelCovariates == NULL)) {
return false;
}
SpeciesKMin.clear();
Expand All @@ -314,7 +315,8 @@ nmfEstimation_Tab5::saveAbsoluteBiomass()
dataMap = m_DatabasePtr->nmfQueryDatabase(queryStr, fields);
NumSpecies = dataMap["SpeName"].size();
for (int species=0; species<NumSpecies; ++species) {
SpeciesKMin.push_back(std::stod(dataMap["SpeciesKMin"][species]));
valueWithoutComma = QString::fromStdString(dataMap["SpeciesKMin"][species]).remove(",");
SpeciesKMin.push_back(valueWithoutComma.toDouble());
SpeNames.push_back(dataMap["SpeName"][species]);
}

Expand Down Expand Up @@ -589,6 +591,10 @@ nmfEstimation_Tab5::readSettings()
m_ProjectName = settings->value("ProjectName","").toString().toStdString();
settings->endGroup();

settings->beginGroup("Preferences");
m_NumSignificantDigits = settings->value("NumSignificantDigits",-1).toInt();
settings->endGroup();

delete settings;
}

Expand Down Expand Up @@ -706,9 +712,9 @@ nmfEstimation_Tab5::loadTableValuesFromDatabase(
for (int j=0; j<NumSpecies; ++j) {
for (int i=0; i<=RunLength; ++i) {
if ((m < NumRecords) && (SpeciesNames[j] == dataMap["SpeName"][m])) {
valueWithComma = locale.toString(std::stod(dataMap["Value"][m++]),'f',6);
valueWithComma = nmfUtilsQt::checkAndCalculateWithSignificantDigits(
std::stod(dataMap["Value"][m++]),m_NumSignificantDigits,6);
item = new QStandardItem(valueWithComma);
// item = new QStandardItem(QString::number(std::stod(dataMap["Value"][m++]),'f',6));
} else {
item = new QStandardItem(QString(""));
}
Expand Down
1 change: 1 addition & 0 deletions MSSPM_GuiEstimation/nmfEstimationTab05.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class nmfEstimation_Tab5: public QObject
std::string m_ProjectName;
std::string m_ModelName;
bool m_IsDark;
int m_NumSignificantDigits;
QStandardItemModel* m_SModelAbsoluteBiomass;
QStandardItemModel* m_SModelRelativeBiomass;
QStandardItemModel* m_SModelCovariates;
Expand Down
Loading

0 comments on commit 2e5355c

Please sign in to comment.