修改新建链接相关bug
This commit is contained in:
parent
bb524a1655
commit
c35eba416d
|
|
@ -26,7 +26,6 @@ set(H_HEADER_FILES
|
|||
include/dbStructureModel.h
|
||||
include/dbStructureView.h
|
||||
include/connectionDialog.h
|
||||
include/connInfoEditDialog.h
|
||||
include/messageDialog.h
|
||||
include/messageBox.h
|
||||
include/settings.h
|
||||
|
|
@ -60,7 +59,6 @@ set(CPP_SOURCE_FILES
|
|||
source/dbStructureModel.cpp
|
||||
source/dbStructureView.cpp
|
||||
source/connectionDialog.cpp
|
||||
source/connInfoEditDialog.cpp
|
||||
source/messageDialog.cpp
|
||||
source/messageBox.cpp
|
||||
source/settings.cpp
|
||||
|
|
@ -86,7 +84,6 @@ set(UI_FILES
|
|||
ui/mainwindow.ui
|
||||
ui/dbBrowser.ui
|
||||
ui/connectionDialog.ui
|
||||
ui/connInfoEditDialog.ui
|
||||
ui/messageDialog.ui
|
||||
ui/modelInfoEditDialog.ui
|
||||
ui/textEditWidget.ui
|
||||
|
|
|
|||
|
|
@ -0,0 +1,164 @@
|
|||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(PowerModeler VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Sql)
|
||||
|
||||
#默认ui文件要和.h头文件在一个目录,若不在一个目录,需要指定其所在目录
|
||||
set(CMAKE_AUTOUIC_SEARCH_PATHS "ui")
|
||||
|
||||
set(H_HEADER_FILES
|
||||
include/global.h
|
||||
include/logger.h
|
||||
include/mainwindow.h
|
||||
include/dbManager.h
|
||||
include/dbBrowser.h
|
||||
include/dbStructureNode.h
|
||||
include/dbStructureModel.h
|
||||
include/dbStructureView.h
|
||||
include/connectionDialog.hgit
|
||||
include/messageDialog.h
|
||||
include/messageBox.h
|
||||
include/settings.h
|
||||
include/tableWidgetHoverDelegate.h
|
||||
include/textColorPreserveDelegate.h
|
||||
include/customMenu.h
|
||||
include/multiLineHeaderView.h
|
||||
include/modelInfoEditDialog.h
|
||||
include/sqlQueryExecutor.h
|
||||
include/attributeNamespace.h
|
||||
include/attributeTableModel.h
|
||||
include/attributeTableDelegate.h
|
||||
include/attributeView.h
|
||||
include/attributeSelector.h
|
||||
include/maskLayer.h
|
||||
include/maskManager.h
|
||||
include/customBorderContainer.h
|
||||
include/groupSelectionDialog.h
|
||||
include/dataSyncManager.h
|
||||
include/importExportManager.h
|
||||
)
|
||||
|
||||
set(CPP_SOURCE_FILES
|
||||
source/main.cpp
|
||||
source/global.cpp
|
||||
source/logger.cpp
|
||||
source/mainwindow.cpp
|
||||
source/dbManager.cpp
|
||||
source/dbBrowser.cpp
|
||||
source/dbStructureNode.cpp
|
||||
source/dbStructureModel.cpp
|
||||
source/dbStructureView.cpp
|
||||
source/connectionDialog.cpp
|
||||
source/messageDialog.cpp
|
||||
source/messageBox.cpp
|
||||
source/settings.cpp
|
||||
source/tableWidgetHoverDelegate.cpp
|
||||
source/textColorPreserveDelegate.cpp
|
||||
source/customMenu.cpp
|
||||
source/multiLineHeaderView.cpp
|
||||
source/modelInfoEditDialog.cpp
|
||||
source/sqlQueryExecutor.cpp
|
||||
source/attributeTableModel.cpp
|
||||
source/attributeTableDelegate.cpp
|
||||
source/attributeView.cpp
|
||||
source/attributeSelector.cpp
|
||||
source/maskLayer.cpp
|
||||
source/maskManager.cpp
|
||||
source/customBorderContainer.cpp
|
||||
source/groupSelectionDialog.cpp
|
||||
source/dataSyncManager.cpp
|
||||
source/importExportManager.cpp
|
||||
)
|
||||
|
||||
set(UI_FILES
|
||||
ui/mainwindow.ui
|
||||
ui/dbBrowser.ui
|
||||
ui/connectionDialog.ui
|
||||
ui/messageDialog.ui
|
||||
ui/modelInfoEditDialog.ui
|
||||
ui/textEditWidget.ui
|
||||
ui/attributeSelector.ui
|
||||
ui/groupSelectionDialog.ui
|
||||
)
|
||||
|
||||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||
qt_add_executable(PowerModeler
|
||||
MANUAL_FINALIZATION
|
||||
${H_HEADER_FILES}
|
||||
${CPP_SOURCE_FILES}
|
||||
${UI_FILES}
|
||||
resource/PowerModeler.qrc
|
||||
)
|
||||
# Define target properties for Android with Qt 6 as:
|
||||
# set_property(TARGET PowerModeler APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
|
||||
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
|
||||
else()
|
||||
if(ANDROID)
|
||||
add_library(PowerModeler SHARED
|
||||
${H_HEADER_FILES}
|
||||
${CPP_SOURCE_FILES}
|
||||
${UI_FILES}
|
||||
resource/PowerModeler.qrc
|
||||
)
|
||||
# Define properties for Android with Qt 5 after find_package() calls as:
|
||||
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
|
||||
else()
|
||||
add_executable(PowerModeler
|
||||
${H_HEADER_FILES}
|
||||
${CPP_SOURCE_FILES}
|
||||
${UI_FILES}
|
||||
resource/PowerModeler.qrc
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_include_directories(PowerModeler PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
target_link_libraries(PowerModeler PRIVATE Qt${QT_VERSION_MAJOR}::Core
|
||||
Qt${QT_VERSION_MAJOR}::Widgets
|
||||
Qt${QT_VERSION_MAJOR}::Gui
|
||||
Qt${QT_VERSION_MAJOR}::Sql)
|
||||
|
||||
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
||||
# If you are developing for iOS or macOS you should consider setting an
|
||||
# explicit, fixed bundle identifier manually though.
|
||||
if(${QT_VERSION} VERSION_LESS 6.1.0)
|
||||
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.PowerModeler)
|
||||
endif()
|
||||
set_target_properties(PowerModeler PROPERTIES
|
||||
${BUNDLE_ID_OPTION}
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||
MACOSX_BUNDLE TRUE
|
||||
WIN32_EXECUTABLE TRUE
|
||||
)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
install(TARGETS PowerModeler
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
|
||||
#配置文件
|
||||
set(CONFIG_FILE "app_config.ini")
|
||||
set(CONFIG_FILE_DIR "${CMAKE_BINARY_DIR}")
|
||||
if(NOT EXISTS "${CONFIG_FILE_DIR}/${CONFIG_FILE}")
|
||||
file(COPY app_config.ini DESTINATION "${CONFIG_FILE_DIR}")
|
||||
else()
|
||||
message(STATUS "${CONFIG_FILE} already exists, skipping copy")
|
||||
endif()
|
||||
|
||||
if(QT_VERSION_MAJOR EQUAL 6)
|
||||
qt_finalize_executable(PowerModeler)
|
||||
endif()
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
#ifndef CONNINFOEDITIALOG_H
|
||||
#define CONNINFOEDITIALOG_H
|
||||
|
||||
#include "global.h"
|
||||
#include <QDialog>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class ConnInfoEditDialog;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class MainWindow;
|
||||
class MaskLayer;
|
||||
class CustomBorderContainer;
|
||||
|
||||
class ConnInfoEditDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ConnInfoEditDialog(QWidget *parent = nullptr);
|
||||
~ConnInfoEditDialog();
|
||||
|
||||
void setMainWindow(MainWindow* w){m_pMainWindow = w;}
|
||||
void setErrorInfo(const QString&);
|
||||
void clearErrorInfo();
|
||||
void loadConnInfo(const QString&);
|
||||
|
||||
Q_INVOKABLE void showMask();
|
||||
Q_INVOKABLE void hideMask();
|
||||
|
||||
private:
|
||||
void initialize();
|
||||
|
||||
Ui::ConnInfoEditDialog *ui;
|
||||
MaskLayer* m_pMaskLayer;
|
||||
MainWindow* m_pMainWindow;
|
||||
CustomBorderContainer* m_customBorderContainer;
|
||||
QString m_connID;
|
||||
|
||||
public slots:
|
||||
void onBtnClicked_save();
|
||||
void onBtnClicked_cancle();
|
||||
void onComboxChanged_dbType(const QString&);
|
||||
};
|
||||
|
||||
#endif //CONNINFOEDITIALOG_H
|
||||
|
|
@ -4,7 +4,6 @@
|
|||
#include "global.h"
|
||||
#include <QDialog>
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class ConnectionDialog;
|
||||
|
|
@ -50,7 +49,8 @@ private:
|
|||
CustomBorderContainer* m_customBorderContainer;
|
||||
|
||||
signals:
|
||||
void addConnection(DatabaseConfig&);
|
||||
void addConnection(const DatabaseConfig&);
|
||||
void updateConnectionInfo(const DatabaseConfig&);
|
||||
|
||||
public slots:
|
||||
void onBtnClicked_open();
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ public:
|
|||
|
||||
bool addDatabase(const DatabaseConfig& config);
|
||||
void removeDatabase(const QString& strConnectionName);
|
||||
void updataDatabase(const DatabaseConfig& config);
|
||||
bool connect(const QString& strConnectionName);
|
||||
void disconnect(const QString& strConnectionName);
|
||||
QStringList conncetions();//获取所有链接名称
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public:
|
|||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||
|
||||
//业务功能接口
|
||||
void addConnection(const QString& name, const QString& dbType);
|
||||
void addConnection(const QString& name, const QString& connID);
|
||||
void removeConnection(const QString& name);
|
||||
QModelIndex getConnNodeIndex(const QString& name);
|
||||
void addDataModel(const QString& connection, Model& model);
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ struct DatabaseConfig
|
|||
|
||||
DatabaseConfig()
|
||||
{
|
||||
strID = "";
|
||||
strConnectionName = "";
|
||||
strDBType = "QPSQL";
|
||||
strHost = "";
|
||||
|
|
|
|||
|
|
@ -59,7 +59,8 @@ private slots:
|
|||
void onActionTrigger_removeModel();
|
||||
void onActionTrigger_addGroup(int);
|
||||
|
||||
void onSIG_addConnection(DatabaseConfig&);
|
||||
void onSIG_addConnection(const DatabaseConfig&);
|
||||
void onSIG_updateConnectionInfo(const DatabaseConfig&);
|
||||
void onSIG_errorFromDBManger(const QString& strConnectionName, const QString& error);
|
||||
void onSIG_errorFormSQLExecutor(const QString& error);
|
||||
void onSIG_connectionStatusChanged(const QString& strConnectionName, bool bConnected);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,128 @@
|
|||
#include "connInfoEditDialog.h"
|
||||
#include "./ui_connInfoEditDialog.h"
|
||||
#include "maskLayer.h"
|
||||
#include "mainwindow.h"
|
||||
#include "settings.h"
|
||||
#include "customBorderContainer.h"
|
||||
|
||||
ConnInfoEditDialog::ConnInfoEditDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::ConnInfoEditDialog)
|
||||
, m_pMainWindow(nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
if(QSysInfo::kernelType() == "linux")
|
||||
{
|
||||
//Linux下默认的Qt::Dialog即使有父窗口也无法按照子窗口的行为进行展示,并且最大、最小按钮不好关闭,因此需要去掉Dialog属性,随之而来的问题是,模态无法起作用
|
||||
setWindowFlags(windowFlags() & ~Qt::Dialog);
|
||||
setStyleSheet("QDialog{border: 1px solid rgb(205,205,205);border-radius:5px;background-color:rgb(245,245,245);}");
|
||||
|
||||
m_customBorderContainer = new CustomBorderContainer(this);
|
||||
m_customBorderContainer->setOperationOptions(CustomBorderContainer::Movable | CustomBorderContainer::Resizable);
|
||||
}
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
ConnInfoEditDialog::~ConnInfoEditDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ConnInfoEditDialog::initialize()
|
||||
{
|
||||
m_connID = "";
|
||||
m_pMaskLayer = new MaskLayer(this);
|
||||
|
||||
QIntValidator* validator = new QIntValidator(0, 9999, this);
|
||||
ui->lineEdit_port->setValidator(validator);
|
||||
ui->lineEdit_password->setEchoMode(QLineEdit::Password);
|
||||
|
||||
connect(ui->btnSave, &QPushButton::clicked, this, &ConnInfoEditDialog::onBtnClicked_save);
|
||||
connect(ui->btnCancle, &QPushButton::clicked, this, &ConnInfoEditDialog::onBtnClicked_cancle);
|
||||
connect(ui->comboBox_dbType, &QComboBox::currentTextChanged, this, &ConnInfoEditDialog::onComboxChanged_dbType);
|
||||
}
|
||||
|
||||
void ConnInfoEditDialog::setErrorInfo(const QString& info)
|
||||
{
|
||||
if(m_pMainWindow)
|
||||
m_pMainWindow->showMessageDialog(type_warning, QString::fromWCharArray(L"错误"),info);
|
||||
else
|
||||
ui->label_error->setText(info);
|
||||
}
|
||||
void ConnInfoEditDialog::clearErrorInfo()
|
||||
{
|
||||
if(m_pMainWindow)
|
||||
m_pMainWindow->hideMessageDialog();
|
||||
else
|
||||
ui->label_error->setText("");
|
||||
}
|
||||
|
||||
void ConnInfoEditDialog::showMask()
|
||||
{
|
||||
m_pMaskLayer->setGeometry(0, 0, this->width(), this->height());
|
||||
m_pMaskLayer->show();
|
||||
}
|
||||
void ConnInfoEditDialog::hideMask()
|
||||
{
|
||||
m_pMaskLayer->close();
|
||||
}
|
||||
|
||||
void ConnInfoEditDialog::loadConnInfo(const QString& connID)
|
||||
{
|
||||
DatabaseConfig config = Settings::instance().loadDatabaseConfig(connID);
|
||||
ui->lineEdit_connection->setText(config.strConnectionName);
|
||||
ui->lineEdit_hostName->setText(config.strHost);
|
||||
ui->lineEdit_port->setText(QString::number(config.nPort));
|
||||
ui->lineEdit_userName->setText(config.strUserName);
|
||||
ui->lineEdit_password->setText(config.strPassword);
|
||||
ui->lineEdit_dbName->setText(config.strDBName);
|
||||
if(config.strDBType == "QPSQL")
|
||||
ui->comboBox_dbType->setCurrentText("PostgreSQL");
|
||||
else if(config.strDBType == "QMYSQL")
|
||||
ui->comboBox_dbType->setCurrentText("MySQL");
|
||||
ui->plainTextEdit->setPlainText(config.strComment);
|
||||
|
||||
m_connID = connID;
|
||||
}
|
||||
|
||||
void ConnInfoEditDialog::onBtnClicked_save()
|
||||
{
|
||||
if(ui->lineEdit_connection->text() == "" || ui->lineEdit_hostName->text() == "" || ui->lineEdit_userName->text() == "" ||
|
||||
ui->lineEdit_password->text() == "" || ui->lineEdit_port->text() == "")
|
||||
{
|
||||
setErrorInfo(QString::fromWCharArray(L"除‘备注’外不能有其它信息为空"));
|
||||
return;
|
||||
}
|
||||
|
||||
DatabaseConfig config;
|
||||
config.strConnectionName = ui->lineEdit_connection->text();
|
||||
config.strHost = ui->lineEdit_hostName->text();
|
||||
config.nPort = ui->lineEdit_port->text().toInt();
|
||||
config.strUserName = ui->lineEdit_userName->text();
|
||||
config.strPassword = ui->lineEdit_password->text();
|
||||
config.strDBName = ui->lineEdit_dbName->text();
|
||||
if(ui->comboBox_dbType->currentText() == "PostgreSQL")
|
||||
config.strDBType = "QPSQL";
|
||||
else if(ui->comboBox_dbType->currentText() == "MySQL")
|
||||
config.strDBType = "QMYSQL";
|
||||
if(ui->plainTextEdit->toPlainText().isEmpty())
|
||||
config.strComment = QString::fromWCharArray(L"无");
|
||||
else
|
||||
config.strComment = ui->plainTextEdit->toPlainText();
|
||||
|
||||
Settings::instance().saveDatabaseConfig(config);
|
||||
}
|
||||
|
||||
void ConnInfoEditDialog::onBtnClicked_cancle()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
void ConnInfoEditDialog::onComboxChanged_dbType(const QString& text)
|
||||
{
|
||||
if(text == "PostgreSQL")
|
||||
ui->lineEdit_port->setText("5432");
|
||||
else if(text == "MySQL")
|
||||
ui->lineEdit_port->setText("3306");
|
||||
}
|
||||
|
|
@ -60,7 +60,7 @@ void ConnectionDialog::closeEvent(QCloseEvent* e)
|
|||
if(m_pMainWindow)
|
||||
{
|
||||
m_pMainWindow->showMessageDialog(type_question, QString::fromWCharArray(L"提示"),
|
||||
QString::fromWCharArray(L"当前正在新建连接的编辑中,确定放弃报吗"));
|
||||
QString::fromWCharArray(L"正在新建连接编辑中,确定放弃吗"));
|
||||
if(g_msgDlgBtn == btn_No)
|
||||
{
|
||||
e->ignore();
|
||||
|
|
@ -272,7 +272,7 @@ void ConnectionDialog::onTableCellClicked_connList(int row, int column)
|
|||
if(m_pMainWindow)
|
||||
{
|
||||
m_pMainWindow->showMessageDialog(type_question, QString::fromWCharArray(L"提示"),
|
||||
QString::fromWCharArray(L"当前正在新建连接的编辑中,确定放弃吗"));
|
||||
QString::fromWCharArray(L"正在新建连接编辑中,确定放弃吗"));
|
||||
if(g_msgDlgBtn == btn_No)
|
||||
{
|
||||
ui->connectionList->setCurrentCell(m_curConnListRow, 0);
|
||||
|
|
@ -308,28 +308,6 @@ void ConnectionDialog::onTableCellClicked_connList(int row, int column)
|
|||
void ConnectionDialog::onTableCellDbClicked_connList(int row, int column)
|
||||
{
|
||||
//qDebug() << "cellDoubleClicked";
|
||||
/*if(m_isNewStatus)
|
||||
{
|
||||
if(m_pMainWindow)
|
||||
{
|
||||
m_pMainWindow->showMessageDialog(type_question, QString::fromWCharArray(L"提示"),
|
||||
QString::fromWCharArray(L"当前正在新建连接的编辑中,确定放弃吗"));
|
||||
if(g_msgDlgBtn == btn_No)
|
||||
{
|
||||
ui->connectionList->setCurrentCell(m_curConnListRow, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_isNewStatus = false;
|
||||
removeConnListItem(m_curConnListRow);
|
||||
}
|
||||
|
||||
//刷新信息
|
||||
QTableWidgetItem* item = ui->connectionList->item(row, 0);
|
||||
QString connID = item->data(Qt::UserRole + itemID).toString();
|
||||
loadConnInfo(connID);
|
||||
m_curConnListRow = row;*/
|
||||
|
||||
//直接打开链接即可,触发doubleClick之前一定会先触发clicked
|
||||
onBtnClicked_open();
|
||||
}
|
||||
|
|
@ -343,6 +321,7 @@ void ConnectionDialog::onBtnClicked_open()
|
|||
return;
|
||||
}
|
||||
|
||||
//要先获取,否则下面的removeConnListItem会触发loadConnInfo从而刷新链接信息
|
||||
DatabaseConfig config;
|
||||
config.strConnectionName = ui->lineEdit_connection->text();
|
||||
config.strHost = ui->lineEdit_hostName->text();
|
||||
|
|
@ -355,6 +334,28 @@ void ConnectionDialog::onBtnClicked_open()
|
|||
else if(ui->comboBox_dbType->currentText() == "MySQL")
|
||||
config.strDBType = "QMYSQL";
|
||||
|
||||
if(m_isNewStatus)
|
||||
{
|
||||
// if(m_pMainWindow)
|
||||
// {
|
||||
// m_pMainWindow->showMessageDialog(type_question, QString::fromWCharArray(L"提示"),
|
||||
// QString::fromWCharArray(L"当前连接未保存,确认放弃吗"));
|
||||
// if(g_msgDlgBtn == btn_No)
|
||||
// return;
|
||||
// }
|
||||
|
||||
// removeConnListItem(m_curConnListRow);
|
||||
// m_isNewStatus = false;
|
||||
setErrorInfo(QString::fromWCharArray(L"请先保存当前新建链接"));
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
QTableWidgetItem* item = ui->connectionList->item(ui->connectionList->currentRow(), 0);
|
||||
if(item)
|
||||
config.strID = item->data(Qt::UserRole + itemID).toString();
|
||||
}
|
||||
|
||||
emit addConnection(config);
|
||||
}
|
||||
|
||||
|
|
@ -385,8 +386,19 @@ void ConnectionDialog::onBtnClicked_save()
|
|||
return;
|
||||
}
|
||||
|
||||
QString connName = ui->lineEdit_connection->text();
|
||||
for(int i = 0; i < ui->connectionList->rowCount() - 1; i++) //和已保存的链接对比
|
||||
{
|
||||
QTableWidgetItem* item = ui->connectionList->item(i, 0);
|
||||
if(item->text() == connName)
|
||||
{
|
||||
setErrorInfo(QString::fromWCharArray(L"已存在同名链接"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DatabaseConfig config;
|
||||
config.strConnectionName = ui->lineEdit_connection->text();
|
||||
config.strConnectionName = connName;
|
||||
config.strHost = ui->lineEdit_hostName->text();
|
||||
config.nPort = ui->lineEdit_port->text().toInt();
|
||||
config.strUserName = ui->lineEdit_userName->text();
|
||||
|
|
@ -416,6 +428,8 @@ void ConnectionDialog::onBtnClicked_save()
|
|||
|
||||
Settings::instance().saveDatabaseConfig(config);
|
||||
ui->btnSave->setEnabled(false);
|
||||
|
||||
emit updateConnectionInfo(config);
|
||||
}
|
||||
|
||||
void ConnectionDialog::onBtnClicked_add()
|
||||
|
|
|
|||
|
|
@ -61,6 +61,11 @@ void DatabaseManager::removeDatabase(const QString& strConnectionName)
|
|||
//从内存中删除
|
||||
m_configs.remove(strConnectionName);
|
||||
}
|
||||
void DatabaseManager::updataDatabase(const DatabaseConfig& config)
|
||||
{
|
||||
if(m_configs.contains(config.strConnectionName))
|
||||
m_configs[config.strConnectionName] = config;
|
||||
}
|
||||
|
||||
bool DatabaseManager::connect(const QString& strConnectionName)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -127,11 +127,12 @@ QVariant DBStructureModel::headerData(int section, Qt::Orientation orientation,
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
void DBStructureModel::addConnection(const QString& name, const QString& dbType)
|
||||
void DBStructureModel::addConnection(const QString& name, const QString& connID)
|
||||
{
|
||||
beginInsertRows(QModelIndex(), m_rootNode->childCount(), m_rootNode->childCount()); //链接节点是根节点的(m_rootNode)的子节点,根节点的索引是QModelIndex()
|
||||
|
||||
DBStructureNode* connectionNode = new DBStructureNode(ConnectionNode, name, m_rootNode);
|
||||
connectionNode->setData(Qt::UserRole + NodeDataRole::ID, connID);
|
||||
m_rootNode->appendChild(connectionNode);
|
||||
|
||||
endInsertRows(); //该语句之后会触发rowsInserted(const QModelIndex &parent, int first, int last)信号,通知视图刷新对应行
|
||||
|
|
|
|||
|
|
@ -161,6 +161,7 @@ void MainWindow::onActionTrigger_connect()
|
|||
m_pConnectionDialog->setMainWindow(this);
|
||||
m_pConnectionDialog->installEventFilter(this);
|
||||
connect(m_pConnectionDialog, &ConnectionDialog::addConnection, this, &MainWindow::onSIG_addConnection);
|
||||
connect(m_pConnectionDialog, &ConnectionDialog::updateConnectionInfo, this, &MainWindow::onSIG_updateConnectionInfo);
|
||||
connect(m_pConnectionDialog, &ConnectionDialog::finished, this, [=]{ MaskManager::instance()->hideMask(m_pConnectionDialog);});
|
||||
}
|
||||
|
||||
|
|
@ -230,7 +231,7 @@ void MainWindow::onActionTrigger_removeModel()
|
|||
m_pDBStrutureView->onActionTrigger_removeModel();
|
||||
}
|
||||
|
||||
void MainWindow::onSIG_addConnection(DatabaseConfig& config)
|
||||
void MainWindow::onSIG_addConnection(const DatabaseConfig& config)
|
||||
{
|
||||
bool result = m_dbManager->addDatabase(config);
|
||||
if(!result)
|
||||
|
|
@ -240,7 +241,12 @@ void MainWindow::onSIG_addConnection(DatabaseConfig& config)
|
|||
}
|
||||
|
||||
m_pConnectionDialog->close();
|
||||
m_pDBStrutureModel->addConnection(config.strConnectionName, config.strDBType);
|
||||
m_pDBStrutureModel->addConnection(config.strConnectionName, config.strID);
|
||||
}
|
||||
|
||||
void MainWindow::onSIG_updateConnectionInfo(const DatabaseConfig& config)
|
||||
{
|
||||
m_dbManager->updataDatabase(config);
|
||||
}
|
||||
|
||||
void MainWindow::onActionTrigger_addGroup(int modelID)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>connInfoEditDialog</class>
|
||||
<widget class="QDialog" name="connInfoEditDialog">
|
||||
<class>ConnInfoEditDialog</class>
|
||||
<widget class="QDialog" name="ConnInfoEditDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
|
|
|
|||
|
|
@ -197,11 +197,30 @@
|
|||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_modelType_2">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>71</width>
|
||||
<height>21</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>71</width>
|
||||
<height>21</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>模型图元:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_group">
|
||||
<attribute name="title">
|
||||
<string>类别信息</string>
|
||||
<string>属性分组</string>
|
||||
</attribute>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<property name="spacing">
|
||||
|
|
|
|||
Loading…
Reference in New Issue