Call: Use signal slots uniformly for calling.

This commit is contained in:
2025-06-19 15:37:39 +08:00
parent b2aa0d3752
commit 5f5569495e
14 changed files with 121 additions and 102 deletions

View File

@@ -1,13 +1,17 @@
#include "LocalFile.h"
#include "LocalFile.h"
#include <QDateTime>
#include <QDir>
#include <QFileInfo>
LocalFile::LocalFile(QObject* parent) : DirFileHelper(parent)
{
}
bool LocalFile::GetHome()
{
auto home = Util::GetUserHome();
pathCall_(home);
emit sigHome(home);
return true;
}
@@ -17,7 +21,7 @@ bool LocalFile::GetDirFile(const QString& dir)
if (!GetDirFile(dir, vec)) {
return false;
}
fileCall_(vec);
emit sigDirFile(vec);
return true;
}

View File

@@ -1,4 +1,4 @@
#ifndef LOCALFILE_H
#ifndef LOCALFILE_H
#define LOCALFILE_H
#include <InfoDirFile.h>
@@ -8,7 +8,7 @@
class LocalFile : public DirFileHelper
{
public:
LocalFile() = default;
LocalFile(QObject* parent = nullptr);
~LocalFile() override = default;
public:

View File

@@ -109,12 +109,7 @@ QString DirFileHelper::GetErr() const
return QString();
}
void DirFileHelper::registerPathCall(const std::function<void(const QString& path)>& call)
DirFileHelper::DirFileHelper(QObject* parent) : QObject(parent)
{
pathCall_ = call;
}
void DirFileHelper::registerFileCall(const std::function<void(const DirFileInfoVec& vec)>& call)
{
fileCall_ = call;
}
}

View File

@@ -22,18 +22,18 @@ class DirFileHelper : public QObject
{
Q_OBJECT
public:
DirFileHelper() = default;
DirFileHelper(QObject* parent = nullptr);
virtual ~DirFileHelper() = default;
public:
QString GetErr() const;
void registerPathCall(const std::function<void(const QString& path)>& call);
void registerFileCall(const std::function<void(const DirFileInfoVec& vec)>& call);
signals:
void sigHome(const QString& path);
void sigDirFile(const DirFileInfoVec& dirFile);
protected:
QString err_;
std::function<void(const QString& path)> pathCall_;
std::function<void(const DirFileInfoVec& info)> fileCall_;
public:
virtual bool GetHome() = 0;