From cc7fc51399f24ebd9ba13b821d1f670191494f1f Mon Sep 17 00:00:00 2001 From: taocong Date: Mon, 1 Jun 2026 19:32:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E6=8E=A7=E4=BB=B6=EF=BC=8C=E4=BF=AE=E5=A4=8D=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Uft30ChangeCode.pro | 2 + src/components/elasearchedit.cpp | 116 ++++++++++++++++++ src/components/elasearchedit.h | 46 +++++++ .../functionsearch/uf20functionsearchpage.cpp | 31 +++-- .../functionsearch/uf20functionsearchpage.h | 9 +- .../functionsearch/uft3functionsearchpage.cpp | 24 ++-- .../functionsearch/uft3functionsearchpage.h | 7 +- src/utils/datacache.cpp | 48 ++++---- src/utils/datacache.h | 4 +- 9 files changed, 232 insertions(+), 55 deletions(-) create mode 100644 src/components/elasearchedit.cpp create mode 100644 src/components/elasearchedit.h diff --git a/Uft30ChangeCode.pro b/Uft30ChangeCode.pro index 9f4ab6d..6cbd7c6 100644 --- a/Uft30ChangeCode.pro +++ b/Uft30ChangeCode.pro @@ -13,6 +13,7 @@ SOURCES += main.cpp \ src/pages/functionsearch/functionsearchpage.cpp \ src/pages/functionsearch/uf20functionsearchpage.cpp \ src/pages/functionsearch/uft3functionsearchpage.cpp \ + src/components/elasearchedit.cpp \ src/pages/help/helppage.cpp \ src/pages/settings/settingspage.cpp \ src/pages/metadatupdate/metadatupdatepage.cpp \ @@ -39,6 +40,7 @@ HEADERS += src/mainwindow/mainwindow.h \ src/pages/functionsearch/functionsearchpage.h \ src/pages/functionsearch/uf20functionsearchpage.h \ src/pages/functionsearch/uft3functionsearchpage.h \ + src/components/elasearchedit.h \ src/pages/help/helppage.h \ src/pages/settings/settingspage.h \ src/pages/metadatupdate/metadatupdatepage.h \ diff --git a/src/components/elasearchedit.cpp b/src/components/elasearchedit.cpp new file mode 100644 index 0000000..f6589fb --- /dev/null +++ b/src/components/elasearchedit.cpp @@ -0,0 +1,116 @@ +#include "elasearchedit.h" +#include +#include "ElaIcon.h" + +ElaSearchEdit::ElaSearchEdit(QWidget* parent) + : QWidget(parent), m_exactMatch(false) +{ + initUI(); +} + +ElaSearchEdit::~ElaSearchEdit() +{ +} + +void ElaSearchEdit::initUI() +{ + QHBoxLayout* mainLayout = new QHBoxLayout(this); + mainLayout->setSpacing(0); + mainLayout->setContentsMargins(0, 0, 0, 0); + + m_lineEdit = new ElaLineEdit(this); + m_lineEdit->setFixedHeight(35); + m_lineEdit->setPlaceholderText("输入查询内容"); + m_lineEdit->setIsClearButtonEnable(false); + + QHBoxLayout* inputLayout = new QHBoxLayout(m_lineEdit); + inputLayout->setContentsMargins(0, 0, 4, 0); + inputLayout->addStretch(); + + m_exactMatchBtn = addToolButton(m_lineEdit, ElaIconType::FontCase, "区分大小写", QSize(26, 26), true, false); + inputLayout->addWidget(m_exactMatchBtn); + + resetInputMargin(); + + mainLayout->addWidget(m_lineEdit); + + m_searchBtn = addToolButton(this, ElaIconType::MagnifyingGlass, "搜索", QSize(35, 35), false, false); + mainLayout->addWidget(m_searchBtn); + + connectSignals(); +} + +void ElaSearchEdit::connectSignals() +{ + connect(m_lineEdit, &ElaLineEdit::textChanged, this, &ElaSearchEdit::textChanged); + connect(m_lineEdit, &ElaLineEdit::returnPressed, this, &ElaSearchEdit::returnPressed); + connect(m_searchBtn, &ElaToolButton::clicked, this, &ElaSearchEdit::searchClicked); + connect(m_exactMatchBtn, &ElaToolButton::clicked, this, [this](bool checked) { + m_exactMatch = checked; + emit exactMatchChanged(checked); + }); +} + +void ElaSearchEdit::resetInputMargin() +{ + m_lineEdit->setTextMargins(0, 0, 30, 0); +} + +ElaToolButton* ElaSearchEdit::addToolButton(QWidget* parent, ElaIconType::IconName icon, const QString& tooltip, const QSize& size, bool checkable, bool checked) +{ + ElaToolButton* btn = new ElaToolButton(parent); + btn->setElaIcon(icon); + btn->setFixedSize(size); + btn->setToolTip(tooltip); + btn->setCheckable(checkable); + btn->setChecked(checked); + btn->setCursor(Qt::PointingHandCursor); + return btn; +} + +QString ElaSearchEdit::text() const +{ + return m_lineEdit->text(); +} + +void ElaSearchEdit::setText(const QString& text) +{ + m_lineEdit->setText(text); +} + +void ElaSearchEdit::setPlaceholderText(const QString& placeholderText) +{ + m_lineEdit->setPlaceholderText(placeholderText); +} + +void ElaSearchEdit::setFixedSize(const QSize& size) +{ + m_lineEdit->setFixedSize(size.width() - 35, size.height()); + m_searchBtn->setFixedSize(35, size.height()); + QWidget::setFixedSize(size); +} + +void ElaSearchEdit::setFixedSize(int w, int h) +{ + m_lineEdit->setFixedSize(w - 35, h); + m_searchBtn->setFixedSize(35, h); + QWidget::setFixedSize(w, h); +} + +void ElaSearchEdit::setFixedHeight(int h) +{ + m_lineEdit->setFixedHeight(h); + m_searchBtn->setFixedSize(35, h); + QWidget::setFixedHeight(h); +} + +bool ElaSearchEdit::isExactMatch() const +{ + return m_exactMatch; +} + +void ElaSearchEdit::setExactMatch(bool exact) +{ + m_exactMatch = exact; + m_exactMatchBtn->setChecked(exact); +} diff --git a/src/components/elasearchedit.h b/src/components/elasearchedit.h new file mode 100644 index 0000000..ee5de62 --- /dev/null +++ b/src/components/elasearchedit.h @@ -0,0 +1,46 @@ +#ifndef ELASEARCHEDIT_H +#define ELASEARCHEDIT_H + +#include +#include +#include +#include "ElaLineEdit.h" +#include "ElaToolButton.h" + +class ElaSearchEdit : public QWidget +{ + Q_OBJECT + +public: + explicit ElaSearchEdit(QWidget* parent = nullptr); + ~ElaSearchEdit() override; + + QString text() const; + void setText(const QString& text); + void setPlaceholderText(const QString& placeholderText); + void setFixedSize(const QSize& size); + void setFixedSize(int w, int h); + void setFixedHeight(int h); + + bool isExactMatch() const; + void setExactMatch(bool exact); + +signals: + void textChanged(const QString& text); + void returnPressed(); + void exactMatchChanged(bool exact); + void searchClicked(); + +private: + void initUI(); + void connectSignals(); + void resetInputMargin(); + ElaToolButton* addToolButton(QWidget* parent, ElaIconType::IconName icon, const QString& tooltip, const QSize& size, bool checkable = false, bool checked = false); + + ElaLineEdit* m_lineEdit; + ElaToolButton* m_searchBtn; + ElaToolButton* m_exactMatchBtn; + bool m_exactMatch; +}; + +#endif // ELASEARCHEDIT_H diff --git a/src/pages/functionsearch/uf20functionsearchpage.cpp b/src/pages/functionsearch/uf20functionsearchpage.cpp index 2be33b6..d332aa4 100644 --- a/src/pages/functionsearch/uf20functionsearchpage.cpp +++ b/src/pages/functionsearch/uf20functionsearchpage.cpp @@ -6,14 +6,11 @@ #include #include #include -#include #include "ElaComboBox.h" -#include "ElaLineEdit.h" -#include "ElaPushButton.h" -#include "ElaText.h" UF20FunctionSearchPage::UF20FunctionSearchPage(QWidget *parent) : QWidget(parent) + , m_exactMatch(false) { initUI(); } @@ -36,15 +33,14 @@ void UF20FunctionSearchPage::initUI() m_searchComboBox->addItem("功能编号", "function_no"); searchLayout->addWidget(m_searchComboBox); - m_searchEdit = new ElaLineEdit; + m_searchEdit = new ElaSearchEdit; m_searchEdit->setPlaceholderText("输入查询内容"); - m_searchEdit->setMinimumWidth(300); - connect(m_searchEdit, &QLineEdit::returnPressed, this, &UF20FunctionSearchPage::onSearch); - searchLayout->addWidget(m_searchEdit); + m_searchEdit->setFixedSize(330, 35); + connect(m_searchEdit, &ElaSearchEdit::returnPressed, this, &UF20FunctionSearchPage::onSearch); + connect(m_searchEdit, &ElaSearchEdit::searchClicked, this, &UF20FunctionSearchPage::onSearch); + connect(m_searchEdit, &ElaSearchEdit::exactMatchChanged, this, &UF20FunctionSearchPage::onExactMatchToggled); - ElaPushButton *searchBtn = new ElaPushButton("搜索"); - connect(searchBtn, &QPushButton::clicked, this, &UF20FunctionSearchPage::onSearch); - searchLayout->addWidget(searchBtn); + searchLayout->addWidget(m_searchEdit); searchLayout->addStretch(); layout->addLayout(searchLayout); @@ -64,13 +60,18 @@ void UF20FunctionSearchPage::initUI() layout->addWidget(m_resultTable); QHBoxLayout *tipLayout = new QHBoxLayout; - QLabel *tipLabel = new QLabel("💡 双击选中行添加转码业务"); + QLabel *tipLabel = new QLabel("💡 双击选中行添加转码业务,只支持LS功能添加"); tipLabel->setStyleSheet("color: #666; font-size: 13px;"); tipLayout->addWidget(tipLabel); tipLayout->addStretch(); layout->addLayout(tipLayout); } +void UF20FunctionSearchPage::onExactMatchToggled(bool checked) +{ + m_exactMatch = checked; +} + void UF20FunctionSearchPage::onSearch() { QString keyword = m_searchEdit->text().trimmed(); @@ -83,7 +84,7 @@ void UF20FunctionSearchPage::onSearch() } QString field = m_searchComboBox->currentData().toString(); - QList results = DataCache::instance()->searchUF20Functions(keyword, field); + QList results = DataCache::instance()->searchUF20Functions(keyword, field, m_exactMatch); if (results.isEmpty()) { QMessageBox::information(this, "提示", "未找到匹配的功能"); @@ -113,6 +114,10 @@ void UF20FunctionSearchPage::onTableDoubleClicked(const QModelIndex &index) { if (index.isValid()) { QString funcName = m_tableModel->data(m_tableModel->index(index.row(), 0)).toString(); + if (!funcName.startsWith("LS_")) { + QMessageBox::information(this, "提示", "仅支持LS功能添加转码业务"); + return; + } emit addFunctionToConvert(funcName); } } diff --git a/src/pages/functionsearch/uf20functionsearchpage.h b/src/pages/functionsearch/uf20functionsearchpage.h index e635de9..3a72ba4 100644 --- a/src/pages/functionsearch/uf20functionsearchpage.h +++ b/src/pages/functionsearch/uf20functionsearchpage.h @@ -4,8 +4,7 @@ #include #include #include "ElaComboBox.h" -#include "ElaLineEdit.h" -#include "ElaPushButton.h" +#include "components/elasearchedit.h" #include "ElaTableView.h" class UF20FunctionSearchPage : public QWidget @@ -17,19 +16,21 @@ public: ~UF20FunctionSearchPage(); signals: - void addFunctionToConvert(const QString &funcName); + void addFunctionToConvert(const QString& funcName); private slots: void onSearch(); + void onExactMatchToggled(bool checked); void onTableDoubleClicked(const QModelIndex &index); private: void initUI(); ElaComboBox *m_searchComboBox; - ElaLineEdit *m_searchEdit; + ElaSearchEdit *m_searchEdit; ElaTableView *m_resultTable; QStandardItemModel *m_tableModel; + bool m_exactMatch; }; #endif diff --git a/src/pages/functionsearch/uft3functionsearchpage.cpp b/src/pages/functionsearch/uft3functionsearchpage.cpp index 6cdb483..038fe2a 100644 --- a/src/pages/functionsearch/uft3functionsearchpage.cpp +++ b/src/pages/functionsearch/uft3functionsearchpage.cpp @@ -6,13 +6,11 @@ #include #include #include -#include #include "ElaComboBox.h" -#include "ElaLineEdit.h" -#include "ElaPushButton.h" UFT3FunctionSearchPage::UFT3FunctionSearchPage(QWidget *parent) : QWidget(parent) + , m_exactMatch(false) { initUI(); } @@ -35,15 +33,14 @@ void UFT3FunctionSearchPage::initUI() m_searchComboBox->addItem("功能编号", "function_no"); searchLayout->addWidget(m_searchComboBox); - m_searchEdit = new ElaLineEdit; + m_searchEdit = new ElaSearchEdit; m_searchEdit->setPlaceholderText("输入查询内容"); - m_searchEdit->setMinimumWidth(300); - connect(m_searchEdit, &QLineEdit::returnPressed, this, &UFT3FunctionSearchPage::onSearch); - searchLayout->addWidget(m_searchEdit); + m_searchEdit->setFixedSize(330, 35); + connect(m_searchEdit, &ElaSearchEdit::returnPressed, this, &UFT3FunctionSearchPage::onSearch); + connect(m_searchEdit, &ElaSearchEdit::searchClicked, this, &UFT3FunctionSearchPage::onSearch); + connect(m_searchEdit, &ElaSearchEdit::exactMatchChanged, this, &UFT3FunctionSearchPage::onExactMatchToggled); - ElaPushButton *searchBtn = new ElaPushButton("搜索"); - connect(searchBtn, &QPushButton::clicked, this, &UFT3FunctionSearchPage::onSearch); - searchLayout->addWidget(searchBtn); + searchLayout->addWidget(m_searchEdit); searchLayout->addStretch(); layout->addLayout(searchLayout); @@ -61,6 +58,11 @@ void UFT3FunctionSearchPage::initUI() layout->addWidget(m_resultTable); } +void UFT3FunctionSearchPage::onExactMatchToggled(bool checked) +{ + m_exactMatch = checked; +} + void UFT3FunctionSearchPage::onSearch() { QString keyword = m_searchEdit->text().trimmed(); @@ -73,7 +75,7 @@ void UFT3FunctionSearchPage::onSearch() } QString field = m_searchComboBox->currentData().toString(); - QList results = DataCache::instance()->searchUFT3Functions(keyword, field); + QList results = DataCache::instance()->searchUFT3Functions(keyword, field, m_exactMatch); if (results.isEmpty()) { QMessageBox::information(this, "提示", "未找到匹配的功能"); diff --git a/src/pages/functionsearch/uft3functionsearchpage.h b/src/pages/functionsearch/uft3functionsearchpage.h index 3513e30..caa8b87 100644 --- a/src/pages/functionsearch/uft3functionsearchpage.h +++ b/src/pages/functionsearch/uft3functionsearchpage.h @@ -4,8 +4,7 @@ #include #include #include "ElaComboBox.h" -#include "ElaLineEdit.h" -#include "ElaPushButton.h" +#include "components/elasearchedit.h" #include "ElaTableView.h" class UFT3FunctionSearchPage : public QWidget @@ -18,14 +17,16 @@ public: private slots: void onSearch(); + void onExactMatchToggled(bool checked); private: void initUI(); ElaComboBox *m_searchComboBox; - ElaLineEdit *m_searchEdit; + ElaSearchEdit *m_searchEdit; ElaTableView *m_resultTable; QStandardItemModel *m_tableModel; + bool m_exactMatch; }; #endif diff --git a/src/utils/datacache.cpp b/src/utils/datacache.cpp index 4012e32..b8e0849 100644 --- a/src/utils/datacache.cpp +++ b/src/utils/datacache.cpp @@ -306,7 +306,7 @@ QSet DataCache::getAllUF20Cnames() return result; } -QList DataCache::searchUF20Functions(const QString& keyword, const QString& field) +QList DataCache::searchUF20Functions(const QString& keyword, const QString& field, bool exactMatch) { QList result; @@ -316,32 +316,34 @@ QList DataCache::searchUF20Functions(const QString& keyword, const QSqlQuery query(m_db); QString sql; + QString keywordValue = exactMatch ? keyword : "%" + keyword + "%"; + QString op = exactMatch ? "= :keyword" : "LIKE :keyword"; if (field == "cname") { - sql = R"( + sql = QString(R"( SELECT cname, e_name, function_no FROM uf20_cname_table - WHERE cname LIKE :keyword + WHERE cname %1 ORDER BY cname - )"; + )").arg(op); } else if (field == "function_no") { - sql = R"( + sql = QString(R"( SELECT cname, e_name, function_no FROM uf20_cname_table - WHERE function_no LIKE :keyword + WHERE function_no %1 ORDER BY cname - )"; + )").arg(op); } else { - sql = R"( + sql = QString(R"( SELECT cname, e_name, function_no FROM uf20_cname_table - WHERE cname LIKE :keyword OR e_name LIKE :keyword OR function_no LIKE :keyword + WHERE cname %1 OR e_name %1 OR function_no %1 ORDER BY cname - )"; + )").arg(op); } query.prepare(sql); - query.bindValue(":keyword", "%" + keyword + "%"); + query.bindValue(":keyword", keywordValue); if (query.exec()) { while (query.next()) { @@ -395,7 +397,7 @@ QSet DataCache::getAllUFT3Cnames() return result; } -QList DataCache::searchUFT3Functions(const QString& keyword, const QString& field) +QList DataCache::searchUFT3Functions(const QString& keyword, const QString& field, bool exactMatch) { QList result; @@ -405,32 +407,34 @@ QList DataCache::searchUFT3Functions(const QString& keyword, const QSqlQuery query(m_db); QString sql; + QString keywordValue = exactMatch ? keyword : "%" + keyword + "%"; + QString op = exactMatch ? "= :keyword" : "LIKE :keyword"; if (field == "cname") { - sql = R"( + sql = QString(R"( SELECT cname, e_name, function_no FROM uft3_cname_table - WHERE cname LIKE :keyword + WHERE cname %1 ORDER BY cname - )"; + )").arg(op); } else if (field == "function_no") { - sql = R"( + sql = QString(R"( SELECT cname, e_name, function_no FROM uft3_cname_table - WHERE function_no LIKE :keyword + WHERE function_no %1 ORDER BY cname - )"; + )").arg(op); } else { - sql = R"( + sql = QString(R"( SELECT cname, e_name, function_no FROM uft3_cname_table - WHERE cname LIKE :keyword OR e_name LIKE :keyword OR function_no LIKE :keyword + WHERE cname %1 OR e_name %1 OR function_no %1 ORDER BY cname - )"; + )").arg(op); } query.prepare(sql); - query.bindValue(":keyword", "%" + keyword + "%"); + query.bindValue(":keyword", keywordValue); if (query.exec()) { while (query.next()) { diff --git a/src/utils/datacache.h b/src/utils/datacache.h index 1318568..30fd9a8 100644 --- a/src/utils/datacache.h +++ b/src/utils/datacache.h @@ -31,11 +31,11 @@ public: bool checkUF20CnameExists(const QString& cname); QSet getAllUF20Cnames(); - QList searchUF20Functions(const QString& keyword, const QString& field = ""); + QList searchUF20Functions(const QString& keyword, const QString& field = "", bool exactMatch = false); bool checkUFT3CnameExists(const QString& cname); QSet getAllUFT3Cnames(); - QList searchUFT3Functions(const QString& keyword, const QString& field = ""); + QList searchUFT3Functions(const QString& keyword, const QString& field = "", bool exactMatch = false); void clearCache();