mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-10-04 09:32:21 +08:00
update:完善搜索功能
This commit is contained in:
parent
a79d76067e
commit
266be7146d
@ -60,6 +60,11 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
});
|
});
|
||||||
|
|
||||||
checkUpdates();
|
checkUpdates();
|
||||||
|
// 新增:监听搜索框文本变化
|
||||||
|
connect(ui->searchPlainTextEdit, &QPlainTextEdit::textChanged, this, [=]() {
|
||||||
|
QString keyword = ui->searchPlainTextEdit->toPlainText();
|
||||||
|
filterAppsByKeyword(keyword);
|
||||||
|
});
|
||||||
initStyle();
|
initStyle();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -196,6 +201,7 @@ void MainWindow::checkUpdates()
|
|||||||
{
|
{
|
||||||
aptssUpdater updater;
|
aptssUpdater updater;
|
||||||
QJsonArray updateInfo = updater.getUpdateInfoAsJson();
|
QJsonArray updateInfo = updater.getUpdateInfoAsJson();
|
||||||
|
m_allApps = updateInfo; // 保存所有应用数据
|
||||||
m_model->setUpdateData(updateInfo);
|
m_model->setUpdateData(updateInfo);
|
||||||
|
|
||||||
for (const auto &item : updateInfo) {
|
for (const auto &item : updateInfo) {
|
||||||
@ -205,6 +211,27 @@ void MainWindow::checkUpdates()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 新增:根据关键字过滤应用
|
||||||
|
void MainWindow::filterAppsByKeyword(const QString &keyword)
|
||||||
|
{
|
||||||
|
if (keyword.trimmed().isEmpty()) {
|
||||||
|
m_model->setUpdateData(m_allApps);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QJsonArray filtered;
|
||||||
|
for (const auto &item : m_allApps) {
|
||||||
|
QJsonObject obj = item.toObject();
|
||||||
|
// 可根据需要匹配更多字段
|
||||||
|
QString name = obj.value("name").toString();
|
||||||
|
QString package = obj.value("package").toString();
|
||||||
|
if (name.contains(keyword, Qt::CaseInsensitive) ||
|
||||||
|
package.contains(keyword, Qt::CaseInsensitive)) {
|
||||||
|
filtered.append(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_model->setUpdateData(filtered);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::runAptssUpgrade()
|
void MainWindow::runAptssUpgrade()
|
||||||
{
|
{
|
||||||
QProcess process;
|
QProcess process;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "applistmodel.h"
|
#include "applistmodel.h"
|
||||||
#include "appdelegate.h"
|
#include "appdelegate.h"
|
||||||
#include <QListView>
|
#include <QListView>
|
||||||
|
#include <QJsonArray> // 添加头文件
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
@ -29,5 +30,7 @@ private:
|
|||||||
AppListModel *m_model;
|
AppListModel *m_model;
|
||||||
AppDelegate *m_delegate;
|
AppDelegate *m_delegate;
|
||||||
QListView *listView; // 声明 QListView 指针
|
QListView *listView; // 声明 QListView 指针
|
||||||
|
QJsonArray m_allApps; // 新增:保存所有应用数据
|
||||||
|
void filterAppsByKeyword(const QString &keyword); // 新增:搜索过滤函数声明
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user