<commit_before>/*===================================================================
APM_PLANNER Open Source Ground Control Station

(c) 2013 APM_PLANNER PROJECT <http://www.diydrones.com>

This file is part of the APM_PLANNER project

    APM_PLANNER 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.

    APM_PLANNER 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 APM_PLANNER. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

#include "AdvParameterList.h"
#include "DownloadRemoteParamsDialog.h"
#include "ParamCompareDialog.h"
#include "QsLog.h"
#include <QTableWidgetItem>
#include <QInputDialog>
#include <QFileDialog>
#include <QFile>
#include <QMessageBox>
#include <QProgressDialog>
#include <QDesktopServices>

#define ADV_TABLE_COLUMN_PARAM 0
#define ADV_TABLE_COLUMN_VALUE 1
#define ADV_TABLE_COLUMN_UNIT 2
#define ADV_TABLE_COLUMN_RANGE 3
#define ADV_TABLE_COLUMN_DESCRIPTION 4
#define ADV_TABLE_COLUMN_COUNT ADV_TABLE_COLUMN_DESCRIPTION + 1

AdvParameterList::AdvParameterList(QWidget *parent) : AP2ConfigWidget(parent),
    m_searchIndex(0),
    m_paramDownloadState(starting),
    m_paramDownloadCount(0),
    m_writingParams(false),
    m_paramsWritten(0),
    m_paramsToWrite(0),
    m_fileDialog(NULL)
{
    ui.setupUi(this);
    connect(ui.refreshPushButton, SIGNAL(clicked()),this, SLOT(refreshButtonClicked()));
    connect(ui.writePushButton, SIGNAL(clicked()),this, SLOT(writeButtonClicked()));
    connect(ui.loadPushButton, SIGNAL(clicked()),this, SLOT(loadButtonClicked()));
    connect(ui.savePushButton, SIGNAL(clicked()),this, SLOT(saveButtonClicked()));
    connect(ui.tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)),
            this, SLOT(tableWidgetItemChanged(QTableWidgetItem*)));
    connect(ui.downloadRemoteButton, SIGNAL(clicked()),this, SLOT(downloadRemoteFiles()));
    connect(ui.compareButton,SIGNAL(clicked()),this, SLOT(compareButtonClicked()));

    connect(ui.searchLineEdit, SIGNAL(textEdited(QString)), this, SLOT(findStringInTable(QString)));
    connect(ui.nextItemButton, SIGNAL(clicked()), this, SLOT(nextItemInSearch()));
    connect(ui.previousItemButton, SIGNAL(clicked()), this, SLOT(previousItemInSearch()));
    connect(ui.resetButton, SIGNAL(clicked()), this, SLOT(resetButtonClicked()));


    ui.tableWidget->setColumnCount(ADV_TABLE_COLUMN_COUNT);
    ui.tableWidget->verticalHeader()->hide();
    ui.tableWidget->setColumnWidth(ADV_TABLE_COLUMN_PARAM,200);
    ui.tableWidget->setColumnWidth(ADV_TABLE_COLUMN_VALUE,100);
    ui.tableWidget->setColumnWidth(ADV_TABLE_COLUMN_UNIT,100);
    ui.tableWidget->setColumnWidth(ADV_TABLE_COLUMN_DESCRIPTION,800);
    ui.tableWidget->setHorizontalHeaderItem(ADV_TABLE_COLUMN_PARAM, new QTableWidgetItem("Param"));
    ui.tableWidget->setHorizontalHeaderItem(ADV_TABLE_COLUMN_VALUE, new QTableWidgetItem("Value"));
    ui.tableWidget->setHorizontalHeaderItem(ADV_TABLE_COLUMN_UNIT, new QTableWidgetItem("Unit"));
    ui.tableWidget->setHorizontalHeaderItem(ADV_TABLE_COLUMN_RANGE, new QTableWidgetItem("Range"));
    ui.tableWidget->setHorizontalHeaderItem(ADV_TABLE_COLUMN_DESCRIPTION,new QTableWidgetItem("Description"));
    ui.tableWidget->horizontalHeaderItem(ADV_TABLE_COLUMN_DESCRIPTION)->setTextAlignment(Qt::AlignLeft);

    ui.paramProgressBar->setRange(0,0);
    ui.paramProgressBar->hide();
    ui.progressLabel->hide();

    initConnections();
}
void AdvParameterList::tableWidgetItemChanged(QTableWidgetItem* item)
{
    if (!ui.tableWidget->item(item->row(),ADV_TABLE_COLUMN_VALUE)
            || !ui.tableWidget->item(item->row(),ADV_TABLE_COLUMN_PARAM))
    {
        //Invalid item, something has gone awry.
        return;
    }
    if (item->column() != ADV_TABLE_COLUMN_VALUE)
    {
        //Don't want to edit values that aren't actual values
        return;
    }
    QLocale locallocale;
    bool ok = false;
    double number = locallocale.toDouble(item->text(),&ok);
    if (!ok)
    {
        //Failed to convert
        QMessageBox::warning(this,"Error","Failed to convert number, please verify your input and try again");
        disconnect(ui.tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)),this, SLOT(tableWidgetItemChanged(QTableWidgetItem*)));
        ui.tableWidget->item(item->row(),ADV_TABLE_COLUMN_VALUE)->setText(m_paramToOrigValueMap[ui.tableWidget->item(item->row(),ADV_TABLE_COLUMN_PARAM)->text()]);
        connect(ui.tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)),this, SLOT(tableWidgetItemChanged(QTableWidgetItem*)));
        return;
    }

    m_origBrushList.append(ui.tableWidget->item(item->row(),ADV_TABLE_COLUMN_PARAM)->text());
    QBrush brush = QBrush(QColor::fromRgb(132,181,132));<commit_msg>Full Parameter View: Fix locale to use ‘decimal’ only<commit_after>/*===================================================================
APM_PLANNER Open Source Ground Control Station

(c) 2013 APM_PLANNER PROJECT <http://www.diydrones.com>

This file is part of the APM_PLANNER project

    APM_PLANNER 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.

    APM_PLANNER 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 APM_PLANNER. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

#include "AdvParameterList.h"
#include "DownloadRemoteParamsDialog.h"
#include "ParamCompareDialog.h"
#include "QsLog.h"
#include <QTableWidgetItem>
#include <QInputDialog>
#include <QFileDialog>
#include <QFile>
#include <QMessageBox>
#include <QProgressDialog>
#include <QDesktopServices>

#define ADV_TABLE_COLUMN_PARAM 0
#define ADV_TABLE_COLUMN_VALUE 1
#define ADV_TABLE_COLUMN_UNIT 2
#define ADV_TABLE_COLUMN_RANGE 3
#define ADV_TABLE_COLUMN_DESCRIPTION 4
#define ADV_TABLE_COLUMN_COUNT ADV_TABLE_COLUMN_DESCRIPTION + 1

AdvParameterList::AdvParameterList(QWidget *parent) : AP2ConfigWidget(parent),
    m_searchIndex(0),
    m_paramDownloadState(starting),
    m_paramDownloadCount(0),
    m_writingParams(false),
    m_paramsWritten(0),
    m_paramsToWrite(0),
    m_fileDialog(NULL)
{
    ui.setupUi(this);
    connect(ui.refreshPushButton, SIGNAL(clicked()),this, SLOT(refreshButtonClicked()));
    connect(ui.writePushButton, SIGNAL(clicked()),this, SLOT(writeButtonClicked()));
    connect(ui.loadPushButton, SIGNAL(clicked()),this, SLOT(loadButtonClicked()));
    connect(ui.savePushButton, SIGNAL(clicked()),this, SLOT(saveButtonClicked()));
    connect(ui.tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)),
            this, SLOT(tableWidgetItemChanged(QTableWidgetItem*)));
    connect(ui.downloadRemoteButton, SIGNAL(clicked()),this, SLOT(downloadRemoteFiles()));
    connect(ui.compareButton,SIGNAL(clicked()),this, SLOT(compareButtonClicked()));

    connect(ui.searchLineEdit, SIGNAL(textEdited(QString)), this, SLOT(findStringInTable(QString)));
    connect(ui.nextItemButton, SIGNAL(clicked()), this, SLOT(nextItemInSearch()));
    connect(ui.previousItemButton, SIGNAL(clicked()), this, SLOT(previousItemInSearch()));
    connect(ui.resetButton, SIGNAL(clicked()), this, SLOT(resetButtonClicked()));


    ui.tableWidget->setColumnCount(ADV_TABLE_COLUMN_COUNT);
    ui.tableWidget->verticalHeader()->hide();
    ui.tableWidget->setColumnWidth(ADV_TABLE_COLUMN_PARAM,200);
    ui.tableWidget->setColumnWidth(ADV_TABLE_COLUMN_VALUE,100);
    ui.tableWidget->setColumnWidth(ADV_TABLE_COLUMN_UNIT,100);
    ui.tableWidget->setColumnWidth(ADV_TABLE_COLUMN_DESCRIPTION,800);
    ui.tableWidget->setHorizontalHeaderItem(ADV_TABLE_COLUMN_PARAM, new QTableWidgetItem("Param"));
    ui.tableWidget->setHorizontalHeaderItem(ADV_TABLE_COLUMN_VALUE, new QTableWidgetItem("Value"));
    ui.tableWidget->setHorizontalHeaderItem(ADV_TABLE_COLUMN_UNIT, new QTableWidgetItem("Unit"));
    ui.tableWidget->setHorizontalHeaderItem(ADV_TABLE_COLUMN_RANGE, new QTableWidgetItem("Range"));
    ui.tableWidget->setHorizontalHeaderItem(ADV_TABLE_COLUMN_DESCRIPTION,new QTableWidgetItem("Description"));
    ui.tableWidget->horizontalHeaderItem(ADV_TABLE_COLUMN_DESCRIPTION)->setTextAlignment(Qt::AlignLeft);

    ui.paramProgressBar->setRange(0,0);
    ui.paramProgressBar->hide();
    ui.progressLabel->hide();

    initConnections();
}
void AdvParameterList::tableWidgetItemChanged(QTableWidgetItem* item)
{
    if (!ui.tableWidget->item(item->row(),ADV_TABLE_COLUMN_VALUE)
            || !ui.tableWidget->item(item->row(),ADV_TABLE_COLUMN_PARAM))
    {
        //Invalid item, something has gone awry.
        return;
    }
    if (item->column() != ADV_TABLE_COLUMN_VALUE)
    {
        //Don't want to edit values that aren't actual values
        return;
    }

    // This is to force the use of '.' decimal as the seperator. ie use the 'C' locale.
    // thousand seperators are also rejected in 'C' locale
    bool ok = false;
    double number = item->text().toDouble(&ok);
    if (!ok)
    {
        //Failed to convert
        QMessageBox::warning(this,"Error","Failed to convert number, please verify your input uses '.' as decimal and no seperator and try again");
        disconnect(ui.tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)),this, SLOT(tableWidgetItemChanged(QTableWidgetItem*)));
        ui.tableWidget->item(item->row(),ADV_TABLE_COLUMN_VALUE)->setText(m_paramToOrigValueMap[ui.tableWidget->item(item->row(),ADV_TABLE_COLUMN_PARAM)->text()]);
        connect(ui.tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)),this, SLOT(tableWidgetItemChanged(QTableWidgetItem*)));
        return;
    }

    m_origBrushList.append(ui.tableWidget->item(item->row(),ADV_TABLE_COLUMN_PARAM)->text());
    QBrush brush = QBrush(QColor::fromRgb(132,181,132));
{'fraction_non_alphanumeric': 0.14073724007561436, 'fraction_numerical': 0.007372400756143667, 'mean_word_length': 5.713832487309645, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '355935', 'n_tokens_mistral': 3317, 'n_tokens_neox': 3244, 'n_words': 619}