[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [labplot/sql] src/kdefrontend: Populate the combobox with the available SQL drivers.
From:       Alexander Semke <alexander.semke () web ! de>
Date:       2016-12-04 21:20:16
Message-ID: E1cDeCm-00071c-IO () code ! kde ! org
[Download RAW message or body]

Git commit 9fe7ccdc2034c8b8f90754817a4dcddd999eeccf by Alexander Semke.
Committed on 04/12/2016 at 21:19.
Pushed by asemke into branch 'sql'.

Populate the combobox with the available SQL drivers.

M  +42   -2    src/kdefrontend/datasources/DatabaseManagerWidget.cpp
M  +2    -0    src/kdefrontend/datasources/DatabaseManagerWidget.h
M  +0    -24   src/kdefrontend/datasources/ImportSQLDatabaseWidget.cpp
M  +24   -10   src/kdefrontend/ui/datasources/databasemanagerwidget.ui

https://commits.kde.org/labplot/9fe7ccdc2034c8b8f90754817a4dcddd999eeccf

diff --git a/src/kdefrontend/datasources/DatabaseManagerWidget.cpp \
b/src/kdefrontend/datasources/DatabaseManagerWidget.cpp index 41b09629..d2b7ed0e \
                100644
--- a/src/kdefrontend/datasources/DatabaseManagerWidget.cpp
+++ b/src/kdefrontend/datasources/DatabaseManagerWidget.cpp
@@ -28,7 +28,9 @@ Copyright            : (C) 2016 Alexander Semke \
(alexander.semke@web.de)  
 #include "DatabaseManagerWidget.h"
 
+#include <QFileDialog>
 #include <QTimer>
+#include <QSqlDatabase>
 
 /*!
    \class DatabaseManagerWidget
@@ -42,10 +44,20 @@ DatabaseManagerWidget::DatabaseManagerWidget(QWidget* parent) : \
QWidget(parent)  
 	ui.tbAdd->setIcon(KIcon("list-add"));
 	ui.tbDelete->setIcon(KIcon("list-remove"));
+	ui.bOpen->setIcon(KIcon("document-open"));
 
 	ui.tbAdd->setToolTip(i18n("Add new database connection"));
 	ui.tbDelete->setToolTip(i18n("Delete selected database connection"));
-	ui.pbTestConnection->setToolTip(i18n("Test selected database connection"));
+	ui.bOpen->setToolTip(i18n("Open database file"));
+	ui.bTestConnection->setToolTip(i18n("Test selected database connection"));
+
+	//add the list of supported SQL drivers
+	foreach (const QString& driver, QSqlDatabase::drivers())
+		ui.cbDriver->addItem(driver);
+
+	//SIGNALs/SLOTs
+	connect( ui.bOpen, SIGNAL(clicked()), this, SLOT (selectFile()) );
+	connect(ui.cbDriver, SIGNAL(currentIndexChanged(int)), SLOT(driverChanged()) );
 
 	QTimer::singleShot( 100, this, SLOT(loadSettings()) );
 }
@@ -59,7 +71,35 @@ void DatabaseManagerWidget::loadSettings() {
 }
 
 DatabaseManagerWidget::~DatabaseManagerWidget() {
-	// save current settings
+	// save available database connections
 	KConfigGroup conf(KSharedConfig::openConfig(), "DatabaseManager");
 	//TODO
 }
+
+void DatabaseManagerWidget::driverChanged() {
+	//determine whether it's a file database (like SQLite) and hide non-relevant fields \
(like host name, etc.) +	bool fileDB = ui.cbDriver->currentText() == \
QLatin1String("QSQLITE"); +	ui.lHost->setVisible(!fileDB);
+	ui.leHost->setVisible(!fileDB);
+	ui.lPort->setVisible(!fileDB);
+	ui.sbPort->setVisible(!fileDB);
+	ui.bOpen->setVisible(fileDB);
+	ui.gbAuthentication->setVisible(!fileDB);
+}
+
+void DatabaseManagerWidget::selectFile() {
+	KConfigGroup conf(KSharedConfig::openConfig(), "DatabaseManagerWidget");
+	QString dir = conf.readEntry("LastDir", "");
+	QString path = QFileDialog::getOpenFileName(this, i18n("Select the database file"), \
dir); +	if (path.isEmpty())
+		return; //cancel was clicked in the file-dialog
+
+	int pos = path.lastIndexOf(QDir::separator());
+	if (pos != -1) {
+		QString newDir = path.left(pos);
+		if (newDir != dir)
+			conf.writeEntry("LastDir", newDir);
+	}
+
+	ui.kleDatabase->setText(path);
+}
diff --git a/src/kdefrontend/datasources/DatabaseManagerWidget.h \
b/src/kdefrontend/datasources/DatabaseManagerWidget.h index 4ceb918f..4fc5700b 100644
--- a/src/kdefrontend/datasources/DatabaseManagerWidget.h
+++ b/src/kdefrontend/datasources/DatabaseManagerWidget.h
@@ -42,6 +42,8 @@ private:
 
 private slots:
 	void loadSettings();
+	void driverChanged();
+	void selectFile();
 };
 
 #endif
diff --git a/src/kdefrontend/datasources/ImportSQLDatabaseWidget.cpp \
b/src/kdefrontend/datasources/ImportSQLDatabaseWidget.cpp index 1af4b5bd..9fbf7926 \
                100644
--- a/src/kdefrontend/datasources/ImportSQLDatabaseWidget.cpp
+++ b/src/kdefrontend/datasources/ImportSQLDatabaseWidget.cpp
@@ -27,12 +27,10 @@
 
 #include "ImportSQLDatabaseWidget.h"
 #include "DatabaseManagerDialog.h"
-#include "kdefrontend/MainWin.h"
 #include "commonfrontend/widgets/TreeViewComboBox.h"
 #include "backend/core/Project.h"
 #include "backend/core/AspectTreeModel.h"
 #include "backend/spreadsheet/Spreadsheet.h"
-#include "kdefrontend/MainWin.h"
 
 #include <QTableWidget>
 #include <QStandardItem>
@@ -45,28 +43,6 @@ ImportSQLDatabaseWidget::ImportSQLDatabaseWidget(QWidget* \
parent):QWidget(parent  \
ui.bDatabaseManager->setIcon(KIcon("network-server-database"));  connect( \
ui.bDatabaseManager, SIGNAL(clicked()), this, SLOT(showDatabaseManager()) );  
-// 	vendorList.append("QDB2");
-// 	ui.cbVendor->addItem(i18n("DB2"));
-// 	vendorList.append("QIBASE");
-// 	ui.cbVendor->addItem(i18n("IBASE"));
-// 	vendorList.append("QMYSQL");
-// 	ui.cbVendor->addItem(i18n("MYSQL"));
-// 	vendorList.append("QOCI");
-// 	ui.cbVendor->addItem(i18n("OCI"));
-// 	vendorList.append("QODBC");
-// 	ui.cbVendor->addItem(i18n("ODBC"));
-// 	vendorList.append("QPSQL");
-// 	ui.cbVendor->addItem(i18n("PSQL"));
-// 	vendorList.append("QSQLITE");
-// 	ui.cbVendor->addItem(i18n("SQLITE"));
-// 	vendorList.append("QSQLITE2");
-// 	ui.cbVendor->addItem(i18n("SQLITE2"));
-// 	vendorList.append("QTDS");
-// 	ui.cbVendor->addItem(i18n("TDS"));
-// 
-// 	connect( ui.pbConnect, SIGNAL(clicked()), this, SLOT(connectDatabase()) );
-// 	connect( ui.pbRefreshPreview, SIGNAL(clicked()), this, SLOT(showPreview()) );
-// 	connect( ui.cbShowPreview, SIGNAL(clicked()), this, SLOT(togglePreviewWidget()) \
);  // 	loadSettings();
 }
 
diff --git a/src/kdefrontend/ui/datasources/databasemanagerwidget.ui \
b/src/kdefrontend/ui/datasources/databasemanagerwidget.ui index 29eea9be..98d5487e \
                100644
--- a/src/kdefrontend/ui/datasources/databasemanagerwidget.ui
+++ b/src/kdefrontend/ui/datasources/databasemanagerwidget.ui
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>446</width>
-    <height>374</height>
+    <width>501</width>
+    <height>376</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -37,24 +37,24 @@
      </property>
      <layout class="QGridLayout" name="gridLayout">
       <item row="0" column="0">
-       <widget class="QLabel" name="lVendor">
+       <widget class="QLabel" name="lDriver">
         <property name="text">
-         <string>Vendor</string>
+         <string>Driver</string>
         </property>
        </widget>
       </item>
       <item row="0" column="1">
-       <widget class="QComboBox" name="cbVendor"/>
+       <widget class="QComboBox" name="cbDriver"/>
       </item>
       <item row="1" column="0">
-       <widget class="QLabel" name="lHostName">
+       <widget class="QLabel" name="lHost">
         <property name="text">
          <string>Host</string>
         </property>
        </widget>
       </item>
       <item row="1" column="1">
-       <widget class="QLineEdit" name="leHostName"/>
+       <widget class="QLineEdit" name="leHost"/>
       </item>
       <item row="2" column="0">
        <widget class="QLabel" name="lPort">
@@ -84,13 +84,20 @@
        </widget>
       </item>
       <item row="3" column="1">
-       <widget class="QLineEdit" name="leDatabaseName"/>
+       <widget class="KLineEdit" name="kleDatabase"/>
+      </item>
+      <item row="3" column="2">
+       <widget class="QPushButton" name="bOpen">
+        <property name="text">
+         <string/>
+        </property>
+       </widget>
       </item>
      </layout>
     </widget>
    </item>
    <item row="1" column="1">
-    <widget class="QGroupBox" name="groupBox_2">
+    <widget class="QGroupBox" name="gbAuthentication">
      <property name="sizePolicy">
       <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
        <horstretch>0</horstretch>
@@ -171,7 +178,7 @@
        </spacer>
       </item>
       <item>
-       <widget class="QPushButton" name="pbTestConnection">
+       <widget class="QPushButton" name="bTestConnection">
         <property name="text">
          <string>Test</string>
         </property>
@@ -182,6 +189,13 @@
    </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>KLineEdit</class>
+   <extends>QLineEdit</extends>
+   <header>klineedit.h</header>
+  </customwidget>
+ </customwidgets>
  <resources/>
  <connections/>
 </ui>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic