From 8940e1e34611f2d5c36f7b6aca10f397736bca3c Mon Sep 17 00:00:00 2001 From: Karsten Rink <karsten.rink@ufz.de> Date: Mon, 20 Aug 2012 18:19:16 +0200 Subject: [PATCH] removed all database-related files --- Gui/DataView/CMakeLists.txt | 8 - Gui/DataView/DBConnection.ui | 228 ----- Gui/DataView/DBConnectionDialog.cpp | 51 -- Gui/DataView/DBConnectionDialog.h | 32 - Gui/DataView/DatabaseConnection.cpp | 847 ------------------ Gui/DataView/DatabaseConnection.h | 80 -- Gui/DataView/DatabaseResultView.ui | 55 -- .../DiagramView/DiagramPrefsDialog.cpp | 32 - Gui/DataView/QueryResultsDialog.cpp | 60 -- Gui/DataView/QueryResultsDialog.h | 42 - Gui/mainwindow.cpp | 50 +- Gui/mainwindow.h | 4 - Gui/mainwindow.ui | 36 - 13 files changed, 3 insertions(+), 1522 deletions(-) delete mode 100644 Gui/DataView/DBConnection.ui delete mode 100644 Gui/DataView/DBConnectionDialog.cpp delete mode 100644 Gui/DataView/DBConnectionDialog.h delete mode 100644 Gui/DataView/DatabaseConnection.cpp delete mode 100644 Gui/DataView/DatabaseConnection.h delete mode 100644 Gui/DataView/DatabaseResultView.ui delete mode 100644 Gui/DataView/QueryResultsDialog.cpp delete mode 100644 Gui/DataView/QueryResultsDialog.h diff --git a/Gui/DataView/CMakeLists.txt b/Gui/DataView/CMakeLists.txt index 0c272640b85..7af04a306b3 100644 --- a/Gui/DataView/CMakeLists.txt +++ b/Gui/DataView/CMakeLists.txt @@ -4,9 +4,7 @@ set( SOURCES ColorTableView.cpp CondFromRasterDialog.cpp ConditionWriterDialog.cpp - DatabaseConnection.cpp DataView.cpp - DBConnectionDialog.cpp DirectConditionGenerator.cpp ElementTreeModel.cpp FEMConditionSetupDialog.cpp @@ -30,7 +28,6 @@ set( SOURCES NewProcessDialog.cpp ProcessModel.cpp ProcessView.cpp - QueryResultsDialog.cpp SelectMeshDialog.cpp SetNameDialog.cpp StationTabWidget.cpp @@ -44,9 +41,7 @@ set( MOC_HEADERS ColorTableView.h CondFromRasterDialog.h ConditionWriterDialog.h - DatabaseConnection.h DataView.h - DBConnectionDialog.h ElementTreeModel.h FEMConditionSetupDialog.h GEOModels.h @@ -66,7 +61,6 @@ set( MOC_HEADERS NewProcessDialog.h ProcessModel.h ProcessView.h - QueryResultsDialog.h SelectMeshDialog.h SetNameDialog.h StationTabWidget.h @@ -92,8 +86,6 @@ set( HEADERS set( UIS CondFromRaster.ui ConditionWriter.ui - DatabaseResultView.ui - DBConnection.ui FEMConditionSetup.ui GeoTabWidgetBase.ui GMSHPrefs.ui diff --git a/Gui/DataView/DBConnection.ui b/Gui/DataView/DBConnection.ui deleted file mode 100644 index f097882e6d0..00000000000 --- a/Gui/DataView/DBConnection.ui +++ /dev/null @@ -1,228 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>DBConnectionDialog</class> - <widget class="QDialog" name="DBConnectionDialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>388</width> - <height>215</height> - </rect> - </property> - <property name="windowTitle"> - <string>Database Connection Settings</string> - </property> - <widget class="QDialogButtonBox" name="dbButtonBox"> - <property name="geometry"> - <rect> - <x>30</x> - <y>170</y> - <width>341</width> - <height>32</height> - </rect> - </property> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set> - </property> - </widget> - <widget class="QComboBox" name="driverBox"> - <property name="geometry"> - <rect> - <x>170</x> - <y>20</y> - <width>201</width> - <height>22</height> - </rect> - </property> - <item> - <property name="text"> - <string>QDB2 (IBM DB2)</string> - </property> - </item> - <item> - <property name="text"> - <string>QIBASE (Borland Interbase)</string> - </property> - </item> - <item> - <property name="text"> - <string>QMYSQL (MySQL)</string> - </property> - </item> - <item> - <property name="text"> - <string>QOCI (Oracle Call Interface)</string> - </property> - </item> - <item> - <property name="text"> - <string>QODBC (ODBC / MS SQL Server)</string> - </property> - </item> - <item> - <property name="text"> - <string>QPSQL (PostgreSQL)</string> - </property> - </item> - <item> - <property name="text"> - <string>QSQLITE (SQLite v.3 or above)</string> - </property> - </item> - <item> - <property name="text"> - <string>QSQLITE2 (SQLite v.2)</string> - </property> - </item> - <item> - <property name="text"> - <string>QTDS (Sybase Adaptive Server)</string> - </property> - </item> - </widget> - <widget class="QLabel" name="driverLine"> - <property name="geometry"> - <rect> - <x>20</x> - <y>20</y> - <width>131</width> - <height>16</height> - </rect> - </property> - <property name="text"> - <string>Database Driver:</string> - </property> - </widget> - <widget class="QLabel" name="hostnameLabel"> - <property name="geometry"> - <rect> - <x>20</x> - <y>50</y> - <width>131</width> - <height>16</height> - </rect> - </property> - <property name="text"> - <string>Hostname:</string> - </property> - </widget> - <widget class="QLabel" name="dbnameLabel"> - <property name="geometry"> - <rect> - <x>20</x> - <y>80</y> - <width>131</width> - <height>16</height> - </rect> - </property> - <property name="text"> - <string>Database Name:</string> - </property> - </widget> - <widget class="QLabel" name="usernameLabel"> - <property name="geometry"> - <rect> - <x>20</x> - <y>110</y> - <width>131</width> - <height>16</height> - </rect> - </property> - <property name="text"> - <string>Username:</string> - </property> - </widget> - <widget class="QLabel" name="passwordLabel"> - <property name="geometry"> - <rect> - <x>20</x> - <y>140</y> - <width>131</width> - <height>16</height> - </rect> - </property> - <property name="text"> - <string>Password (optional):</string> - </property> - </widget> - <widget class="QLineEdit" name="hostnameLine"> - <property name="geometry"> - <rect> - <x>170</x> - <y>50</y> - <width>201</width> - <height>20</height> - </rect> - </property> - </widget> - <widget class="QLineEdit" name="dbnameLine"> - <property name="geometry"> - <rect> - <x>170</x> - <y>80</y> - <width>201</width> - <height>20</height> - </rect> - </property> - </widget> - <widget class="QLineEdit" name="usernameLine"> - <property name="geometry"> - <rect> - <x>170</x> - <y>110</y> - <width>201</width> - <height>20</height> - </rect> - </property> - </widget> - <widget class="QLineEdit" name="passwordLine"> - <property name="geometry"> - <rect> - <x>170</x> - <y>140</y> - <width>201</width> - <height>20</height> - </rect> - </property> - </widget> - </widget> - <resources/> - <connections> - <connection> - <sender>dbButtonBox</sender> - <signal>accepted()</signal> - <receiver>DBConnectionDialog</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>248</x> - <y>254</y> - </hint> - <hint type="destinationlabel"> - <x>157</x> - <y>274</y> - </hint> - </hints> - </connection> - <connection> - <sender>dbButtonBox</sender> - <signal>rejected()</signal> - <receiver>DBConnectionDialog</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>316</x> - <y>260</y> - </hint> - <hint type="destinationlabel"> - <x>286</x> - <y>274</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/Gui/DataView/DBConnectionDialog.cpp b/Gui/DataView/DBConnectionDialog.cpp deleted file mode 100644 index b3b6349ef53..00000000000 --- a/Gui/DataView/DBConnectionDialog.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/** - * \file DBConnectionDialog.cpp - * KR Initial implementation - */ - -#include "DBConnectionDialog.h" -#include <QSettings> - -/// Constructor -DBConnectionDialog::DBConnectionDialog(QDialog* parent) : QDialog(parent) -{ - setupUi(this); - - int idx = 0; - QSettings settings("UFZ", "OpenGeoSys-5"); - - if (!settings.value("DBProtocol", "").toString().isEmpty()) - for (int i = 0; i < driverBox->count(); i++) - if (driverBox->itemText(i).startsWith(settings.value("DBProtocol", - "").toString())) - idx = i; - - driverBox->setCurrentIndex(idx); - hostnameLine->setText(settings.value("DBHost", "").toString()); - dbnameLine->setText(settings.value("DBName", "").toString()); - usernameLine->setText(settings.value("DBUser", "").toString()); - passwordLine->setText(settings.value("DBPass", "").toString()); -} - -DBConnectionDialog::~DBConnectionDialog() -{ -} - -/// Instructions if the OK-Button has been pressed. -void DBConnectionDialog::accept() -{ - QString protocol = (driverBox->currentText()).left((driverBox->currentText()).indexOf(" ")); - QString hostname = hostnameLine->text(); - QString dbname = dbnameLine->text(); - QString user = usernameLine->text(); - QString pass = passwordLine->text(); - - emit connectionRequested(protocol, hostname, dbname, user, pass); - this->done(QDialog::Accepted); -} - -/// Instructions if the Cancel-Button has been pressed. -void DBConnectionDialog::reject() -{ - this->done(QDialog::Rejected); -} diff --git a/Gui/DataView/DBConnectionDialog.h b/Gui/DataView/DBConnectionDialog.h deleted file mode 100644 index 65bf87d4543..00000000000 --- a/Gui/DataView/DBConnectionDialog.h +++ /dev/null @@ -1,32 +0,0 @@ -/** - * \file DBConnectionDialog.h - * KR Initial implementation - */ - -#ifndef DBCONNECTIONDIALOG_H -#define DBCONNECTIONDIALOG_H - -#include "ui_DBConnection.h" -#include <QSqlQueryModel> -#include <QDialog> - -/** - * \brief A dialog window for settung up a database connection - */ -class DBConnectionDialog : public QDialog, private Ui_DBConnectionDialog -{ - Q_OBJECT - -public: - DBConnectionDialog(QDialog* parent = 0); - ~DBConnectionDialog(void); - -private slots: - void accept(); - void reject(); - -signals: - void connectionRequested(QString, QString, QString, QString, QString); -}; - -#endif //DBCONNECTIONDIALOG_H diff --git a/Gui/DataView/DatabaseConnection.cpp b/Gui/DataView/DatabaseConnection.cpp deleted file mode 100644 index 7075584aa41..00000000000 --- a/Gui/DataView/DatabaseConnection.cpp +++ /dev/null @@ -1,847 +0,0 @@ -/** - * \file DatabaseConnection.cpp - * KR Initial implementation - */ - -#include "DatabaseConnection.h" -#include "DateTools.h" -#include "OGSError.h" -#include "QueryResultsDialog.h" -#include "StringTools.h" -#include <QSettings> -#include <QSqlError> -#include <QSqlQuery> -#include <QSqlQueryModel> -#include <QVariant> - -#include <fstream> -#include <iostream> - -/// The OGS5-Connection to a database -DatabaseConnection::DatabaseConnection(GeoLib::GEOObjects* geoObjects, - QObject* parent) : QObject(parent), _geoObjects(geoObjects) -{ -} - -/// Deconstructor for the connection object -DatabaseConnection::~DatabaseConnection() -{ - _db.removeDatabase("QOCI"); -} - -/** - * Initialising and testing the default database-connection. - * \return 1 if the connection has been established, 0 (and an error message) otherwise. - */ -int DatabaseConnection::dbConnect() -{ - QSettings settings("UFZ", "OpenGeoSys-5"); - QString protocol = settings.value("DBProtocol", "").toString(); - QString hostname = settings.value("DBHost", "").toString(); - QString dbname = settings.value("DBName", "").toString(); - QString user = settings.value("DBUser", "").toString(); - QString pass = settings.value("DBPass", "").toString(); - - //default connection - if (protocol.isEmpty() || hostname.isEmpty() || dbname.isEmpty() || user.isEmpty() || - pass.isEmpty()) - { - protocol = "QOCI"; - hostname = "cora1-vip.leipzig.ufz.de"; - dbname = "ORACLE1"; - user = "GEOSYS"; - pass = "project09"; - } - - return dbConnect(protocol, hostname, dbname, user, pass); -} - -/** - * Initialising and testing a specific database-connection. - * \param protocol The database connection driver - * \param hostname The connection's host name - * \param dbname The connection's database name - * \param user The user name for connecting to the database - * \param pass The password for the specified user name - * \return 1 if the connection has been established, 0 (and an error message) otherwise. - */ -int DatabaseConnection::dbConnect(QString protocol, - QString hostname, - QString dbname, - QString user, - QString pass) -{ - QSqlDatabase::removeDatabase(_db.connectionName()); - - _db = QSqlDatabase::addDatabase(protocol); - _db.setHostName(hostname); - _db.setDatabaseName(dbname); - _db.setUserName(user); - _db.setPassword(pass); - - return test(false); -} - -/** - * Setting up a new database-connection as default connection. - * \param protocol The database connection driver - * \param hostname The connection's host name - * \param dbname The connection's database name - * \param user The user name for connecting to the database - * \param pass The password for the specified user name - * \return 1 if the connection has been established, 0 (and an error message) otherwise. - */ -int DatabaseConnection::setConnection(QString protocol, - QString hostname, - QString dbname, - QString user, - QString pass) -{ - QSettings settings("UFZ", "OpenGeoSys-5"); - - settings.setValue("DBProtocol", protocol); - settings.setValue("DBHost", hostname); - settings.setValue("DBName", dbname); - settings.setValue("DBUser", user); - settings.setValue("DBPass", pass); - - dbConnect(protocol, hostname, dbname, user, pass); - disconnect(this, SLOT(setConnection(QString, QString, QString, QString, QString))); - return test(true); -} - -/** - * Tests the current database connection. - * \return 1 if the connection has been established, 0 (and an error message) otherwise. - */ -int DatabaseConnection::test(bool showBox) -{ - if (_db.open()) - { - if (showBox) - OGSError::box("Database connection established."); - else - std::cout << "Database connection established...\n"; - _db.close(); - return 1; - } - else - { - std::cout << "Database connection failed...\n"; - databaseError(); - OGSError::box("Could not connect to database."); - return 0; - } -} - -/// Outputting an error related to the database connection -void DatabaseConnection::databaseError() -{ - QSqlError error = _db.lastError(); - if (error.isValid()) - { - std::cout << (error.databaseText()).toStdString(); - std::cout << (error.driverText()).toStdString() << "\n\n"; - } -} - -/// Opening a dialog containing all the available station lists -void DatabaseConnection::getListSelection() -{ - if (_db.open()) - { - QSqlQueryModel* qModel = new QSqlQueryModel(); - qModel->setQuery( - "select l.listid, c.catname, l.listname from lists l, categories c where c.catid=l.catid order by c.catname"); - - QueryResultsDialog* dbView = new QueryResultsDialog(); - connect(dbView, SIGNAL(listSelected(int)), this, SLOT(loadStationList(int))); - - dbView->setView(qModel); - dbView->exec(); - - _db.close(); - } - else - databaseError(); -} - -/// Tests if the current database connection is valid. -bool DatabaseConnection::isConnected() -{ - return _db.isValid(); -} - -/** - * Loads a list of stations. - * \param listID The ID of the list that is requested - * \return 1 if there were no errors, 0 and an error message otherwise. - */ -int DatabaseConnection::loadStationList(int listID) -{ - if (_db.open()) - { - QSqlQuery query, stnQuery; - QString stationName; - std::vector<GeoLib::Point*>* stations = new std::vector<GeoLib::Point*>; - - query.exec( - "select stationtype from geosysstationtypes where listid=" + - QString::number(listID)); - - if (query.next()) - { - GeoLib::Station::StationType type = - static_cast<GeoLib::Station::StationType>(query.value(0).toInt()); - if (type == GeoLib::Station::BOREHOLE) - query.exec( - "select c.catname, l.listname from lists l, categories c, boreholes b where c.catid=l.catid and l.listid=b.listid and l.listid=" - + QString::number(listID)); - else - query.exec( - "select c.catname, l.listname from lists l, categories c where c.catid=l.catid and l.listid=" - + QString::number(listID)); - - if (query.next()) - { - QString listName = (query.value(0)).toString() + " (" + - (query.value(1)).toString() + ")"; - - if (type == GeoLib::Station::BOREHOLE) - stnQuery.exec( - "select s.stationid, s.name, s.x, s.y, s.z, b.bdepth, to_char(b.bdate, 'YYYY-MM-DD') from stations s, boreholes b where s.listid=b.listid and s.stationid=b.stationid and s.listid=" - + QString::number(listID) + " order by stationid"); - else - stnQuery.exec( - "select stationid, name, x, y, z from stations where listid=" - + QString::number(listID) + " order by stationid"); - - while (stnQuery.next()) - { - stationName = stnQuery.value(1).toString(); - if (stationName.isEmpty()) - stationName = "Station" + - stnQuery.value(0).toString(); - - GeoLib::Station* newStation; - if (type == GeoLib::Station::BOREHOLE) - newStation = GeoLib::StationBorehole::createStation( - stationName.toStdString(), - stnQuery.value(2).toDouble(), - stnQuery.value(3).toDouble(), - stnQuery.value(4).toDouble(), - stnQuery.value(5).toDouble(), - stnQuery.value(6).toString().toStdString()); - else - newStation = GeoLib::Station::createStation( - stationName.toStdString(), - stnQuery.value(2).toDouble(), - stnQuery.value(3).toDouble(), - stnQuery.value(4).toDouble()); - - stations->push_back(newStation); - } - - if (type == GeoLib::Station::BOREHOLE) - //addStratigraphy(listID, _geoObjects->getStationVec(listName.toStdString())); - addStratigraphy(listID, stations); - - std::string temp_name (listName.toStdString()); - if (!stations->empty()) - _geoObjects->addStationVec(stations, temp_name); - - _db.close(); - //emit listLoaded(listName); - - return 1; - } - } - else - { - std::cout << - "DatabaseConnection::loadList() - No database entry found for the selected key." - << std::endl; - _db.close(); - } - } - else - databaseError(); - - return 0; -} - -/** - * Loads additional stratigraphy-data if the loaded station list consists of boreholes - * \param listID The ID of the list that is requested - * \param stations List of station objects for which stratigraphy data will be provided - * \return 1 if there were no errors, 0 and an error message otherwise. - */ -int DatabaseConnection::addStratigraphy(int listID, std::vector<GeoLib::Point*>* stations) -{ - if (_db.open()) - { - QSqlQuery strat; - - size_t size = stations->size(); - for (size_t i = 0; i < size; i++) - { - int count = 1; - GeoLib::StationBorehole* newStation = - static_cast<GeoLib::StationBorehole*>((*stations)[i]); - strat.exec( - "select s.layerid, s.thickness, s.strat from stations t, stratigraphies s where s.listid=" - + QString::number( - listID) + - " and s.listid=t.listid and s.stationid=t.stationid and t.name='" + - QString::fromStdString(static_cast<GeoLib::Station*>((*stations)[i]) - -> - getName()) + "' order by layerid"); - - while (strat.next()) - { - if (count == strat.value(0)) - newStation->addSoilLayer (strat.value(1).toDouble(), - (strat.value( - 2).toString()). - toStdString()); - //newStation->type = Station::BOREHOLE; - else - std::cout << - "DatabaseConnection::addStratigraphy - Station " << - static_cast<GeoLib::Station*>((*stations)[i])->getName() << - ": Stratigraphy incomplete...\n"; - count++; - } - (*stations)[i] = newStation; - } - } - else - { - std::cout << "Database error" << std::endl; - return 0; - } - - return 1; -} - -/** - * Returns the list ID for the station at a given postition - * \param list The name of the list - * \param x The x-coordinate of a station within the list - * \param y The y-coordinate of a station within the list - * \return The list ID if there were no errors, -1 and an error message otherwise. - */ -int DatabaseConnection::getListID(const QString &list, const double &x, const double &y) -{ - if (_db.open()) - { - QSqlQuery query; - query.exec( - "select l.listid from lists l, categories c, stations s where l.catid = c.catid and l.listid = s.listid and s.x=" - + QString::number(x,'f') + " and s.y=" + QString::number(y, - 'f') + - " and c.catname='" + list.left(list.indexOf(" (")) + "'"); - - if (query.next()) - return query.value(0).toInt(); - - return -1; - } - - return -1; -} - -/** - * Returns the station ID for the station at a given postition - * \param listID The ID of the list the station belongs to - * \param x The x-coordinate of the station - * \param y The y-coordinate of the station - * \return The station ID if there were no errors, -1 and an error message otherwise. - */ -int DatabaseConnection::getStationID(const int &listID, const double &x, const double &y) -{ - if (_db.open()) - { - QSqlQuery query; - query.exec("select stationid from stations where listid=" + QString::number( - listID) + " and x=" + QString::number(x, - 'f') + " and y=" + - QString::number(y,'f')); - - QString oldq = query.lastQuery(); - if (query.next()) - return query.value(0).toInt(); - - return -1; - } - - return -1; -} - -/** - * Returns all properties associated with a given list - * Note: This function is currently not implemented correctly. Please leave it alone or contact me if you want to use it. - * \param listID The ID of the queried list - * \param propNames A vector in which the properties will be stored - * \return 1 if there were no errors, 0 and an error message otherwise. - */ -int DatabaseConnection::getListProperties(const int &listID, std::vector<QString> &propNames) -{ - Q_UNUSED (listID); - - if (_db.open()) - { - QSqlQuery query; - query.exec( - "select column_name,data_type from all_tab_cols where table_name =\'STATIONS\'"); - while (query.next()) - if ((query.value(0).toString()).compare("LISTID") != 0 && - (query.value(0).toString()).compare("STATIONID") != 0 && - (query.value(1).toString()).compare("VARCHAR2") != 0) - propNames.push_back(query.value(0).toString()); - - return 1; - } - return 0; -} - -/** - * The minimum and maximum date for time series data associated with a given station - * \param listID The ID of the list the station belongs to - * \param stationID The ID of the station - * \param startDate The value of the first date for that station found in the database - * \param endDate The value of the last date for that station found in the database - * \return 1 if there were no errors, 0 and an error message otherwise. - */ -int DatabaseConnection::getDateBounds(const int &listID, - const int &stationID, - QString &startDate, - QString &endDate) -{ - startDate = ""; - endDate = ""; - if (_db.open()) - { - QSqlQuery query; - query.exec( - "select to_char(min(mdate), 'DD.MM.YYYY'), to_char(max(mdate), 'DD.MM.YYYY') from mvalues where listid=" - + QString::number(listID) + " and stationID=" + QString::number(stationID)); - if (query.next()) - { - startDate = query.value(0).toString(); - endDate = query.value(1).toString(); - } - _db.close(); - return 1; - } - return 0; -} - -/** - * The minimum and maximum value for a given property associated with a given list - * \param listID The ID of the list - * \param prop The name of the property - * \param min The smallest value of that property found in the database - * \param max The largest value of that property found in the database - * \return 1 if there were no errors, 0 and an error message otherwise. - */ -int DatabaseConnection::getPropertyBounds(const int &listID, - const QString &prop, - double &min, - double &max) -{ - if (_db.open()) - { - QSqlQuery query; - query.exec( - "select min(" + prop + "), max(" + prop + - ") from stations where listid=" + - QString::number(listID)); - if (query.next()) - { - min = query.value(0).toDouble(); - max = query.value(1).toDouble(); - } - _db.close(); - return 1; - } - return 0; -} - -/** - * Load time series data for a given station from the database - * \param listID The ID of the list the station belongs to - * \param stationID The ID of the station - * \param startDate The start date for the requested time series data - * \param endDate The end date for the requested time series data - * \param values The data - * \return 1 if there were no errors, 0 and an error message otherwise. - */ -int DatabaseConnection::loadValues(const int &listID, - const int &stationID, - const QDateTime &startDate, - const QDateTime &endDate, - std::vector< std::pair<QDateTime, float> > &values) -{ - if (startDate < endDate && _db.open()) - { - QSqlQuery query; - - query.prepare( - "select to_char(mdate,'YYYY-MM-DD'),mvalue from mvalues where listid=:listID and stationid=:stationID " - "and mdate>=to_date(:startDate,'DD.MM.YYYY') and mdate<=to_date(:endDate,'DD.MM.YYYY') order by mdate"); - query.bindValue(":listID", listID); - query.bindValue(":stationID", stationID); - query.bindValue(":startDate", startDate.toString("dd.MM.yyyy")); - query.bindValue(":endDate", endDate.toString("dd.MM.yyyy")); - query.exec(); - - while (query.next()) - values.push_back( std::pair<QDateTime, float>(query.value(0).toDateTime(), - static_cast<float>(query. - value(1). - toDouble())) ); - - _db.close(); - return 1; - } - - _db.close(); - return 0; -} - -/********************************************* -* Inserting data into the database. * -* Be very careful what you do with any of * -* functions below. * -* You might corrupt the database otherwise. * -* --KR * -*********************************************/ - -/** - * Inserts a new station list into the database - * \param path the path to the file containing the data - * \param listName the name of the list given a certain category - * \param catName the category of stations (i.e. boreholes) - * \param type the OGS5 Stationtype - */ -int DatabaseConnection::addListToDB(std::string path, - std::string listName, - std::string catName, - GeoLib::Station::StationType type) -{ - if (_db.open()) - { - int listID, catID(0); - bool status = true, commit = true; - - std::ifstream in( path.c_str() ); - - if (!in.is_open()) - { - std::cout << - "DatabaseConnection::addListToDB() - Could not open file..." << std::endl; - return 0; - } - - /* a name for the list in the first line of the file. this name is ignored here because - * the real list name is required as parameter to this method - */ - std::string line; - getline(in, line); - if ((line.substr(0,1)).compare("!") == 0) - line.substr( 1, line.length() - 1 ); - - QSqlQuery query; - query.exec("select max(listid) from lists"); - if (query.next()) - { - listID = query.value(0).toInt() + 1; - - query.exec( - "select catid from categories where catname='" + - QString::fromStdString(catName) + "'"); - - if (query.next()) - catID = query.value(0).toInt(); - else - { - query.exec("select max(catid) from categories"); - if (query.next()) - catID = query.value(0).toInt() + 1; - query.prepare("insert into categories values (" + - QString::number( - catID) + ", '" + QString::fromStdString( - catName) + "')"); - commitTransaction(query); - } - - _db.transaction(); - query.exec("insert into lists values(" + QString::number( - listID) + ", '" + QString::fromStdString( - listName) + "', " + - QString::number(catID) + ", 0)"); - if (type == GeoLib::Station::BOREHOLE) - query.exec( - "insert into geosysstationtypes values (" + QString::number( - listID) + ", 2)"); - - int stationID = 1; - - /* read all stations */ - while ( getline(in, line) ) - { - if (type == GeoLib::Station::BOREHOLE) - status = addBoreholeToDB(listID, stationID, line); - else - status = addStationToDB(listID, stationID, line); - - if (!status) - { - databaseError(); - commit = false; - } - stationID++; - } - - if (commit) - _db.commit(); - else - _db.rollback(); - - _db.close(); - in.close(); - - return commit; - } - else - std::cout << "Database error." << std::endl; - - _db.close(); - } - else - databaseError(); - - return 0; -} - -/** - * Inserts a new station into the database (this is to be called from addListToDB()) - * \param listID the ID of the list the station belongs to - * \param stationID the ID of the station - * \param line a line of text containing all the necessary information for the station (typically from a textfile) - */ -bool DatabaseConnection::addStationToDB(int listID, int stationID, std::string line) -{ - QSqlQuery query; - GeoLib::Station* station = GeoLib::Station::createStation(line); - query.prepare("insert into stations values(:listid, :stationid, :stationname, :x, :y, :z)"); - query.bindValue(":listid", listID); - query.bindValue(":stationid", stationID); - query.bindValue(":stationname", QString::fromStdString(station->getName())); - query.bindValue(":x", (*station)[0]); - query.bindValue(":y", (*station)[1]); - query.bindValue(":z", (*station)[2]); - return query.exec(); -} - -/** - * Inserts a new borehole into the database (this is to be called from addListToDB()) - * This is kind of an expansion of addStationToDB() which uses the same parameters - * \param listID the ID of the list the station belongs to - * \param stationID the ID of the station - * \param line a line of text containing all the necessary information for the station (typically from a textfile) - */ -bool DatabaseConnection::addBoreholeToDB(int listID, int stationID, std::string line) -{ - QSqlQuery query; - GeoLib::StationBorehole* station = GeoLib::StationBorehole::createStation(line); - - if (addStationToDB(listID, stationID, line)) - { - query.prepare( - "insert into boreholes values (:listid, :stationid, :bdepth, to_date(:bdate, 'DD.MM.YYYY'))"); - query.bindValue(":listid", listID); - query.bindValue(":stationid", stationID); - query.bindValue(":bdepth", station->getDepth()); - QString sDate = QString::fromStdString(BaseLib::date2string(station->getDate())); - query.bindValue(":bdate", sDate); - return query.exec(); - } - return false; -} - -/** - * Adds stratigraphic information for a given list of boreholes to the database - * This method assumes that the given list of boreholes exists - * \param path the path to the file containing the data - * \param listID the ID of the station list the stratigraphic data belongs to - */ -int DatabaseConnection::addStratigraphyToDB(std::string path, int listID) -{ - QSqlQuery query; - int stationID; - std::string line, stationName; - - if (_db.open()) - { - std::ifstream in( path.c_str() ); - - if (!in.is_open()) - { - std::cout << - "DatabaseConnection::addListToDB() - Could not open file..." << std::endl; - return 0; - } - - query.exec("select count(*) from lists where listid=" + QString::number(listID)); - if (query.next()) - { - if (query.value(0).toInt() == 1) - { - _db.transaction(); - - /* read all stations */ - while ( getline(in, line) ) - { - std::list<std::string> fields = splitString(line, '\t'); - - stationName = fields.front(); - fields.pop_front(); - query.exec( - "select stationid from stations where listid=" + - QString::number( - listID) + " and name='" + - QString::fromStdString( - stationName) + "'" ); - - if (query.next() && fields.size() >= 3) - { - stationID = query.value(0).toInt(); - - query.prepare( - "insert into stratigraphies values (:listid, :stationid, :layerid, :thickness, :strat, :petro)"); - query.bindValue(":listid", listID); - query.bindValue(":stationid", stationID); - query.bindValue(":layerid", - atoi(fields.front().c_str())); - fields.pop_front(); - query.bindValue(":thickness", - strtod(replaceString(",", ".", - fields.front()) - .c_str(),0)); - fields.pop_front(); - query.bindValue(":strat", - QString::fromStdString(fields.front())); - fields.pop_front(); - - if (!fields.empty()) - query.bindValue(":petro", - QString::fromStdString( - fields.front())); - else - query.bindValue(":petro", ""); - - query.exec(); - } - } - _db.commit(); - } - in.close(); - _db.close(); - - return 1; - } - else - std::cout << "Database error." << std::endl; - - _db.close(); - } - else - databaseError(); - - return 0; -} - -/** - * Adds time series information for a given station to the database - * This method assumes that the given list and station-id exists - * \param path the path to the file containing the data - * \param listID the ID of the list the stratigraphic data belongs to - * \param stationID the ID of the station the stratigraphic data belongs to - */ -int DatabaseConnection::addMeasuredValuesToDB(std::string path, int listID, int stationID) -{ - QSqlQuery query; - std::string line; - - if (_db.open()) - { - std::ifstream in( path.c_str() ); - - if (!in.is_open()) - { - std::cout << - "DatabaseConnection::addMeasuredValuesToDB() - Could not open file..." << - std::endl; - return 0; - } - - query.exec("select count(*) from stations where listid=" + QString::number( - listID) + " and stationid=" + QString::number(stationID)); - if (query.next()) - { - if (query.value(0).toInt() == 1) - { - _db.transaction(); - - while ( getline(in, line) ) - { - std::list<std::string> fields = splitString(line, '\t'); - - QString a = query.lastQuery(); - - query.prepare( - "insert into mvalues values (:listid, :stationid, to_date(:mdatetime,'DD.MM.YYYY'), :mvalue)"); - query.bindValue(":listid", listID); - query.bindValue(":stationid", stationID); - query.bindValue(":mdatetime", - QString::fromStdString(fields.front())); - fields.pop_front(); - query.bindValue(":mvalue", - strtod(replaceString(",", ".", - fields.front()).c_str(), - 0)); - fields.pop_front(); - query.exec(); - } - _db.commit(); - } - in.close(); - _db.close(); - - return 1; - } - else - std::cout << "Database error." << std::endl; - - _db.close(); - } - else - databaseError(); - - return 0; -} - -/** - * Executing a query as an encapsulated transaction - * \return True if everything is alright, false if there were errors. - */ -bool DatabaseConnection::commitTransaction(QSqlQuery query) -{ - _db.transaction(); - query.exec(); - bool r = _db.commit(); - return r; -} - diff --git a/Gui/DataView/DatabaseConnection.h b/Gui/DataView/DatabaseConnection.h deleted file mode 100644 index 4819bf7d9a4..00000000000 --- a/Gui/DataView/DatabaseConnection.h +++ /dev/null @@ -1,80 +0,0 @@ -/** - * \file DatabaseConnection.h - * KR Initial implementation - */ - -#ifndef DATABASECONNECTION_H -#define DATABASECONNECTION_H - -#include "GEOObjects.h" -#include "Station.h" -#include <QDateTime> -#include <QObject> -#include <QSqlDatabase> -#include <string> - -/** - * \brief Management of a database connection including the actual connection process, error handling and relevant queries. - */ -class DatabaseConnection : public QObject -{ - Q_OBJECT - -public: - DatabaseConnection(GeoLib::GEOObjects* geoObjects, QObject* parent = 0); - ~DatabaseConnection(); - - int dbConnect(); - - int getDateBounds(const int &listID, - const int &stationID, - QString &startDate, - QString &endDate); - int getListID(const QString &list, const double &x, const double &y); - int getListProperties(const int &listID, std::vector<QString> &propNames); - int getPropertyBounds(const int &listID, const QString &prop, double &min, double &max); - int getStationID(const int &listID, const double &x, const double &y); - void getListSelection(); - bool isConnected(); - int loadValues(const int &listID, - const int &stationID, - const QDateTime &startDate, - const QDateTime &endDate, - std::vector< std::pair<QDateTime, float> > &values); - int test(bool showBox); - -public slots: - int dbConnect(QString protocol, - QString hostname, - QString dbname, - QString user, - QString pass); - int loadStationList(int listID); - int setConnection(QString protocol, - QString hostname, - QString dbname, - QString user, - QString pass); - -private: - void databaseError(); - int addStratigraphy(int listID, std::vector<GeoLib::Point*>* stations); - bool commitTransaction(QSqlQuery query); - - //data-insert functions -- be careful! - int addListToDB(std::string path, - std::string listName, - std::string catName, - GeoLib::Station::StationType type); - bool addStationToDB(int listID, int stationID, std::string line); - bool addBoreholeToDB(int listID, int stationID, std::string line); - int addStratigraphyToDB(std::string path, int listID); - int addMeasuredValuesToDB(std::string path, int listID, int stationID); - - QSqlDatabase _db; - GeoLib::GEOObjects* _geoObjects; - -signals: - void listLoaded(QString listName); -}; -#endif //DATABASECONNECTION_H diff --git a/Gui/DataView/DatabaseResultView.ui b/Gui/DataView/DatabaseResultView.ui deleted file mode 100644 index 81c25edeef5..00000000000 --- a/Gui/DataView/DatabaseResultView.ui +++ /dev/null @@ -1,55 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>DatabaseResultsView</class> - <widget class="QDialog" name="DatabaseResultsView"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>400</width> - <height>290</height> - </rect> - </property> - <property name="windowTitle"> - <string>Existing Datasets</string> - </property> - <widget class="QTableView" name="queryView"> - <property name="geometry"> - <rect> - <x>10</x> - <y>10</y> - <width>381</width> - <height>231</height> - </rect> - </property> - </widget> - <widget class="QPushButton" name="openButton"> - <property name="geometry"> - <rect> - <x>70</x> - <y>250</y> - <width>121</width> - <height>31</height> - </rect> - </property> - <property name="text"> - <string>Open Dataset</string> - </property> - </widget> - <widget class="QPushButton" name="cancelButton"> - <property name="geometry"> - <rect> - <x>210</x> - <y>250</y> - <width>121</width> - <height>31</height> - </rect> - </property> - <property name="text"> - <string>Cancel</string> - </property> - </widget> - </widget> - <resources/> - <connections/> -</ui> diff --git a/Gui/DataView/DiagramView/DiagramPrefsDialog.cpp b/Gui/DataView/DiagramView/DiagramPrefsDialog.cpp index 552244a933c..64e36e0efe4 100644 --- a/Gui/DataView/DiagramView/DiagramPrefsDialog.cpp +++ b/Gui/DataView/DiagramView/DiagramPrefsDialog.cpp @@ -3,7 +3,6 @@ * KR Initial implementation */ -#include "DatabaseConnection.h" #include "DetailWindow.h" #include "DiagramList.h" #include "DiagramPrefsDialog.h" @@ -27,22 +26,6 @@ DiagramPrefsDialog::DiagramPrefsDialog(const GeoLib::Station* stn, setupUi(this); stationNameLabel->setText(QString::fromStdString(stn->getName())); stationTypeLabel->setText(listName); - - if (db) - { - _db = db; - _listID = _db->getListID(listName, (*stn)[0], (*stn)[1]); - _stationID = _db->getStationID(_listID, (*stn)[0], (*stn)[1]); - if (_listID > 0 && _stationID > 0) - { - QString startDate, endDate; - if (_db->getDateBounds(_listID, _stationID, startDate, endDate)) - { - fromDateLine->setText(startDate); - toDateLine->setText(endDate); - } - } - } } DiagramPrefsDialog::DiagramPrefsDialog(GeoLib::Station* stn, QDialog* parent) @@ -80,21 +63,6 @@ void DiagramPrefsDialog::accept() if ((fromDateLine->text().length() > 0) && (toDateLine->text().length() > 0) && (!_list.empty())) { - if (_list[0]->size() == 0) // data will be read from the database (if data has been loaded from file, size is already >0) - - if (_listID > 0 && _stationID > 0) - { - std::vector< std::pair<QDateTime, float> > values; - _db->loadValues(_listID, _stationID, - QDateTime::fromString( - fromDateLine->text(), - "dd.MM.yyyy"), - QDateTime::fromString(toDateLine->text(), - "dd.MM.yyyy"), values); - if (!loadList(values)) - OGSError::box("No data found."); - } - // data has been loaded if (_list[0]->size() > 0) { diff --git a/Gui/DataView/QueryResultsDialog.cpp b/Gui/DataView/QueryResultsDialog.cpp deleted file mode 100644 index 585579a0354..00000000000 --- a/Gui/DataView/QueryResultsDialog.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/** - * \file QueryResultsDialog.cpp - * KR Initial implementation - */ - -#include "OGSError.h" -#include "QueryResultsDialog.h" - -/** - * Constructor. - */ -QueryResultsDialog::QueryResultsDialog(QDialog* parent) : QDialog(parent) -{ - setupUi(this); -} - -QueryResultsDialog::~QueryResultsDialog() -{ -} - -void QueryResultsDialog::setView(QSqlQueryModel* model) -{ - queryView->setModel(model); - setViewProperties(); -} - -void QueryResultsDialog::setViewProperties() -{ - queryView->setColumnHidden(0, true); //hide ID column - queryView->setSelectionMode(QAbstractItemView::SingleSelection); - queryView->setSelectionBehavior(QAbstractItemView::SelectRows); - queryView->setEditTriggers(QAbstractItemView::NoEditTriggers); - queryView->resizeColumnsToContents(); - - QHeaderView* header = queryView->horizontalHeader(); - header->setStretchLastSection(true); -} - -void QueryResultsDialog::on_openButton_clicked() -{ - QItemSelectionModel* selection = queryView->selectionModel(); - - if (selection->hasSelection()) - { - queryView->selectColumn(0); - QModelIndexList indexes = selection->selectedIndexes(); - int listID = (queryView->model()->data(indexes.first())).toInt(); - - emit listSelected(listID); - - this->done(QDialog::Accepted); - } - else - OGSError::box("No data selected."); -} - -void QueryResultsDialog::on_cancelButton_clicked() -{ - this->done(QDialog::Rejected); -} diff --git a/Gui/DataView/QueryResultsDialog.h b/Gui/DataView/QueryResultsDialog.h deleted file mode 100644 index 2e374b32784..00000000000 --- a/Gui/DataView/QueryResultsDialog.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * \file QueryResultsDialog.h - * KR Initial implementation - */ - -#ifndef QUERYRESULTSDIALOG_H -#define QUERYRESULTSDIALOG_H - -#include "ui_DatabaseResultView.h" -#include <QSqlQueryModel> -#include <QDialog> - -/** - * \brief A Dialog for displaying the results of a database query in a table. - */ -class QueryResultsDialog : public QDialog, private Ui_DatabaseResultsView -{ - Q_OBJECT - -public: - QueryResultsDialog(QDialog* parent = 0); - ~QueryResultsDialog(void); - - /// Sets up the view. - void setView(QSqlQueryModel* model); - -private: - /// Sets the properties of the view. - void setViewProperties(); - -private slots: - /// Instructions if the Cancel-button is clicked. - void on_cancelButton_clicked(); - - /// Instructions if the Open-button is clicked. - void on_openButton_clicked(); - -signals: - void listSelected(int listID); -}; - -#endif //QUERYRESULTSDIALOG_H diff --git a/Gui/mainwindow.cpp b/Gui/mainwindow.cpp index 987007650ea..3345aff50af 100644 --- a/Gui/mainwindow.cpp +++ b/Gui/mainwindow.cpp @@ -15,7 +15,6 @@ #include "StationTreeModel.h" //dialogs -#include "DBConnectionDialog.h" #include "CondFromRasterDialog.h" #include "ConditionWriterDialog.h" #include "DiagramPrefsDialog.h" @@ -35,7 +34,6 @@ #include "SHPImportDialog.h" #endif -#include "DatabaseConnection.h" #include "OGSError.h" #include "VtkRaster.h" #include "RecentFiles.h" @@ -61,7 +59,7 @@ #include "GocadInterface.h" #include "MeshIO/GMSHInterface.h" #include "MeshIO/TetGenInterface.h" -#include "NetCDFInterface.h" //YW 07.2010 +#include "NetCDFInterface.h" #include "OGSIOVer4.h" #include "PetrelInterface.h" #include "StationIO.h" @@ -72,12 +70,8 @@ #include "StringTools.h" -// MSH -#include "msh_mesh.h" -#include "MshEditor.h" //test - // MSHGEOTOOLS -#include "ExtractMeshNodes.h" +//TODO6 #include "ExtractMeshNodes.h" // Qt includes #include <QDesktopWidget> @@ -107,19 +101,11 @@ #include "BuildInfo.h" #endif // OGS_BUILD_INFO -//// test only -//#include "rf_mmp_new.h" -//#include "rf_msp_new.h" -//#include "rf_mfp_new.h" - -/// FEM. 11.03.2010. WW -#include "problem.h" -Problem* aproblem = NULL; using namespace FileIO; MainWindow::MainWindow(QWidget* parent /* = 0*/) - : QMainWindow(parent), _db (NULL), _project(), _import_files_menu(NULL) + : QMainWindow(parent), _project(), _import_files_menu(NULL) { setupUi(this); @@ -377,7 +363,6 @@ MainWindow::MainWindow(QWidget* parent /* = 0*/) MainWindow::~MainWindow() { delete _import_files_menu; - delete _db; delete _vtkVisPipeline; delete _meshModels; delete _processModel; @@ -448,34 +433,6 @@ void MainWindow::open() } } -void MainWindow::openDatabase() -{ - if (_db == NULL) - { - _db = new DatabaseConnection(_geoModels); - _db->dbConnect(); - } - - if (_db != NULL && _db->isConnected()) - { - _db->getListSelection(); - updateDataViews(); - } -} - -void MainWindow::openDatabaseConnection() -{ - if (_db == NULL) - _db = new DatabaseConnection(_geoModels); - DBConnectionDialog* dbConn = new DBConnectionDialog(); - connect( - dbConn, - SIGNAL(connectionRequested(QString, QString, QString, QString, QString)), - _db, - SLOT(setConnection(QString, QString, QString, QString, QString))); - dbConn->show(); -} - void MainWindow::openRecentFile() { QAction* action = qobject_cast<QAction*> (sender()); @@ -1316,7 +1273,6 @@ void MainWindow::showDiagramPrefsDialog(QModelIndex &index) if ((stn->type() == GeoLib::Station::STATION) && stn->getSensorData()) { DiagramPrefsDialog* prefs ( new DiagramPrefsDialog(stn) ); - //DiagramPrefsDialog* prefs = new DiagramPrefsDialog(stn, listName, _db); prefs->setAttribute(Qt::WA_DeleteOnClose); prefs->show(); } diff --git a/Gui/mainwindow.h b/Gui/mainwindow.h index 378ebf8deb5..d75da6d5312 100644 --- a/Gui/mainwindow.h +++ b/Gui/mainwindow.h @@ -17,7 +17,6 @@ class ElementTreeModel; class StationTreeModel; class ProcessModel; class VtkVisPipeline; -class DatabaseConnection; class VisPrefsDialog; #ifdef OGS_USE_VRPN @@ -76,8 +75,6 @@ protected slots: void importFeflow(); void importTetGen(); void loadFEMConditions(std::string geoName); - void openDatabase(); - void openDatabaseConnection(); void openRecentFile(); void about(); void showAddPipelineFilterItemDialog(QModelIndex parentIndex); @@ -128,7 +125,6 @@ private: QString curFile; - DatabaseConnection* _db; BaseLib::FileFinder _fileFinder; GEOModels* _geoModels; MshModel* _meshModels; diff --git a/Gui/mainwindow.ui b/Gui/mainwindow.ui index 7df37a485f4..e056d6667ee 100644 --- a/Gui/mainwindow.ui +++ b/Gui/mainwindow.ui @@ -101,7 +101,6 @@ <addaction name="actionExportOpenSG"/> </widget> <addaction name="action_Open"/> - <addaction name="action_Database"/> <addaction name="actionSave_As"/> <addaction name="separator"/> <addaction name="menuExport"/> @@ -118,7 +117,6 @@ <property name="title"> <string>Settings</string> </property> - <addaction name="action_DatabaseConnection"/> <addaction name="action_VisualisationSettings"/> <addaction name="action_TrackingSettings"/> </widget> @@ -473,38 +471,6 @@ </hint> </hints> </connection> - <connection> - <sender>action_Database</sender> - <signal>triggered()</signal> - <receiver>MainWindowClass</receiver> - <slot>openDatabase()</slot> - <hints> - <hint type="sourcelabel"> - <x>-1</x> - <y>-1</y> - </hint> - <hint type="destinationlabel"> - <x>399</x> - <y>299</y> - </hint> - </hints> - </connection> - <connection> - <sender>action_DatabaseConnection</sender> - <signal>triggered()</signal> - <receiver>MainWindowClass</receiver> - <slot>openDatabaseConnection()</slot> - <hints> - <hint type="sourcelabel"> - <x>-1</x> - <y>-1</y> - </hint> - <hint type="destinationlabel"> - <x>399</x> - <y>299</y> - </hint> - </hints> - </connection> <connection> <sender>actionSave_As</sender> <signal>triggered()</signal> @@ -620,8 +586,6 @@ </connections> <slots> <slot>open()</slot> - <slot>openDatabase()</slot> - <slot>openDatabaseConnection()</slot> <slot>import()</slot> <slot>save()</slot> <slot>showVisalizationPrefsDialog()</slot> -- GitLab