0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 08:34:38 +03:00

Port property has been added to connection describer

This commit is contained in:
Arin Alexander 2018-01-18 20:13:18 +03:00
parent 6bbf3e4210
commit f64a918ffe
5 changed files with 113 additions and 76 deletions

View File

@ -117,6 +117,8 @@ ConnectionDesc *ConnectionDialog::uiToConnection(LimeReport::ConnectionDesc* con
result = new LimeReport::ConnectionDesc(); result = new LimeReport::ConnectionDesc();
result ->setName(ConnectionDesc::connectionNameForReport(ui->leConnectionName->text())); result ->setName(ConnectionDesc::connectionNameForReport(ui->leConnectionName->text()));
result ->setHost(ui->leServerName->text()); result ->setHost(ui->leServerName->text());
if (!ui->lePort->text().isEmpty())
result->setPort(ui->lePort->text().toInt());
result ->setDriver(ui->cbbDrivers->currentText()); result ->setDriver(ui->cbbDrivers->currentText());
result ->setUserName(ui->leUserName->text()); result ->setUserName(ui->leUserName->text());
result ->setPassword(ui->lePassword->text()); result ->setPassword(ui->lePassword->text());
@ -139,6 +141,7 @@ void ConnectionDialog::connectionToUI()
ui->cbbDrivers->setCurrentIndex(ui->cbbDrivers->findText(m_connection->driver())); ui->cbbDrivers->setCurrentIndex(ui->cbbDrivers->findText(m_connection->driver()));
ui->cbAutoConnect->setChecked(m_connection->autoconnect()); ui->cbAutoConnect->setChecked(m_connection->autoconnect());
ui->cbbKeepCredentials->setChecked(!m_connection->keepDBCredentials()); ui->cbbKeepCredentials->setChecked(!m_connection->keepDBCredentials());
ui->lePort->setText(m_connection->port()!=-1?QString::number(m_connection->port()):"");
} }
void ConnectionDialog::on_toolButton_clicked() void ConnectionDialog::on_toolButton_clicked()

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>420</width> <width>420</width>
<height>294</height> <height>323</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -17,7 +17,7 @@
<iconset resource="lrdatabrowser.qrc"> <iconset resource="lrdatabrowser.qrc">
<normaloff>:/databrowser/images/database_disconnected</normaloff>:/databrowser/images/database_disconnected</iconset> <normaloff>:/databrowser/images/database_disconnected</normaloff>:/databrowser/images/database_disconnected</iconset>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
@ -44,88 +44,106 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QFormLayout" name="formLayout"> <layout class="QHBoxLayout" name="horizontalLayout_4">
<item row="0" column="0"> <item>
<widget class="QLabel" name="lbDriver"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="text">
<string>Driver</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="cbbDrivers"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbServer">
<property name="text">
<string>Server </string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="leServerName">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbUser">
<property name="text">
<string>User</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="leUserName">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lbPassword">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lePassword">
<property name="text">
<string/>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lbDatabase">
<property name="text">
<string>Database</string>
</property>
</widget>
</item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>2</number>
</property>
<item> <item>
<widget class="QLineEdit" name="leDataBase"> <widget class="QLabel" name="lbDriver">
<property name="text">
<string>Driver</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lbServer">
<property name="text">
<string>Server </string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Port</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lbUser">
<property name="text">
<string>User</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lbPassword">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lbDatabase">
<property name="text">
<string>Database</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QComboBox" name="cbbDrivers"/>
</item>
<item>
<widget class="QLineEdit" name="leServerName">
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QToolButton" name="toolButton"> <widget class="QLineEdit" name="lePort"/>
</item>
<item>
<widget class="QLineEdit" name="leUserName">
<property name="text"> <property name="text">
<string>...</string> <string/>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QLineEdit" name="lePassword">
<property name="text">
<string/>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="QLineEdit" name="leDataBase">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>

View File

