新增自定义控件,修复查询添加问题

This commit is contained in:
taocong 2026-06-01 19:32:23 +08:00
parent fad539e127
commit cc7fc51399
9 changed files with 232 additions and 55 deletions

View File

@ -13,6 +13,7 @@ SOURCES += main.cpp \
src/pages/functionsearch/functionsearchpage.cpp \ src/pages/functionsearch/functionsearchpage.cpp \
src/pages/functionsearch/uf20functionsearchpage.cpp \ src/pages/functionsearch/uf20functionsearchpage.cpp \
src/pages/functionsearch/uft3functionsearchpage.cpp \ src/pages/functionsearch/uft3functionsearchpage.cpp \
src/components/elasearchedit.cpp \
src/pages/help/helppage.cpp \ src/pages/help/helppage.cpp \
src/pages/settings/settingspage.cpp \ src/pages/settings/settingspage.cpp \
src/pages/metadatupdate/metadatupdatepage.cpp \ src/pages/metadatupdate/metadatupdatepage.cpp \
@ -39,6 +40,7 @@ HEADERS += src/mainwindow/mainwindow.h \
src/pages/functionsearch/functionsearchpage.h \ src/pages/functionsearch/functionsearchpage.h \
src/pages/functionsearch/uf20functionsearchpage.h \ src/pages/functionsearch/uf20functionsearchpage.h \
src/pages/functionsearch/uft3functionsearchpage.h \ src/pages/functionsearch/uft3functionsearchpage.h \
src/components/elasearchedit.h \
src/pages/help/helppage.h \ src/pages/help/helppage.h \
src/pages/settings/settingspage.h \ src/pages/settings/settingspage.h \
src/pages/metadatupdate/metadatupdatepage.h \ src/pages/metadatupdate/metadatupdatepage.h \

View File

@ -0,0 +1,116 @@
#include "elasearchedit.h"
#include <QHBoxLayout>
#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);
}

View File

@ -0,0 +1,46 @@
#ifndef ELASEARCHEDIT_H
#define ELASEARCHEDIT_H
#include <QWidget>
#include <QHBoxLayout>
#include <QList>
#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

View File

