void ParamCompareDialog::populateParamListFromString(QString paramString, QMap<QString, UASParameter*>* list) { QStringList paramSplit = paramString.split("\n"); foreach (QString paramLine, paramSplit) { if (!paramLine.startsWith("#")) { QStringList lineSplit = paramLine.split(","); if (lineSplit.size() == 2) { bool ok; QLOG_DEBUG() << "load param: " << lineSplit[0] << "=" << lineSplit[1]; UASParameter* param = new UASParameter(); param->setName(lineSplit[0]); double value = lineSplit[1].toFloat(&ok); if (ok){ param->setValue(QVariant(value)); } else { QLOG_ERROR() << "Conversion Failure"; param->setValue(QVariant("NaN")); } list->insert(param->name(), param); } } else { QLOG_DEBUG() << "Comment: " << paramLine; } } }
void ParamCompareDialog::populateParamListFromString(QString paramString, QMap<QString, UASParameter*>* list, QWidget* widget = NULL) { QStringList paramSplit = paramString.split("\n"); bool summaryComplete = false; bool summaryShown = false; QString summaryText; foreach (QString paramLine, paramSplit) { if (!paramLine.startsWith("#")) { summaryComplete = true; QStringList lineSplit = paramLine.split(","); if (lineSplit.size() == 2) { bool ok; QLOG_DEBUG() << "load param: " << lineSplit[0] << "=" << lineSplit[1]; UASParameter* param = new UASParameter(); param->setName(lineSplit[0]); double value = lineSplit[1].toFloat(&ok); if (ok){ param->setValue(QVariant(value)); } else { QLOG_ERROR() << "Conversion Failure"; param->setValue(QVariant("NaN")); } list->insert(param->name(), param); } } else { QLOG_DEBUG() << "Comment: " << paramLine; if (!summaryShown && !summaryComplete){ // removes the '#' and any whites space before or after summaryText.append(paramLine.remove(0,1).trimmed() + "\n"); } } if (!summaryShown && summaryComplete){ QLOG_DEBUG() << "Show Summary: " << summaryText; if (summaryText.count()>0){ QMessageBox::information(widget,tr("Param File Summary"),summaryText,QMessageBox::Ok); } summaryShown = true; } } }
void ParamCompareDialog::saveNewParameters() { QLOG_DEBUG() << " Save selected Parameters"; QTableWidget* table = ui->compareTableWidget; for(int rowCount = 0; rowCount < table->rowCount(); ++rowCount){ // Get hold of the UASParameter QTableWidgetItem* paramName = table->item(rowCount, PCD_COLUMN_PARAM_NAME); QTableWidgetItem* paramCheck= table->item(rowCount, PCD_COLUMN_CHECKBOX); if (paramName && (paramCheck->checkState() == Qt::Checked)){ UASParameter* param = m_currentList->value(paramName->text()); // then update it's value in the current list // [TODO] this would be an action of the Param Manager param->setValue(table->item(rowCount, PCD_COLUMN_NEW_VALUE)->data(Qt::DisplayRole)); QLOG_DEBUG() << "Applied to m_currentList:" << param << " = " << table->item(rowCount, PCD_COLUMN_NEW_VALUE)->data(Qt::DisplayRole); } } accept(); // dismiss the dialog }
void ParamCompareDialog::compareLists() { QList<QString> keys = m_newList->keys(); // This needs to be an amalgamated list of all keys ui->compareTableWidget->setSortingEnabled(false); for(int count = 0; count < keys.count(); ++count){ UASParameter* currentParam = m_currentList->value(keys[count]); if (currentParam != NULL){ UASParameter* newParam = m_newList->value(keys[count]); if (currentParam->value() != newParam->value() ){ QLOG_DEBUG() << "Difference : " << currentParam->name() << " current: " << currentParam->value() << " new:" << newParam->value(); int rowCount = ui->compareTableWidget->rowCount(); ui->compareTableWidget->setRowCount(ui->compareTableWidget->rowCount()+1); QTableWidgetItem* widgetItemParam = new QTableWidgetItem(keys[count]); widgetItemParam->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled ); ui->compareTableWidget->setItem(rowCount, PCD_COLUMN_PARAM_NAME, widgetItemParam); QTableWidgetItem* widgetItemValue = new QTableWidgetItem(); widgetItemValue->setData(Qt::DisplayRole, currentParam->value()); widgetItemValue->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled); ui->compareTableWidget->setItem(rowCount, PCD_COLUMN_VALUE, widgetItemValue); QTableWidgetItem* widgetItemNewValue = new QTableWidgetItem(); widgetItemNewValue->setData(Qt::DisplayRole, newParam->value()); widgetItemNewValue->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled | Qt::ItemIsEditable); ui->compareTableWidget->setItem(rowCount, PCD_COLUMN_NEW_VALUE, widgetItemNewValue); QTableWidgetItem* widgetItemCheckbox= new QTableWidgetItem(); widgetItemCheckbox->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable); widgetItemCheckbox->setCheckState(Qt::Checked); ui->compareTableWidget->setItem(rowCount, PCD_COLUMN_CHECKBOX, widgetItemCheckbox); } } else { // [TODO] add in a blanck entry? } } }