@ -342,13 +342,13 @@ void ModelToDataSource::slotModelDestroed()
ConnectionDesc::ConnectionDesc(QSqlDatabase db, QObject *parent) ConnectionDesc::ConnectionDesc(QSqlDatabase db, QObject *parent)
: QObject(parent), m_connectionName(db.connectionName()), m_connectionHost(db.hostName()), m_connectionDriver(db.driverName()), : QObject(parent), m_connectionName(db.connectionName()), m_connectionHost(db.hostName()), m_connectionDriver(db.driverName()),
m_databaseName(db.databaseName()), m_user(db.userName()), m_password(db.password()), m_autoconnect(false), m_databaseName(db.databaseName()), m_user(db.userName()), m_password(db.password()), m_port(-1), m_autoconnect(false),
m_internal(false), m_keepDBCredentials(true) m_internal(false), m_keepDBCredentials(true)
{} {}
ConnectionDesc::ConnectionDesc(QObject *parent) ConnectionDesc::ConnectionDesc(QObject *parent)
:QObject(parent),m_connectionName(""),m_connectionHost(""),m_connectionDriver(""), :QObject(parent),m_connectionName(""),m_connectionHost(""), m_connectionDriver(""),
m_databaseName(""), m_user(""), m_password(""), m_autoconnect(false), m_databaseName(""), m_user(""), m_password(""), m_port(-1), m_autoconnect(false),
m_internal(false), m_keepDBCredentials(true) m_internal(false), m_keepDBCredentials(true)
{} {}
@ -383,6 +383,16 @@ QString ConnectionDesc::connectionNameForReport(const QString &connectionName)
return connectionName.compare(tr("defaultConnection")) == 0 ? QSqlDatabase::defaultConnection : connectionName; return connectionName.compare(tr("defaultConnection")) == 0 ? QSqlDatabase::defaultConnection : connectionName;
} }
int ConnectionDesc::port() const
{
return m_port;
}
void ConnectionDesc::setPort(int port)
{
m_port = port;
}
bool ConnectionDesc::keepDBCredentials() const bool ConnectionDesc::keepDBCredentials() const
{ {
return m_keepDBCredentials; return m_keepDBCredentials;

View File

@ -111,6 +111,7 @@ class ConnectionDesc : public QObject{
Q_PROPERTY(QString host READ host WRITE setHost) Q_PROPERTY(QString host READ host WRITE setHost)
Q_PROPERTY(bool autoconnect READ autoconnect WRITE setAutoconnect) Q_PROPERTY(bool autoconnect READ autoconnect WRITE setAutoconnect)
Q_PROPERTY(bool keepDBCredentials READ keepDBCredentials WRITE setKeepDBCredentials) Q_PROPERTY(bool keepDBCredentials READ keepDBCredentials WRITE setKeepDBCredentials)
Q_PROPERTY(int port READ port WRITE setPort)
public: public:
typedef QSharedPointer<ConnectionDesc> Ptr; typedef QSharedPointer<ConnectionDesc> Ptr;
ConnectionDesc(QSqlDatabase db, QObject* parent=0); ConnectionDesc(QSqlDatabase db, QObject* parent=0);
@ -135,6 +136,8 @@ public:
void setInternal(bool value) {m_internal = value;} void setInternal(bool value) {m_internal = value;}
bool keepDBCredentials() const; bool keepDBCredentials() const;
void setKeepDBCredentials(bool keepDBCredentials); void setKeepDBCredentials(bool keepDBCredentials);
int port() const;
void setPort(int port);
public: public:
static QString connectionNameForUser(const QString& connectionName); static QString connectionNameForUser(const QString& connectionName);
static QString connectionNameForReport(const QString& connectionName); static QString connectionNameForReport(const QString& connectionName);
@ -147,6 +150,7 @@ private:
QString m_databaseName; QString m_databaseName;
QString m_user; QString m_user;
QString m_password; QString m_password;
int m_port;
bool m_autoconnect; bool m_autoconnect;
bool m_internal; bool m_internal;
bool m_keepDBCredentials; bool m_keepDBCredentials;

View File

@ -740,6 +740,8 @@ bool DataSourceManager::initAndOpenDB(QSqlDatabase& db, ConnectionDesc& connecti
db.setHostName(replaceVariables(connectionDesc.host())); db.setHostName(replaceVariables(connectionDesc.host()));
db.setUserName(replaceVariables(connectionDesc.userName())); db.setUserName(replaceVariables(connectionDesc.userName()));
db.setPassword(replaceVariables(connectionDesc.password())); db.setPassword(replaceVariables(connectionDesc.password()));
if (connectionDesc.port()!=-1)
db.setPort(connectionDesc.port());
if (!connectionDesc.keepDBCredentials() && m_dbCredentialsProvider){ if (!connectionDesc.keepDBCredentials() && m_dbCredentialsProvider){
if (!m_dbCredentialsProvider->getUserName(connectionDesc.name()).isEmpty()) if (!m_dbCredentialsProvider->getUserName(connectionDesc.name()).isEmpty())