@ -6,14 +6,11 @@
#include <QHeaderView> #include <QHeaderView>
#include <QMessageBox> #include <QMessageBox>
#include <QStandardItem> #include <QStandardItem>
#include <QLineEdit>
#include "ElaComboBox.h" #include "ElaComboBox.h"
#include "ElaLineEdit.h"
#include "ElaPushButton.h"
#include "ElaText.h"
UF20FunctionSearchPage::UF20FunctionSearchPage(QWidget *parent) UF20FunctionSearchPage::UF20FunctionSearchPage(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, m_exactMatch(false)
{ {
initUI(); initUI();
} }
@ -36,15 +33,14 @@ void UF20FunctionSearchPage::initUI()
m_searchComboBox->addItem("功能编号", "function_no"); m_searchComboBox->addItem("功能编号", "function_no");
searchLayout->addWidget(m_searchComboBox); searchLayout->addWidget(m_searchComboBox);
m_searchEdit = new ElaLineEdit; m_searchEdit = new ElaSearchEdit;
m_searchEdit->setPlaceholderText("输入查询内容"); m_searchEdit->setPlaceholderText("输入查询内容");
m_searchEdit->setMinimumWidth(300); m_searchEdit->setFixedSize(330, 35);
connect(m_searchEdit, &QLineEdit::returnPressed, this, &UF20FunctionSearchPage::onSearch); connect(m_searchEdit, &ElaSearchEdit::returnPressed, this, &UF20FunctionSearchPage::onSearch);
searchLayout->addWidget(m_searchEdit); connect(m_searchEdit, &ElaSearchEdit::searchClicked, this, &UF20FunctionSearchPage::onSearch);
connect(m_searchEdit, &ElaSearchEdit::exactMatchChanged, this, &UF20FunctionSearchPage::onExactMatchToggled);
ElaPushButton *searchBtn = new ElaPushButton("搜索"); searchLayout->addWidget(m_searchEdit);
connect(searchBtn, &QPushButton::clicked, this, &UF20FunctionSearchPage::onSearch);
searchLayout->addWidget(searchBtn);
searchLayout->addStretch(); searchLayout->addStretch();
layout->addLayout(searchLayout); layout->addLayout(searchLayout);
@ -64,13 +60,18 @@ void UF20FunctionSearchPage::initUI()
layout->addWidget(m_resultTable); layout->addWidget(m_resultTable);
QHBoxLayout *tipLayout = new QHBoxLayout; QHBoxLayout *tipLayout = new QHBoxLayout;
QLabel *tipLabel = new QLabel("💡 双击选中行添加转码业务"); QLabel *tipLabel = new QLabel("💡 双击选中行添加转码业务,只支持LS功能添加");
tipLabel->setStyleSheet("color: #666; font-size: 13px;"); tipLabel->setStyleSheet("color: #666; font-size: 13px;");
tipLayout->addWidget(tipLabel); tipLayout->addWidget(tipLabel);
tipLayout->addStretch(); tipLayout->addStretch();
layout->addLayout(tipLayout); layout->addLayout(tipLayout);
} }
void UF20FunctionSearchPage::onExactMatchToggled(bool checked)
{
m_exactMatch = checked;
}
void UF20FunctionSearchPage::onSearch() void UF20FunctionSearchPage::onSearch()
{ {
QString keyword = m_searchEdit->text().trimmed(); QString keyword = m_searchEdit->text().trimmed();
@ -83,7 +84,7 @@ void UF20FunctionSearchPage::onSearch()
} }
QString field = m_searchComboBox->currentData().toString(); QString field = m_searchComboBox->currentData().toString();
QList<FunctionInfo> results = DataCache::instance()->searchUF20Functions(keyword, field); QList<FunctionInfo> results = DataCache::instance()->searchUF20Functions(keyword, field, m_exactMatch);
if (results.isEmpty()) { if (results.isEmpty()) {
QMessageBox::information(this, "提示", "未找到匹配的功能"); QMessageBox::information(this, "提示", "未找到匹配的功能");
@ -113,6 +114,10 @@ void UF20FunctionSearchPage::onTableDoubleClicked(const QModelIndex &index)
{ {
if (index.isValid()) { if (index.isValid()) {
QString funcName = m_tableModel->data(m_tableModel->index(index.row(), 0)).toString(); QString funcName = m_tableModel->data(m_tableModel->index(index.row(), 0)).toString();
if (!funcName.startsWith("LS_")) {
QMessageBox::information(this, "提示", "仅支持LS功能添加转码业务");
return;
}
emit addFunctionToConvert(funcName); emit addFunctionToConvert(funcName);
} }
} }

View File

@ -4,8 +4,7 @@
#include <QWidget> #include <QWidget>
#include <QStandardItemModel> #include <QStandardItemModel>
#include "ElaComboBox.h" #include "ElaComboBox.h"
#include "ElaLineEdit.h" #include "components/elasearchedit.h"
#include "ElaPushButton.h"
#include "ElaTableView.h" #include "ElaTableView.h"
class UF20FunctionSearchPage : public QWidget class UF20FunctionSearchPage : public QWidget
@ -17,19 +16,21 @@ public:
~UF20FunctionSearchPage(); ~UF20FunctionSearchPage();
signals: signals:
void addFunctionToConvert(const QString &funcName); void addFunctionToConvert(const QString& funcName);
private slots: private slots:
void onSearch(); void onSearch();
void onExactMatchToggled(bool checked);
void onTableDoubleClicked(const QModelIndex &index); void onTableDoubleClicked(const QModelIndex &index);
private: private:
void initUI(); void initUI();
ElaComboBox *m_searchComboBox; ElaComboBox *m_searchComboBox;
ElaLineEdit *m_searchEdit; ElaSearchEdit *m_searchEdit;
ElaTableView *m_resultTable; ElaTableView *m_resultTable;
QStandardItemModel *m_tableModel; QStandardItemModel *m_tableModel;
bool m_exactMatch;
}; };
#endif #endif

View File

