ImportASCIIDialog.h
Go to the documentation of this file.
/***************************************************************************
File : ImportASCIIDialog.h
Project : QtiPlot
--------------------------------------------------------------------
Copyright : (C) 2006,2007 by Ion Vasilief, Knut Franke
Email (use @ for *) : ion_vasilief*yahoo.fr, knut.franke*gmx.de
Description : Import ASCII file(s) dialog
***************************************************************************/
/***************************************************************************
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
***************************************************************************/
#ifndef IMPORTFILESDIALOG_H
#define IMPORTFILESDIALOG_H
#include <ExtensibleFileDialog.h>
#include <QComboBox>
#include <QCheckBox>
#include <QSpinBox>
#include <QLineEdit>
#include <QTableView>
class QGroupBox;
class QPushButton;
class QStackedWidget;
class QLabel;
class Matrix;
class MatrixModel;
#include <q3table.h>
#include <q3header.h>
class PreviewTable : public Q3Table
{
Q_OBJECT
public:
PreviewTable(int numRows, int numCols, QWidget * parent = 0, const char * name = 0);
void importASCII(const QString &fname, const QString &sep, int ignoredLines, bool renameCols,
bool stripSpaces, bool simplifySpaces, bool importComments, const QString& commentString,
int importMode, const QLocale& importLocale, int endLine, int maxRows);
void resetHeader();
void clear();
void setNumericPrecision(int prec) {d_numeric_precision = prec;};
QList<int> columnTypes(){return colTypes;};
QStringList columnFormats(){return d_col_format;};
void showColTypeDialog();
void setSelectedColumn(int col);
signals:
void modifiedColumnType();
private slots:
void setColumnType(int);
void setColumnFormat(const QString&);
void setHeader();
void prevColumn();
void nextColumn();
void updateColumn(int sc);
bool eventFilter(QObject *object, QEvent *e);
private:
void addColumns(int c);
QStringList comments, col_label;
int d_numeric_precision, d_start_col;
QList<int> colTypes;
QStringList d_col_format;
int d_selected_column;
QComboBox *formatBox, *typesBox;
QLabel *formatLabel;
QPushButton *buttonNext, *buttonPrev;
QGroupBox *gb1;
};
class PreviewMatrix : public QTableView
{
public:
PreviewMatrix(QWidget *parent, Matrix * m = 0);
void importASCII(const QString &fname, const QString &sep, int ignoredLines,
bool stripSpaces, bool simplifySpaces, const QString& commentString,
int importAs, const QLocale& locale, int endLine, int maxRows);
void clear();
private:
MatrixModel *d_matrix_model;
};
class ImportASCIIDialog: public ExtensibleFileDialog
{
Q_OBJECT
public:
enum ImportMode {
NewTables,
NewMatrices,
NewColumns,
NewRows,
Overwrite
};
ImportASCIIDialog(bool new_windows_only, QWidget * parent = 0, bool extended = true, Qt::WFlags flags = 0 );
ImportMode importMode() const { return (ImportMode) d_import_mode->currentIndex(); }
const QString columnSeparator() const;
int ignoredLines() const { return d_ignored_lines->value(); }
bool renameColumns() const { return d_rename_columns->isChecked() && !d_first_line_role->currentIndex(); };
bool useFirstRow() const { return d_rename_columns->isChecked();};
bool simplifySpaces() const { return d_simplify_spaces->isChecked(); };
bool stripSpaces() const { return d_strip_spaces->isChecked(); };
bool readOnly() const {return d_read_only->isChecked(); };
void setColumnSeparator(const QString &sep);
QLocale decimalSeparators();
QString commentString(){return d_comment_string->text();};
bool importComments();
bool useSecondRow() const { return d_import_comments->isChecked();};
inline int endLineChar(){return boxEndLine->currentIndex();};
QList<int> columnTypes(){if (d_preview_table) return d_preview_table->columnTypes(); return QList<int>();};
QStringList columnFormats(){if (d_preview_table) return d_preview_table->columnFormats(); return QStringList();};
void setCurrentPath(const QString& path);
public slots:
void selectFilter(const QString & filter);
private slots:
void displayHelp();
void showColTypeDialog();
void updateImportMode(int mode);
void preview();
void changePreviewFile(const QString& path);
void enableTableOptions(bool on);
void enableComments();
private:
void initPreview(int previewMode);
void previewTable();
void previewMatrix();
void closeEvent(QCloseEvent*);
void initAdvancedOptions();
void setNewWindowsOnly(bool on);
QGroupBox *d_advanced_options;
QCheckBox *d_read_only, *d_omit_thousands_sep;
QPushButton *d_help_button, *d_col_types_button;
// the actual options
QComboBox *d_import_mode, *d_column_separator, *boxDecimalSeparator, *boxEndLine;
QSpinBox *d_ignored_lines, *d_preview_lines_box;
QCheckBox *d_rename_columns, *d_simplify_spaces, *d_strip_spaces, *d_import_comments;
QLineEdit *d_comment_string;
PreviewTable *d_preview_table;
PreviewMatrix *d_preview_matrix;
QCheckBox *d_preview_button;
QStackedWidget *d_preview_stack;
QString d_current_path;
QComboBox *d_first_line_role;
};
#endif
ImportASCIIDialog::useSecondRow
bool useSecondRow() const
Definition: ImportASCIIDialog.h:167
ImportASCIIDialog::setColumnSeparator
void setColumnSeparator(const QString &sep)
Set the selected columns separator.
Definition: ImportASCIIDialog.cpp:324
ExtensibleFileDialog.h
ImportASCIIDialog::setNewWindowsOnly
void setNewWindowsOnly(bool on)
Definition: ImportASCIIDialog.cpp:535
ImportASCIIDialog::ignoredLines
int ignoredLines() const
Return the number of lines to be skipped at the start of each file.
Definition: ImportASCIIDialog.h:145
ImportASCIIDialog::Overwrite
replace content of current table with the selected file (like importing a single file in previous ver...
Definition: ImportASCIIDialog.h:125
ImportASCIIDialog::NewColumns
add each file as new columns to the current table
Definition: ImportASCIIDialog.h:123
MatrixModel
Definition: MatrixModel.h:43
ImportASCIIDialog::closeEvent
void closeEvent(QCloseEvent *)
Definition: ImportASCIIDialog.cpp:401
PreviewTable::buttonPrev
QPushButton * buttonPrev
Definition: ImportASCIIDialog.h:91
ImportASCIIDialog::columnTypes
QList< int > columnTypes()
Definition: ImportASCIIDialog.h:172
ImportASCIIDialog::endLineChar
int endLineChar()
Returns the convention used for the end line character!
Definition: ImportASCIIDialog.h:170
ImportASCIIDialog::NewTables
create a new table for each file (default)
Definition: ImportASCIIDialog.h:121
PreviewTable::d_selected_column
int d_selected_column
Definition: ImportASCIIDialog.h:87
PreviewTable::setHeader
void setHeader()
Definition: ImportASCIIDialog.cpp:803
PreviewTable::setColumnFormat
void setColumnFormat(const QString &)
Definition: ImportASCIIDialog.cpp:861
PreviewTable::updateColumn
void updateColumn(int sc)
Definition: ImportASCIIDialog.cpp:995
ImportASCIIDialog::d_ignored_lines
QSpinBox * d_ignored_lines
Definition: ImportASCIIDialog.h:208
ImportASCIIDialog::stripSpaces
bool stripSpaces() const
Whether to remove whitespace from beginning and end of lines.
Definition: ImportASCIIDialog.h:152
PreviewTable::setSelectedColumn
void setSelectedColumn(int col)
Definition: ImportASCIIDialog.cpp:855
ImportASCIIDialog::updateImportMode
void updateImportMode(int mode)
For Overwrite mode, allow only one file to be selected.
Definition: ImportASCIIDialog.cpp:386
PreviewMatrix::clear
void clear()
Definition: ImportASCIIDialog.cpp:1067
PreviewTable::resetHeader
void resetHeader()
Definition: ImportASCIIDialog.cpp:774
ImportASCIIDialog::NewRows
add each file as new rows to the current table
Definition: ImportASCIIDialog.h:124
ImportASCIIDialog::d_rename_columns
QCheckBox * d_rename_columns
Definition: ImportASCIIDialog.h:209
PreviewTable::columnTypes
QList< int > columnTypes()
Definition: ImportASCIIDialog.h:64
PreviewTable::buttonNext
QPushButton * buttonNext
Definition: ImportASCIIDialog.h:91
PreviewTable::colTypes
QList< int > colTypes
Definition: ImportASCIIDialog.h:85
ImportASCIIDialog::NewMatrices
create a new matrix for each file
Definition: ImportASCIIDialog.h:122
ImportASCIIDialog::preview
void preview()
Definition: ImportASCIIDialog.cpp:440
ImportASCIIDialog::d_preview_matrix
PreviewMatrix * d_preview_matrix
Definition: ImportASCIIDialog.h:212
PreviewTable::formatLabel
QLabel * formatLabel
Definition: ImportASCIIDialog.h:90
ImportASCIIDialog::initPreview
void initPreview(int previewMode)
Definition: ImportASCIIDialog.cpp:259
ImportASCIIDialog::d_import_comments
QCheckBox * d_import_comments
Definition: ImportASCIIDialog.h:209
ImportASCIIDialog::useFirstRow
bool useFirstRow() const
Definition: ImportASCIIDialog.h:148
ImportASCIIDialog::importMode
ImportMode importMode() const
Return the selected import mode.
Definition: ImportASCIIDialog.h:141
ImportASCIIDialog::setCurrentPath
void setCurrentPath(const QString &path)
Definition: ImportASCIIDialog.cpp:510
ImportASCIIDialog::renameColumns
bool renameColumns() const
Whether to rename columns based on the first (non-skipped) line.
Definition: ImportASCIIDialog.h:147
ImportASCIIDialog::d_simplify_spaces
QCheckBox * d_simplify_spaces
Definition: ImportASCIIDialog.h:209
PreviewTable::prevColumn
void prevColumn()
Definition: ImportASCIIDialog.cpp:985
ImportASCIIDialog::d_comment_string
QLineEdit * d_comment_string
Definition: ImportASCIIDialog.h:210
ImportASCIIDialog::d_import_mode
QComboBox * d_import_mode
Definition: ImportASCIIDialog.h:207
ImportASCIIDialog::selectFilter
void selectFilter(const QString &filter)
Definition: ImportASCIIDialog.cpp:562
PreviewTable::setNumericPrecision
void setNumericPrecision(int prec)
Definition: ImportASCIIDialog.h:63
ImportASCIIDialog::importComments
bool importComments()
Returns true if the second line of the ASCII file should be used to set comments in table...
Definition: ImportASCIIDialog.cpp:546
ImportASCIIDialog::previewTable
void previewTable()
Definition: ImportASCIIDialog.cpp:454
PreviewTable::nextColumn
void nextColumn()
Definition: ImportASCIIDialog.cpp:990
ImportASCIIDialog::d_read_only
QCheckBox * d_read_only
Definition: ImportASCIIDialog.h:204
ImportASCIIDialog::ImportMode
ImportMode
Possible destinations for the imported data.
Definition: ImportASCIIDialog.h:120
ImportASCIIDialog::showColTypeDialog
void showColTypeDialog()
Definition: ImportASCIIDialog.cpp:251
ImportASCIIDialog::d_preview_button
QCheckBox * d_preview_button
Definition: ImportASCIIDialog.h:213
PreviewTable::d_col_format
QStringList d_col_format
Definition: ImportASCIIDialog.h:86
ImportASCIIDialog::readOnly
bool readOnly() const
Whether the user wants the import options to be saved.
Definition: ImportASCIIDialog.h:154
ImportASCIIDialog::enableTableOptions
void enableTableOptions(bool on)
Enable/Disable options which are only available for tables.
Definition: ImportASCIIDialog.cpp:316
PreviewTable::columnFormats
QStringList columnFormats()
Definition: ImportASCIIDialog.h:65
ImportASCIIDialog::d_help_button
QPushButton * d_help_button
Definition: ImportASCIIDialog.h:205
ImportASCIIDialog::d_preview_table
PreviewTable * d_preview_table
Definition: ImportASCIIDialog.h:211
ImportASCIIDialog::d_col_types_button
QPushButton * d_col_types_button
Definition: ImportASCIIDialog.h:205
PreviewTable::typesBox
QComboBox * typesBox
Definition: ImportASCIIDialog.h:89
ImportASCIIDialog::boxDecimalSeparator
QComboBox * boxDecimalSeparator
Definition: ImportASCIIDialog.h:207
PreviewTable::col_label
QStringList col_label
Definition: ImportASCIIDialog.h:83
ImportASCIIDialog::changePreviewFile
void changePreviewFile(const QString &path)
Definition: ImportASCIIDialog.cpp:516
PreviewTable::addColumns
void addColumns(int c)
Definition: ImportASCIIDialog.cpp:813
Matrix
Matrix worksheet class.
Definition: Matrix.h:57
ImportASCIIDialog::commentString
QString commentString()
Returns a string used to comment lines when importing ASCII files.
Definition: ImportASCIIDialog.h:163
PreviewTable::showColTypeDialog
void showColTypeDialog()
Definition: ImportASCIIDialog.cpp:929
ImportASCIIDialog::d_first_line_role
QComboBox * d_first_line_role
Definition: ImportASCIIDialog.h:216
ImportASCIIDialog
Import ASCII file(s) dialog.
Definition: ImportASCIIDialog.h:111
ImportASCIIDialog::columnSeparator
const QString columnSeparator() const
Return the selected column separator.
Definition: ImportASCIIDialog.cpp:348
PreviewMatrix
Definition: ImportASCIIDialog.h:95
ImportASCIIDialog::d_column_separator
QComboBox * d_column_separator
Definition: ImportASCIIDialog.h:207
PreviewTable::eventFilter
bool eventFilter(QObject *object, QEvent *e)
Definition: ImportASCIIDialog.cpp:833
PreviewMatrix::d_matrix_model
MatrixModel * d_matrix_model
Definition: ImportASCIIDialog.h:107
ImportASCIIDialog::previewMatrix
void previewMatrix()
Definition: ImportASCIIDialog.cpp:487
ImportASCIIDialog::displayHelp
void displayHelp()
Display help for advanced options.
Definition: ImportASCIIDialog.cpp:370
ImportASCIIDialog::initAdvancedOptions
void initAdvancedOptions()
Initialise d_advanced_options and everything it contains.
Definition: ImportASCIIDialog.cpp:117
PreviewTable::d_start_col
int d_start_col
Definition: ImportASCIIDialog.h:84
ImportASCIIDialog::d_strip_spaces
QCheckBox * d_strip_spaces
Definition: ImportASCIIDialog.h:209
ImportASCIIDialog::boxEndLine
QComboBox * boxEndLine
Definition: ImportASCIIDialog.h:207
ImportASCIIDialog::columnFormats
QStringList columnFormats()
Definition: ImportASCIIDialog.h:173
ImportASCIIDialog::d_advanced_options
QGroupBox * d_advanced_options
Container widget for all advanced options.
Definition: ImportASCIIDialog.h:203
ImportASCIIDialog::d_omit_thousands_sep
QCheckBox * d_omit_thousands_sep
Definition: ImportASCIIDialog.h:204
PreviewTable::clear
void clear()
Definition: ImportASCIIDialog.cpp:795
ImportASCIIDialog::simplifySpaces
bool simplifySpaces() const
Whether to replace sequences of whitespace charecters with a single space.
Definition: ImportASCIIDialog.h:150
ImportASCIIDialog::decimalSeparators
QLocale decimalSeparators()
Returns a locale having the decimal separators set to user custom settings.
Definition: ImportASCIIDialog.cpp:416
PreviewTable::modifiedColumnType
void modifiedColumnType()
ImportASCIIDialog::d_preview_stack
QStackedWidget * d_preview_stack
Definition: ImportASCIIDialog.h:214
PreviewTable::d_numeric_precision
int d_numeric_precision
Definition: ImportASCIIDialog.h:84
PreviewTable::comments
QStringList comments
Definition: ImportASCIIDialog.h:83
ImportASCIIDialog::ImportASCIIDialog
ImportASCIIDialog(bool new_windows_only, QWidget *parent=0, bool extended=true, Qt::WFlags flags=0)
Constructor.
Definition: ImportASCIIDialog.cpp:52
ImportASCIIDialog::d_current_path
QString d_current_path
Definition: ImportASCIIDialog.h:215
PreviewTable::importASCII
void importASCII(const QString &fname, const QString &sep, int ignoredLines, bool renameCols, bool stripSpaces, bool simplifySpaces, bool importComments, const QString &commentString, int importMode, const QLocale &importLocale, int endLine, int maxRows)
Definition: ImportASCIIDialog.cpp:611
PreviewMatrix::importASCII
void importASCII(const QString &fname, const QString &sep, int ignoredLines, bool stripSpaces, bool simplifySpaces, const QString &commentString, int importAs, const QLocale &locale, int endLine, int maxRows)
Definition: ImportASCIIDialog.cpp:1058
ImportASCIIDialog::d_preview_lines_box
QSpinBox * d_preview_lines_box
Definition: ImportASCIIDialog.h:208
PreviewTable::formatBox
QComboBox * formatBox
Definition: ImportASCIIDialog.h:89
PreviewTable::setColumnType
void setColumnType(int)
Definition: ImportASCIIDialog.cpp:866
PreviewTable::PreviewTable
PreviewTable(int numRows, int numCols, QWidget *parent=0, const char *name=0)
Definition: ImportASCIIDialog.cpp:585
PreviewTable
Definition: ImportASCIIDialog.h:50
ExtensibleFileDialog
QFileDialog plus generic extension support.
Definition: ExtensibleFileDialog.h:44
ImportASCIIDialog::enableComments
void enableComments()
Definition: ImportASCIIDialog.cpp:556
PreviewMatrix::PreviewMatrix
PreviewMatrix(QWidget *parent, Matrix *m=0)
Definition: ImportASCIIDialog.cpp:1024
PreviewTable::gb1
QGroupBox * gb1
Definition: ImportASCIIDialog.h:92