File indexing completed on 2024-05-12 15:27:51
0001 /*************************************************************************** 0002 File : ImportSQLDatabaseWidget.cpp 0003 Project : LabPlot 0004 Description : SQLDatabase 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2016 by Ankit Wagadre (wagadre.ankit@gmail.com) 0007 Copyright : (C) 2016-2017 Alexander Semke (alexander.semke@web.de) 0008 0009 ***************************************************************************/ 0010 /*************************************************************************** 0011 * * 0012 * This program is free software; you can redistribute it and/or modify * 0013 * it under the terms of the GNU General Public License as published by * 0014 * the Free Software Foundation; either version 2 of the License, or * 0015 * (at your option) any later version. * 0016 * * 0017 * This program is distributed in the hope that it will be useful, * 0018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0020 * GNU General Public License for more details. * 0021 * * 0022 * You should have received a copy of the GNU General Public License * 0023 * along with this program; if not, write to the Free Software * 0024 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0025 * Boston, MA 02110-1301 USA * 0026 * * 0027 ***************************************************************************/ 0028 0029 #ifndef IMPORTSQLDATABASEWIDGET_H 0030 #define IMPORTSQLDATABASEWIDGET_H 0031 0032 #include <QSqlDatabase> 0033 #include "backend/core/AbstractColumn.h" 0034 #include "backend/datasources/filters/AbstractFileFilter.h" 0035 #include "ui_importsqldatabasewidget.h" 0036 0037 #ifdef HAVE_KF5_SYNTAX_HIGHLIGHTING 0038 #include <repository.h> 0039 namespace KSyntaxHighlighting { 0040 class SyntaxHighlighter; 0041 } 0042 #endif 0043 0044 class QStandardItemModel; 0045 0046 class ImportSQLDatabaseWidget : public QWidget { 0047 Q_OBJECT 0048 0049 public: 0050 explicit ImportSQLDatabaseWidget(QWidget*); 0051 ~ImportSQLDatabaseWidget() override; 0052 0053 void read(AbstractDataSource*, AbstractFileFilter::ImportMode importMode = AbstractFileFilter::ImportMode::Replace); 0054 QString selectedTable() const; 0055 bool isValid() const; 0056 bool isNumericData() const; 0057 0058 private: 0059 Ui::ImportSQLDatabaseWidget ui; 0060 QList<QString> m_vendorList; 0061 QList<QString> m_tableNamesList; 0062 QStringList m_columnNames; 0063 QVector<AbstractColumn::ColumnMode> m_columnModes; 0064 int m_cols{0}; 0065 int m_rows{0}; 0066 QSqlDatabase m_db; 0067 QStandardItemModel* m_databaseTreeModel{nullptr}; 0068 QString m_configPath; 0069 bool m_initializing{false}; 0070 bool m_valid{false}; 0071 bool m_numeric{false}; 0072 #ifdef HAVE_KF5_SYNTAX_HIGHLIGHTING 0073 KSyntaxHighlighting::SyntaxHighlighter* m_highlighter; 0074 KSyntaxHighlighting::Repository m_repository; 0075 #endif 0076 0077 void readConnections(); 0078 QString currentQuery(bool preview = false); 0079 void setInvalid(); 0080 void setValid(); 0081 0082 private slots: 0083 void loadSettings(); 0084 void showDatabaseManager(); 0085 void connectionChanged(); 0086 void importFromChanged(int); 0087 void refreshPreview(); 0088 0089 signals: 0090 void completed(int); 0091 void stateChanged(); 0092 }; 0093 0094 #endif // IMPORTSQLDATABASEWIDGET_H