@ -6,13 +6,11 @@
#include <QHeaderView> #include <QHeaderView>
#include <QMessageBox> #include <QMessageBox>
#include <QStandardItem> #include <QStandardItem>
#include <QLineEdit>
#include "ElaComboBox.h" #include "ElaComboBox.h"
#include "ElaLineEdit.h"
#include "ElaPushButton.h"
UFT3FunctionSearchPage::UFT3FunctionSearchPage(QWidget *parent) UFT3FunctionSearchPage::UFT3FunctionSearchPage(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, m_exactMatch(false)
{ {
initUI(); initUI();
} }
@ -35,15 +33,14 @@ void UFT3FunctionSearchPage::initUI()
m_searchComboBox->addItem("功能编号", "function_no"); m_searchComboBox->addItem("功能编号", "function_no");
searchLayout->addWidget(m_searchComboBox); searchLayout->addWidget(m_searchComboBox);
m_searchEdit = new ElaLineEdit; m_searchEdit = new ElaSearchEdit;
m_searchEdit->setPlaceholderText("输入查询内容"); m_searchEdit->setPlaceholderText("输入查询内容");
m_searchEdit->setMinimumWidth(300); m_searchEdit->setFixedSize(330, 35);
connect(m_searchEdit, &QLineEdit::returnPressed, this, &UFT3FunctionSearchPage::onSearch); connect(m_searchEdit, &ElaSearchEdit::returnPressed, this, &UFT3FunctionSearchPage::onSearch);
searchLayout->addWidget(m_searchEdit); connect(m_searchEdit, &ElaSearchEdit::searchClicked, this, &UFT3FunctionSearchPage::onSearch);
connect(m_searchEdit, &ElaSearchEdit::exactMatchChanged, this, &UFT3FunctionSearchPage::onExactMatchToggled);
ElaPushButton *searchBtn = new ElaPushButton("搜索"); searchLayout->addWidget(m_searchEdit);
connect(searchBtn, &QPushButton::clicked, this, &UFT3FunctionSearchPage::onSearch);
searchLayout->addWidget(searchBtn);
searchLayout->addStretch(); searchLayout->addStretch();
layout->addLayout(searchLayout); layout->addLayout(searchLayout);
@ -61,6 +58,11 @@ void UFT3FunctionSearchPage::initUI()
layout->addWidget(m_resultTable); layout->addWidget(m_resultTable);
} }
void UFT3FunctionSearchPage::onExactMatchToggled(bool checked)
{
m_exactMatch = checked;
}
void UFT3FunctionSearchPage::onSearch() void UFT3FunctionSearchPage::onSearch()
{ {
QString keyword = m_searchEdit->text().trimmed(); QString keyword = m_searchEdit->text().trimmed();
@ -73,7 +75,7 @@ void UFT3FunctionSearchPage::onSearch()
} }
QString field = m_searchComboBox->currentData().toString(); QString field = m_searchComboBox->currentData().toString();
QList<FunctionInfo> results = DataCache::instance()->searchUFT3Functions(keyword, field); QList<FunctionInfo> results = DataCache::instance()->searchUFT3Functions(keyword, field, m_exactMatch);
if (results.isEmpty()) { if (results.isEmpty()) {
QMessageBox::information(this, "提示", "未找到匹配的功能"); QMessageBox::information(this, "提示", "未找到匹配的功能");

View File

@ -4,8 +4,7 @@
#include <QWidget> #include <QWidget>
#include <QStandardItemModel> #include <QStandardItemModel>
#include "ElaComboBox.h" #include "ElaComboBox.h"
#include "ElaLineEdit.h" #include "components/elasearchedit.h"
#include "ElaPushButton.h"
#include "ElaTableView.h" #include "ElaTableView.h"
class UFT3FunctionSearchPage : public QWidget class UFT3FunctionSearchPage : public QWidget
@ -18,14 +17,16 @@ public:
private slots: private slots:
void onSearch(); void onSearch();
void onExactMatchToggled(bool checked);
private: private:
void initUI(); void initUI();
ElaComboBox *m_searchComboBox; ElaComboBox *m_searchComboBox;
ElaLineEdit *m_searchEdit; ElaSearchEdit *m_searchEdit;
ElaTableView *m_resultTable; ElaTableView *m_resultTable;
QStandardItemModel *m_tableModel; QStandardItemModel *m_tableModel;
bool m_exactMatch;
}; };
#endif #endif

View File

