Fix some bugs and add preview table. ref #804.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-02-06 15:46:20 +02:00
parent 7c6b0d9f58
commit 7fedd20319
4 changed files with 229 additions and 30 deletions

View file

@ -981,6 +981,7 @@ void TMainWindow::ImportDataFromCSV()
dialog.SetWithHeader(qApp->Settings()->GetCSVWithHeader());
dialog.SetSelectedMib(qApp->Settings()->GetCSVCodec());
dialog.SetSeparator(qApp->Settings()->GetCSVSeparator());
dialog.ShowFilePreview(fileName);
if (dialog.exec() == QDialog::Accepted)
{
@ -3159,17 +3160,24 @@ void TMainWindow::ImportIndividualMeasurements(const QxtCsvModel &csv)
{
try
{
const QString name = csv.text(i, 0).simplified();
if (name.isEmpty())
{
ShowError(tr("Error in row %1. Measurement name is empty.").arg(i));
continue;
}
IndividualMeasurement measurement;
measurement.name = CheckMName(qApp->TrVars()->MFromUser(csv.text(i, 0).simplified()));
measurement.name = CheckMName(qApp->TrVars()->MFromUser(name));
measurement.value = VTranslateVars::TryFormulaFromUser(csv.text(i, 1), qApp->Settings()->GetOsSeparator());
const bool custom = csv.text(i, 0).simplified().startsWith(CustomMSign);
if (columns >= 3 && not custom)
if (columns > 2 && custom)
{
measurement.fullName = csv.text(i, 2).simplified();
}
if (columns >= 4 && not custom)
if (columns > 3 && custom)
{
measurement.description = csv.text(i, 3).simplified();
}
@ -3251,8 +3259,15 @@ void TMainWindow::ImportMultisizeMeasurements(const QxtCsvModel &csv)
{
try
{
const QString name = csv.text(i, 0).simplified();
if (name.isEmpty())
{
ShowError(tr("Error in row %1. Measurement name is empty.").arg(i));
continue;
}
MultisizeMeasurement measurement;
measurement.name = CheckMName(qApp->TrVars()->MFromUser(csv.text(i, 0).simplified()));
measurement.name = CheckMName(qApp->TrVars()->MFromUser(name));
measurement.base = ConverToDouble(csv.text(i, 1),
tr("Cannot convert base size value to double in column 2."));
@ -3264,12 +3279,12 @@ void TMainWindow::ImportMultisizeMeasurements(const QxtCsvModel &csv)
tr("Cannot convert size increase value to double in column 4."));
const bool custom = csv.text(i, 0).simplified().startsWith(CustomMSign);
if (columns >= 5 && not custom)
if (columns > 4 && custom)
{
measurement.fullName = csv.text(i, 4).simplified();
}
if (columns >= 6 && not custom)
if (columns > 5 && custom)
{
measurement.description = csv.text(i, 5).simplified();
}

View file

@ -29,7 +29,8 @@
#include "dialogexporttocsv.h"
#include "ui_dialogexporttocsv.h"
#include "../vmisc/vcommonsettings.h"
#include "../vcommonsettings.h"
#include "../qxtcsvmodel.h"
#include "../vabstractapplication.h"
#include <QPushButton>
@ -40,7 +41,8 @@
DialogExportToCSV::DialogExportToCSV(QWidget *parent)
: QDialog(parent),
ui(new Ui::DialogExportToCSV),
isInitialized(false)
isInitialized(false),
m_fileName()
{
ui->setupUi(this);
@ -57,11 +59,27 @@ DialogExportToCSV::DialogExportToCSV(QWidget *parent)
SCASSERT(bDefaults != nullptr)
connect(bDefaults, &QPushButton::clicked, this, [this]()
{
ui->comboBoxCodec->blockSignals(true);
ui->checkBoxWithHeader->blockSignals(true);
ui->buttonGroup->blockSignals(true);
ui->checkBoxWithHeader->setChecked(qApp->Settings()->GetDefCSVWithHeader());
ui->comboBoxCodec->setCurrentIndex(ui->comboBoxCodec->findData(VCommonSettings::GetDefCSVCodec()));
SetSeparator(VCommonSettings::GetDefCSVSeparator());
ui->comboBoxCodec->blockSignals(false);
ui->checkBoxWithHeader->blockSignals(false);
ui->buttonGroup->blockSignals(false);
ShowPreview();
});
ui->groupBoxPreview->setVisible(false);
connect(ui->comboBoxCodec, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](){ShowPreview();});
connect(ui->checkBoxWithHeader, &QCheckBox::stateChanged, this, [this](){ShowPreview();});
connect(ui->buttonGroup, QOverload<int>::of(&QButtonGroup::buttonClicked), this, [this](){ShowPreview();});
}
//---------------------------------------------------------------------------------------------------------------------
@ -158,12 +176,71 @@ void DialogExportToCSV::showEvent(QShowEvent *event)
}
// do your init stuff here
setMaximumSize(size());
setMinimumSize(size());
resize(1, 1);
adjustSize();
if (not m_fileName.isEmpty())
{
ShowPreview();
}
else
{
setMaximumSize(size());
setMinimumSize(size());
}
isInitialized = true;//first show windows are held
}
//---------------------------------------------------------------------------------------------------------------------
void DialogExportToCSV::ShowPreview()
{
if (m_fileName.isEmpty())
{
return;
}
ui->groupBoxPreview->setVisible(true);
QxtCsvModel csv(m_fileName, nullptr, IsWithHeader(), GetSeparator(), QTextCodec::codecForMib(GetSelectedMib()));
const int columns = csv.columnCount();
const int rows = csv.rowCount();
ui->tableWidget->clear();
ui->tableWidget->setColumnCount(columns);
ui->tableWidget->setRowCount(rows);
ui->tableWidget->horizontalHeader()->setVisible(IsWithHeader());
if (IsWithHeader())
{
for(int column=0; column<columns; ++column)
{
QTableWidgetItem *header = new QTableWidgetItem(csv.headerText(column));
ui->tableWidget->setHorizontalHeaderItem(column, header);
}
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
}
for (int row=0; row < rows; ++row)
{
for(int column=0; column<columns; ++column)
{
QTableWidgetItem *item = new QTableWidgetItem(csv.text(row, column));
item->setToolTip(csv.text(row, column));
// set the item non-editable (view only), and non-selectable
Qt::ItemFlags flags = item->flags();
flags &= ~(Qt::ItemIsEditable); // reset/clear the flag
item->setFlags(flags);
ui->tableWidget->setItem(row, column, item);
}
}
ui->tableWidget->resizeColumnsToContents();
ui->tableWidget->resizeRowsToContents();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogExportToCSV::SetSeparator(const QChar &separator)
{
@ -185,6 +262,12 @@ void DialogExportToCSV::SetSeparator(const QChar &separator)
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogExportToCSV::ShowFilePreview(const QString &fileName)
{
m_fileName = fileName;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogExportToCSV::MakeHelpCodecsList()
{

View file

@ -53,6 +53,8 @@ public:
QChar GetSeparator() const;
void SetSeparator(const QChar &separator);
void ShowFilePreview(const QString &fileName);
static QString MakeHelpCodecsList();
static QString MakeHelpSeparatorList();
@ -64,6 +66,9 @@ private:
Q_DISABLE_COPY(DialogExportToCSV)
Ui::DialogExportToCSV *ui;
bool isInitialized;
QString m_fileName;
void ShowPreview();
};
#endif // DIALOGEXPORTTOCSV_H

View file

@ -9,25 +9,25 @@
<rect>
<x>0</x>
<y>0</y>
<width>333</width>
<height>292</height>
<width>326</width>
<height>383</height>
</rect>
</property>
<property name="windowTitle">
<string>Export options</string>
<string>Options</string>
</property>
<property name="windowIcon">
<iconset resource="../share/resources/tapeicon.qrc">
<iconset resource="../../../app/tape/share/resources/tapeicon.qrc">
<normaloff>:/tapeicon/64x64/logo.png</normaloff>:/tapeicon/64x64/logo.png</iconset>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QGroupBox" name="groupBoxExport">
<widget class="QGroupBox" name="groupBoxGlobal">
<property name="title">
<string>Export</string>
<string>Global</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
@ -53,7 +53,27 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxCodec"/>
<widget class="QComboBox" name="comboBoxCodec">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
@ -62,12 +82,36 @@
</item>
<item>
<widget class="QGroupBox" name="groupBoxSeparator">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Separator</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="formAlignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
<item row="0" column="0">
<widget class="QRadioButton" name="radioButtonTab">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Tab</string>
</property>
@ -76,8 +120,30 @@
</attribute>
</widget>
</item>
<item>
<item row="2" column="0">
<widget class="QRadioButton" name="radioButtonSemicolon">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Semicolon</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="radioButtonComma">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Comma</string>
</property>
@ -89,23 +155,53 @@
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonSemicolon">
<item row="2" column="1">
<widget class="QRadioButton" name="radioButtonSpace">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Semicolon</string>
<string>Space</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBoxPreview">
<property name="title">
<string>Preview</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QRadioButton" name="radioButtonSpace">
<property name="text">
<string>Space</string>
<widget class="QTableWidget" name="tableWidget">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
<property name="tabKeyNavigation">
<bool>false</bool>
</property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
<property name="dragDropOverwriteMode">
<bool>false</bool>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
@ -125,7 +221,7 @@
</layout>
</widget>
<resources>
<include location="../share/resources/tapeicon.qrc"/>
<include location="../../../app/tape/share/resources/tapeicon.qrc"/>
</resources>
<connections>
<connection>