1 /*************************************************************************** 2 qgsmssqlnewconnection.h - description 3 ------------------- 4 begin : 2011-10-08 5 copyright : (C) 2011 by Tamas Szekeres 6 email : szekerest at gmail.com 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 #ifndef QGSMSSQLNEWCONNECTION_H 18 #define QGSMSSQLNEWCONNECTION_H 19 #include "ui_qgsmssqlnewconnectionbase.h" 20 #include "qgsguiutils.h" 21 #include "qgshelp.h" 22 #include <QAbstractListModel> 23 24 #include <QSqlDatabase> 25 26 class QgsMssqlDatabase; 27 28 /** 29 * \class QgsMssqlNewConnection 30 * \brief Dialog to allow the user to configure and save connection 31 * information for an MSSQL database 32 */ 33 class QgsMssqlNewConnection : public QDialog, private Ui::QgsMssqlNewConnectionBase 34 { 35 Q_OBJECT 36 public: 37 //! Constructor 38 QgsMssqlNewConnection( QWidget *parent = nullptr, const QString &connName = QString(), Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags ); 39 40 //! Tests the connection using the parameters supplied 41 bool testConnection( const QString &testDatabase = QString() ); 42 43 /** 44 * \brief List all databases found for the given server. 45 */ 46 void listDatabases(); 47 public slots: 48 void accept() override; 49 void btnListDatabase_clicked(); 50 void btnConnect_clicked(); 51 void cb_trustedConnection_clicked(); 52 53 private slots: 54 //! Updates state of the OK button depending of the filled fields 55 void updateOkButtonState(); 56 void onCurrentDataBaseChange(); 57 58 void onExtentFromGeometryToggled( bool checked ); 59 void onPrimaryKeyFromGeometryToggled( bool checked ); 60 61 private: 62 //! Class that reprents a model to display available schemas on a database and choose which will be displayed in QGIS 63 class SchemaModel: public QAbstractListModel 64 { 65 public: 66 SchemaModel( QObject *parent = nullptr ); 67 68 int rowCount( const QModelIndex &parent ) const override; 69 QVariant data( const QModelIndex &index, int role ) const override; 70 bool setData( const QModelIndex &index, const QVariant &value, int role ) override; 71 Qt::ItemFlags flags( const QModelIndex &index ) const override; 72 73 //! Returns the unchecked schemas 74 QStringList uncheckedSchemas() const; 75 76 //! Returns the database name represented by the model 77 QString dataBaseName() const; 78 79 //! Sets the database nale represented by the model 80 void setDataBaseName( const QString &dataBaseName ); 81 82 //! Sets the settings for \a database 83 void setSettings( const QString &database, const QStringList &schemas, const QStringList &excludedSchemas ); 84 85 //! Checks all schemas 86 void checkAll(); 87 88 //! Unchecks all schemas 89 void unCheckAll(); 90 91 private: 92 QString mDataBaseName; 93 QStringList mSchemas; 94 QStringList mExcludedSchemas; 95 96 }; 97 98 QString mOriginalConnName; //store initial name to delete entry in case of rename 99 void showHelp(); 100 101 QVariantMap mSchemaSettings; //store the schema settings edited during this QDialog life time 102 SchemaModel mSchemaModel; 103 104 std::shared_ptr<QgsMssqlDatabase> getDatabase( const QString &name = QString() ) const; 105 106 bool testExtentInGeometryColumns() const; 107 108 bool testPrimaryKeyInGeometryColumns() const; 109 }; 110 111 #endif // QGSMSSQLNEWCONNECTION_H 112