@ -306,7 +306,7 @@ QSet<QString> DataCache::getAllUF20Cnames()
return result; return result;
} }
QList<FunctionInfo> DataCache::searchUF20Functions(const QString& keyword, const QString& field) QList<FunctionInfo> DataCache::searchUF20Functions(const QString& keyword, const QString& field, bool exactMatch)
{ {
QList<FunctionInfo> result; QList<FunctionInfo> result;
@ -316,32 +316,34 @@ QList<FunctionInfo> DataCache::searchUF20Functions(const QString& keyword, const
QSqlQuery query(m_db); QSqlQuery query(m_db);
QString sql; QString sql;
QString keywordValue = exactMatch ? keyword : "%" + keyword + "%";
QString op = exactMatch ? "= :keyword" : "LIKE :keyword";
if (field == "cname") { if (field == "cname") {
sql = R"( sql = QString(R"(
SELECT cname, e_name, function_no SELECT cname, e_name, function_no
FROM uf20_cname_table FROM uf20_cname_table
WHERE cname LIKE :keyword WHERE cname %1
ORDER BY cname ORDER BY cname
)"; )").arg(op);
} else if (field == "function_no") { } else if (field == "function_no") {
sql = R"( sql = QString(R"(
SELECT cname, e_name, function_no SELECT cname, e_name, function_no
FROM uf20_cname_table FROM uf20_cname_table
WHERE function_no LIKE :keyword WHERE function_no %1
ORDER BY cname ORDER BY cname
)"; )").arg(op);
} else { } else {
sql = R"( sql = QString(R"(
SELECT cname, e_name, function_no SELECT cname, e_name, function_no
FROM uf20_cname_table 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 ORDER BY cname
)"; )").arg(op);
} }
query.prepare(sql); query.prepare(sql);
query.bindValue(":keyword", "%" + keyword + "%"); query.bindValue(":keyword", keywordValue);
if (query.exec()) { if (query.exec()) {
while (query.next()) { while (query.next()) {
@ -395,7 +397,7 @@ QSet<QString> DataCache::getAllUFT3Cnames()
return result; return result;
} }
QList<FunctionInfo> DataCache::searchUFT3Functions(const QString& keyword, const QString& field) QList<FunctionInfo> DataCache::searchUFT3Functions(const QString& keyword, const QString& field, bool exactMatch)
{ {
QList<FunctionInfo> result; QList<FunctionInfo> result;
@ -405,32 +407,34 @@ QList<FunctionInfo> DataCache::searchUFT3Functions(const QString& keyword, const
QSqlQuery query(m_db); QSqlQuery query(m_db);
QString sql; QString sql;
QString keywordValue = exactMatch ? keyword : "%" + keyword + "%";
QString op = exactMatch ? "= :keyword" : "LIKE :keyword";
if (field == "cname") { if (field == "cname") {
sql = R"( sql = QString(R"(
SELECT cname, e_name, function_no SELECT cname, e_name, function_no
FROM uft3_cname_table FROM uft3_cname_table
WHERE cname LIKE :keyword WHERE cname %1
ORDER BY cname ORDER BY cname
)"; )").arg(op);
} else if (field == "function_no") { } else if (field == "function_no") {
sql = R"( sql = QString(R"(
SELECT cname, e_name, function_no SELECT cname, e_name, function_no
FROM uft3_cname_table FROM uft3_cname_table
WHERE function_no LIKE :keyword WHERE function_no %1
ORDER BY cname ORDER BY cname
)"; )").arg(op);
} else { } else {
sql = R"( sql = QString(R"(
SELECT cname, e_name, function_no SELECT cname, e_name, function_no
FROM uft3_cname_table 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 ORDER BY cname
)"; )").arg(op);
} }
query.prepare(sql); query.prepare(sql);
query.bindValue(":keyword", "%" + keyword + "%"); query.bindValue(":keyword", keywordValue);
if (query.exec()) { if (query.exec()) {
while (query.next()) { while (query.next()) {

View File

@ -31,11 +31,11 @@ public:
bool checkUF20CnameExists(const QString& cname); bool checkUF20CnameExists(const QString& cname);
QSet<QString> getAllUF20Cnames(); QSet<QString> getAllUF20Cnames();
QList<FunctionInfo> searchUF20Functions(const QString& keyword, const QString& field = ""); QList<FunctionInfo> searchUF20Functions(const QString& keyword, const QString& field = "", bool exactMatch = false);
bool checkUFT3CnameExists(const QString& cname); bool checkUFT3CnameExists(const QString& cname);
QSet<QString> getAllUFT3Cnames(); QSet<QString> getAllUFT3Cnames();
QList<FunctionInfo> searchUFT3Functions(const QString& keyword, const QString& field = ""); QList<FunctionInfo> searchUFT3Functions(const QString& keyword, const QString& field = "", bool exactMatch = false);
void clearCache(); void clearCache();