QtiPlot  0.9.8.2
ImportASCIIDialog.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : ImportASCIIDialog.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2006,2007 by Ion Vasilief, Knut Franke
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr, knut.franke*gmx.de
00007     Description          : Import ASCII file(s) dialog
00008 
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *  This program is free software; you can redistribute it and/or modify   *
00014  *  it under the terms of the GNU General Public License as published by   *
00015  *  the Free Software Foundation; either version 2 of the License, or      *
00016  *  (at your option) any later version.                                    *
00017  *                                                                         *
00018  *  This program is distributed in the hope that it will be useful,        *
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00021  *  GNU General Public License for more details.                           *
00022  *                                                                         *
00023  *   You should have received a copy of the GNU General Public License     *
00024  *   along with this program; if not, write to the Free Software           *
00025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00026  *   Boston, MA  02110-1301  USA                                           *
00027  *                                                                         *
00028  ***************************************************************************/
00029 #ifndef IMPORTFILESDIALOG_H
00030 #define IMPORTFILESDIALOG_H
00031 
00032 #include <ExtensibleFileDialog.h>
00033 
00034 #include <QComboBox>
00035 #include <QCheckBox>
00036 #include <QSpinBox>
00037 #include <QLineEdit>
00038 #include <QTableView>
00039 
00040 class QGroupBox;
00041 class QPushButton;
00042 class QStackedWidget;
00043 class QLabel;
00044 class Matrix;
00045 class MatrixModel;
00046 
00047 #include <q3table.h>
00048 #include <q3header.h>
00049 
00050 class PreviewTable : public Q3Table
00051 {
00052     Q_OBJECT
00053 
00054 public:
00055     PreviewTable(int numRows, int numCols, QWidget * parent = 0, const char * name = 0);
00056 
00057     void importASCII(const QString &fname, const QString &sep, int ignoredLines, bool renameCols,
00058         bool stripSpaces, bool simplifySpaces, bool importComments, const QString& commentString,
00059         int importMode, const QLocale& importLocale, int endLine, int maxRows);
00060 
00061     void resetHeader();
00062     void clear();
00063     void setNumericPrecision(int prec) {d_numeric_precision = prec;};
00064     QList<int> columnTypes(){return colTypes;};
00065     QStringList columnFormats(){return d_col_format;};
00066     void showColTypeDialog();
00067     void setSelectedColumn(int col);
00068 
00069 signals:
00070     void modifiedColumnType();
00071 
00072 private slots:
00073     void setColumnType(int);
00074     void setColumnFormat(const QString&);
00075     void setHeader();
00076     void prevColumn();
00077     void nextColumn();
00078     void updateColumn(int sc);
00079     bool eventFilter(QObject *object, QEvent *e);
00080 
00081 private:
00082     void addColumns(int c);
00083     QStringList comments, col_label;
00084     int d_numeric_precision, d_start_col;
00085     QList<int> colTypes;
00086     QStringList d_col_format;
00087     int d_selected_column;
00088 
00089     QComboBox *formatBox, *typesBox;
00090     QLabel *formatLabel;
00091     QPushButton *buttonNext, *buttonPrev;
00092     QGroupBox *gb1;
00093 };
00094 
00095 class PreviewMatrix : public QTableView
00096 {
00097 public:
00098     PreviewMatrix(QWidget *parent, Matrix * m = 0);
00099 
00100     void importASCII(const QString &fname, const QString &sep, int ignoredLines,
00101         bool stripSpaces, bool simplifySpaces, const QString& commentString,
00102         int importAs, const QLocale& locale, int endLine, int maxRows);
00103 
00104     void clear();
00105 
00106 private:
00107      MatrixModel *d_matrix_model;
00108 };
00109 
00111 class ImportASCIIDialog: public ExtensibleFileDialog
00112 {
00113     Q_OBJECT
00114 
00115 public:
00117 
00120     enum ImportMode {
00121         NewTables, 
00122         NewMatrices, 
00123         NewColumns, 
00124         NewRows, 
00125         Overwrite 
00126     };
00127 
00129 
00135     ImportASCIIDialog(bool new_windows_only, QWidget * parent = 0, bool extended = true, Qt::WFlags flags = 0 );
00136 
00138 
00141     ImportMode importMode() const { return (ImportMode) d_import_mode->currentIndex(); }
00143     const QString columnSeparator() const;
00145     int ignoredLines() const { return d_ignored_lines->value(); }
00147     bool renameColumns() const { return d_rename_columns->isChecked() && !d_first_line_role->currentIndex(); };
00148     bool useFirstRow() const { return d_rename_columns->isChecked();};
00150     bool simplifySpaces() const { return d_simplify_spaces->isChecked(); };
00152     bool stripSpaces() const { return d_strip_spaces->isChecked(); };
00154     bool readOnly() const {return d_read_only->isChecked(); };
00155 
00157     void setColumnSeparator(const QString &sep);
00158 
00160     QLocale decimalSeparators();
00161 
00163     QString commentString(){return d_comment_string->text();};
00164 
00166     bool importComments();
00167     bool useSecondRow() const { return d_import_comments->isChecked();};
00168 
00170     inline int endLineChar(){return boxEndLine->currentIndex();};
00171 
00172     QList<int> columnTypes(){if (d_preview_table) return d_preview_table->columnTypes(); return QList<int>();};
00173     QStringList columnFormats(){if (d_preview_table) return d_preview_table->columnFormats(); return QStringList();};
00174 
00175     void setCurrentPath(const QString& path);
00176 
00177 public slots:
00178     void selectFilter(const QString & filter);
00179 
00180 private slots:
00182     void displayHelp();
00183     void showColTypeDialog();
00185     void updateImportMode(int mode);
00186     void preview();
00187     void changePreviewFile(const QString& path);
00189     void enableTableOptions(bool on);
00190     void enableComments();
00191 
00192 private:
00193     void initPreview(int previewMode);
00194     void previewTable();
00195     void previewMatrix();
00196 
00197     void closeEvent(QCloseEvent*);
00199     void initAdvancedOptions();
00200     void setNewWindowsOnly(bool on);
00201 
00203     QGroupBox *d_advanced_options;
00204     QCheckBox *d_read_only, *d_omit_thousands_sep;
00205     QPushButton *d_help_button, *d_col_types_button;
00206     // the actual options
00207     QComboBox *d_import_mode, *d_column_separator, *boxDecimalSeparator, *boxEndLine;
00208     QSpinBox *d_ignored_lines, *d_preview_lines_box;
00209     QCheckBox *d_rename_columns, *d_simplify_spaces, *d_strip_spaces, *d_import_comments;
00210     QLineEdit *d_comment_string;
00211     PreviewTable *d_preview_table;
00212     PreviewMatrix *d_preview_matrix;
00213     QCheckBox *d_preview_button;
00214     QStackedWidget *d_preview_stack;
00215     QString d_current_path;
00216     QComboBox *d_first_line_role;
00217 };
00218 
00219 #endif