kexi
kexicsvimportdialog.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef KEXI_CSVDIALOG_H
00029 #define KEXI_CSVDIALOG_H
00030
00031 #include <qvaluevector.h>
00032 #include <qvaluelist.h>
00033 #include <qptrvector.h>
00034 #include <qregexp.h>
00035 #include <qbitarray.h>
00036
00037 #include <kdialogbase.h>
00038
00039 #include <kexiutils/tristate.h>
00040 #include <kexidb/connection.h>
00041
00042 class QVBoxLayout;
00043 class QHBoxLayout;
00044 class QGridLayout;
00045 class QButtonGroup;
00046 class QCheckBox;
00047 class QLabel;
00048 class QLineEdit;
00049 class QPushButton;
00050 class QRadioButton;
00051 class QTable;
00052 class QFile;
00053 class KComboBox;
00054 class KIntSpinBox;
00055 class KProgressDialog;
00056
00057 class KexiMainWindow;
00058 class KexiCSVDelimiterWidget;
00059 class KexiCSVTextQuoteComboBox;
00060 class KexiCSVInfoLabel;
00061
00076 class KexiCSVImportDialog : public KDialogBase
00077 {
00078 Q_OBJECT
00079
00080 public:
00081
00082 enum Mode { Clipboard, File };
00083 enum Header { TEXT, NUMBER, DATE, CURRENCY };
00084
00086 KexiCSVImportDialog( Mode mode, KexiMainWindow* mainWin, QWidget * parent,
00087 const char * name = 0);
00088
00089 ~KexiCSVImportDialog();
00090
00091 bool cancelled() const;
00092 virtual bool eventFilter ( QObject * watched, QEvent * e );
00093
00094 protected:
00095 bool openData();
00096 virtual void accept();
00097
00098
00099 private:
00100 QGridLayout* MyDialogLayout;
00101 QHBoxLayout* Layout1;
00102 QTable* m_table;
00103 KexiCSVDelimiterWidget* m_delimiterWidget;
00104 QString m_formatComboText;
00105 QLabel* m_formatLabel;
00106 KComboBox* m_formatCombo;
00107 KIntSpinBox *m_startAtLineSpinBox;
00108 KexiCSVTextQuoteComboBox* m_comboQuote;
00109 QLabel* m_startAtLineLabel;
00110 QLabel* TextLabel2;
00111 QCheckBox* m_ignoreDuplicates;
00112 QCheckBox* m_1stRowForFieldNames;
00113 QCheckBox* m_primaryKeyField;
00114
00115 KexiMainWindow* m_mainWin;
00116
00117 void detectTypeAndUniqueness(int row, int col, const QString& text);
00118 void setText(int row, int col, const QString& text, bool inGUI);
00119
00125 bool parseDate(const QString& text, QDate& date);
00126
00132 bool parseTime(const QString& text, QTime& time);
00133
00135 void adjustRows(int iRows);
00136
00137 int getHeader(int col);
00138 QString getText(int row, int col);
00139 void updateColumnText(int col);
00140 void updateRowCountInfo();
00141 tristate loadRows(QString &field, int &row, int &columnm, int &maxColumn, bool inGUI);
00143 QString detectDelimiterByLookingAtFirstBytesOfFile(QTextStream& inputStream);
00144
00147 bool saveRow(bool inGUI);
00148
00149 bool m_cancelled;
00150 int m_adjustRows;
00151 int m_startline;
00152 QChar m_textquote;
00153 QString m_clipboardData;
00154 QByteArray m_fileArray;
00155 Mode m_mode;
00156 int m_prevSelectedCol;
00157
00160 QValueVector<int> m_detectedTypes;
00161
00164 QPtrVector< QValueList<int> > m_uniquenessTest;
00165
00166 QRegExp m_dateRegExp, m_timeRegExp1, m_timeRegExp2, m_fpNumberRegExp;
00167 QValueVector<QString> m_typeNames, m_columnNames;
00168 QBitArray m_changedColumnNames;
00169 bool m_columnsAdjusted : 1;
00170 bool m_1stRowForFieldNamesDetected : 1;
00171 bool m_firstFillTableCall : 1;
00172 bool m_blockUserEvents : 1;
00173 int m_primaryKeyColumn;
00174 int m_maximumRowsForPreview;
00175 int m_maximumBytesForPreview;
00176 QPixmap m_pkIcon;
00177 QString m_fname;
00178 QFile* m_file;
00179 QTextStream *m_inputStream;
00180 QString m_encoding;
00181 KProgressDialog *m_loadingProgressDlg, *m_importingProgressDlg;
00182 bool m_dialogCancelled;
00183 KexiCSVInfoLabel *m_infoLbl;
00184 KexiDB::Connection *m_conn;
00185 KexiDB::TableSchema *m_destinationTableSchema;
00186 KexiDB::PreparedStatement::Ptr m_importingStatement;
00187 QValueList<QVariant> m_dbRowBuffer;
00188 bool m_implicitPrimaryKeyAdded;
00189 bool m_allRowsLoadedInPreview;
00190 bool m_stoppedAt_MAX_BYTES_TO_PREVIEW;
00191
00192 private slots:
00193 void fillTable();
00194 void initLater();
00195 void formatChanged(int id);
00196 void delimiterChanged(const QString& delimiter);
00197 void startlineSelected(int line);
00198 void textquoteSelected(int);
00199 void currentCellChanged(int, int col);
00200 void ignoreDuplicatesChanged(int);
00201 void slot1stRowForFieldNamesChanged(int);
00202 void cellValueChanged(int row,int col);
00203 void optionsButtonClicked();
00204 void slotPrimaryKeyFieldToggled(bool on);
00205 };
00206
00207 #endif
|