From bb524a16556ab91543ae0a11fdcf39b79681c24a Mon Sep 17 00:00:00 2001 From: duanshengchao <519970194@qq.com> Date: Fri, 23 May 2025 17:55:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E2=80=98=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E2=80=99=E7=BC=96=E8=BE=91=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E8=AF=B7=E5=81=87=E9=93=BE=E6=8E=A5=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E5=8F=8C=E5=87=BB=E6=89=93=E5=BC=80=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 3 + include/connInfoEditDialog.h | 0 include/connectionDialog.h | 1 + source/connInfoEditDialog.cpp | 0 source/connectionDialog.cpp | 57 ++++- ui/connInfoEditDialog.ui | 468 ++++++++++++++++++++++++++++++++++ ui/connectionDialog.ui | 5 +- ui/mainwindow.ui | 8 +- 8 files changed, 538 insertions(+), 4 deletions(-) create mode 100644 include/connInfoEditDialog.h create mode 100644 source/connInfoEditDialog.cpp create mode 100644 ui/connInfoEditDialog.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index 0808303..c0967ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ 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 @@ -59,6 +60,7 @@ 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 @@ -84,6 +86,7 @@ set(UI_FILES ui/mainwindow.ui ui/dbBrowser.ui ui/connectionDialog.ui + ui/connInfoEditDialog.ui ui/messageDialog.ui ui/modelInfoEditDialog.ui ui/textEditWidget.ui diff --git a/include/connInfoEditDialog.h b/include/connInfoEditDialog.h new file mode 100644 index 0000000..e69de29 diff --git a/include/connectionDialog.h b/include/connectionDialog.h index ce20e0d..c60e9a7 100644 --- a/include/connectionDialog.h +++ b/include/connectionDialog.h @@ -60,6 +60,7 @@ public slots: void onBtnClicked_remove(); void onComboxChanged_dbType(const QString&); void onTableCellClicked_connList(int, int); + void onTableCellDbClicked_connList(int, int); }; #endif // CONNECTIONDIALOG_H diff --git a/source/connInfoEditDialog.cpp b/source/connInfoEditDialog.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/connectionDialog.cpp b/source/connectionDialog.cpp index 52f470a..a5ababf 100644 --- a/source/connectionDialog.cpp +++ b/source/connectionDialog.cpp @@ -47,6 +47,7 @@ void ConnectionDialog::showEvent(QShowEvent* e) QString connID = item->data(Qt::UserRole + itemID).toString(); loadConnInfo(connID); m_curConnListRow = 0; + ui->btnSave->setEnabled(false); } QDialog::showEvent(e); @@ -59,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(); @@ -110,12 +111,19 @@ void ConnectionDialog::initialize() ui->splitter->setStretchFactor(0, 3); connect(ui->connectionList, &QTableWidget::cellClicked, this, &ConnectionDialog::onTableCellClicked_connList); + connect(ui->connectionList, &QTableWidget::cellDoubleClicked, this, &ConnectionDialog::onTableCellDbClicked_connList); connect(ui->comboBox_dbType, &QComboBox::currentTextChanged, this, &ConnectionDialog::onComboxChanged_dbType); connect(ui->btnOpen, &QPushButton::clicked, this, &ConnectionDialog::onBtnClicked_open); connect(ui->btnCancle, &QPushButton::clicked, this, &ConnectionDialog::onBtnClicked_cancle); connect(ui->btnSave, &QPushButton::clicked, this, &ConnectionDialog::onBtnClicked_save); connect(ui->btnAdd, &QPushButton::clicked, this, &ConnectionDialog::onBtnClicked_add); connect(ui->btnRemove, &QPushButton::clicked, this, &ConnectionDialog::onBtnClicked_remove); + + QList lineEdits = this->findChildren(); + for(QLineEdit* lineEdit : lineEdits) + connect(lineEdit, &QLineEdit::textEdited, this, [this]{ui->btnSave->setEnabled(true);}); + connect(ui->plainTextEdit, &QPlainTextEdit::textChanged, this, [this]{ui->btnSave->setEnabled(true);}); + connect(ui->comboBox_dbType, &QComboBox::currentIndexChanged, this, [this]{ui->btnSave->setEnabled(true);}); } void ConnectionDialog::appendConnListItem(const QString& connID, const QString& connName, const QString& connRemark) @@ -256,6 +264,7 @@ void ConnectionDialog::onComboxChanged_dbType(const QString& text) void ConnectionDialog::onTableCellClicked_connList(int row, int column) { + //qDebug() << "cellClicked"; if(m_curConnListRow != row) { if(m_isNewStatus) @@ -273,15 +282,58 @@ void ConnectionDialog::onTableCellClicked_connList(int row, int column) m_isNewStatus = false; removeConnListItem(m_curConnListRow); } + else if(ui->btnSave->isEnabled()) //信息有修改 + { + 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; + } + } + } //刷新信息 QTableWidgetItem* item = ui->connectionList->item(row, 0); QString connID = item->data(Qt::UserRole + itemID).toString(); loadConnInfo(connID); m_curConnListRow = row; + ui->btnSave->setEnabled(false); } } +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(); +} + void ConnectionDialog::onBtnClicked_open() { if(ui->lineEdit_connection->text() == "" || ui->lineEdit_hostName->text() == "" || ui->lineEdit_userName->text() == "" || @@ -363,6 +415,7 @@ void ConnectionDialog::onBtnClicked_save() item->setText(config.strComment); Settings::instance().saveDatabaseConfig(config); + ui->btnSave->setEnabled(false); } void ConnectionDialog::onBtnClicked_add() @@ -376,6 +429,7 @@ void ConnectionDialog::onBtnClicked_add() } addNewConnListItem(); m_isNewStatus = true; + ui->btnSave->setEnabled(true); } void ConnectionDialog::onBtnClicked_remove() @@ -389,6 +443,7 @@ void ConnectionDialog::onBtnClicked_remove() removeConnListItem(m_curConnListRow); if(m_isNewStatus) m_isNewStatus = false; + ui->btnSave->setEnabled(false); } } } diff --git a/ui/connInfoEditDialog.ui b/ui/connInfoEditDialog.ui new file mode 100644 index 0000000..90286eb --- /dev/null +++ b/ui/connInfoEditDialog.ui @@ -0,0 +1,468 @@ + + + connInfoEditDialog + + + + 0 + 0 + 431 + 422 + + + + 会话编辑 + + + + :/img/images/icon_disconnect.png:/img/images/icon_disconnect.png + + + + + + + + + 0 + + + false + + + true + + + + + :/img/images/icon_setting.png:/img/images/icon_setting.png + + + 配置 + + + + 18 + + + 10 + + + 18 + + + 0 + + + 0 + + + 10 + + + + + + 0 + 21 + + + + + 16777215 + 21 + + + + 30 + + + + + + + + 91 + 21 + + + + + 91 + 21 + + + + 用户名: + + + + + + + + 91 + 21 + + + + + 91 + 21 + + + + 端口号: + + + + + + + + 0 + 21 + + + + + 16777215 + 21 + + + + 30 + + + + + + + + 0 + 21 + + + + + 16777215 + 21 + + + + 30 + + + QLineEdit::EchoMode::Password + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 51 + 21 + + + + + 51 + 21 + + + + 5432 + + + + + + + color: rgb(255, 0, 0); + + + + + + Qt::AlignmentFlag::AlignCenter + + + + + + + + + + + 91 + 21 + + + + + 91 + 21 + + + + 备注: + + + + + + + + 106 + 21 + + + + + 106 + 21 + + + + 主机名/IP地址: + + + + + + + + 91 + 21 + + + + + 91 + 21 + + + + 链接名称: + + + + + + + + 91 + 21 + + + + + 91 + 21 + + + + 密码: + + + + + + + + + + + + + + + 0 + 21 + + + + + 16777215 + 21 + + + + 30 + + + + + + + + 91 + 21 + + + + + 91 + 21 + + + + 数据库类型: + + + + + + + + 0 + 26 + + + + + 16777215 + 26 + + + + + PostgreSQL + + + + :/img/images/icon_postgresql.png:/img/images/icon_postgresql.png + + + + + MySQL + + + + :/img/images/icon_mysql.png:/img/images/icon_mysql.png + + + + + + + + + 91 + 21 + + + + + 91 + 21 + + + + 数据库名称: + + + + + + + + 0 + 21 + + + + + 16777215 + 21 + + + + 30 + + + + + + + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + 86 + 31 + + + + + 86 + 31 + + + + 保存 + + + + + + + + 86 + 31 + + + + + 86 + 31 + + + + 取消 + + + + + + + + + + + + diff --git a/ui/connectionDialog.ui b/ui/connectionDialog.ui index 6bc808e..24dc0af 100644 --- a/ui/connectionDialog.ui +++ b/ui/connectionDialog.ui @@ -15,7 +15,7 @@ - :/img/images/icon_database.png:/img/images/icon_database.png + :/img/images/icon_disconnect.png:/img/images/icon_disconnect.png @@ -179,6 +179,9 @@ QTableView::item:selected 0 + + false + diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index 34f277b..087d024 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -14,8 +14,8 @@ PowerModeler - - :/img/images/icons_database.png:/img/images/icons_database.png + + :/img/images/icon_database.png:/img/images/icon_database.png QPushButton @@ -31,6 +31,10 @@ QPushButton:pressed { background-color:rgba(70,130,180,50); } +QPushButton:disabled +{ + color:rgb(180,180,180); +} QComboBox QAbstractItemView {