fix(app-database-service):modify the time sequence of the transmitted signal.
This commit is contained in:
parent
ba31496a89
commit
87e6da7336
|
@ -26,15 +26,55 @@ SignalTransformer *SignalTransformer::getTransformer()
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SignalTransformer::transform()
|
||||||
|
{
|
||||||
|
switch (m_signalType) {
|
||||||
|
case Delete:
|
||||||
|
if (!m_items2BDelete.isEmpty()) {
|
||||||
|
Q_EMIT this->appDBItemsDelete(m_items2BDelete);
|
||||||
|
m_items2BDelete.clear();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Insert:
|
||||||
|
if (!m_items2BInsert.isEmpty()) {
|
||||||
|
Q_EMIT this->appDBItemsAdd(m_items2BInsert);
|
||||||
|
m_items2BInsert.clear();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case UpdateAll:
|
||||||
|
if (!m_items2BUpdateAll.isEmpty()) {
|
||||||
|
Q_EMIT this->appDBItemsUpdateAll(m_items2BUpdateAll);
|
||||||
|
m_items2BUpdateAll.clear();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Update:
|
||||||
|
if (!m_items2BUpdate.isEmpty()) {
|
||||||
|
Q_EMIT this->appDBItemsUpdate(m_items2BUpdate);
|
||||||
|
m_items2BUpdate.clear();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SignalTransformer::handleItemInsert(const QString &desktopFilePath)
|
void SignalTransformer::handleItemInsert(const QString &desktopFilePath)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&s_mutex);
|
QMutexLocker locker(&s_mutex);
|
||||||
|
if ((m_signalType ^ SignalType::Invalid) && (m_signalType ^ SignalType::Insert)) {
|
||||||
|
transform();
|
||||||
|
}
|
||||||
|
m_signalType = SignalType::Insert;
|
||||||
m_items2BInsert.append(desktopFilePath);
|
m_items2BInsert.append(desktopFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SignalTransformer::handleItemUpdate(const ApplicationInfoMap &item)
|
void SignalTransformer::handleItemUpdate(const ApplicationInfoMap &item)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&s_mutex);
|
QMutexLocker locker(&s_mutex);
|
||||||
|
if ((m_signalType ^ SignalType::Invalid) && (m_signalType ^ SignalType::Update)) {
|
||||||
|
transform();
|
||||||
|
}
|
||||||
|
m_signalType = SignalType::Update;
|
||||||
for(auto it = item.constBegin(); it != item.constEnd(); it++) {
|
for(auto it = item.constBegin(); it != item.constEnd(); it++) {
|
||||||
ApplicationPropertyMap propertyinfo = it.value();
|
ApplicationPropertyMap propertyinfo = it.value();
|
||||||
for (auto i = propertyinfo.constBegin(); i != propertyinfo.constEnd(); i++) {
|
for (auto i = propertyinfo.constBegin(); i != propertyinfo.constEnd(); i++) {
|
||||||
|
@ -46,12 +86,20 @@ void SignalTransformer::handleItemUpdate(const ApplicationInfoMap &item)
|
||||||
void SignalTransformer::handleItemUpdateAll(const QString &desktopFilePath)
|
void SignalTransformer::handleItemUpdateAll(const QString &desktopFilePath)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&s_mutex);
|
QMutexLocker locker(&s_mutex);
|
||||||
|
if ((m_signalType ^ SignalType::Invalid) && (m_signalType ^ SignalType::UpdateAll)) {
|
||||||
|
transform();
|
||||||
|
}
|
||||||
|
m_signalType = SignalType::UpdateAll;
|
||||||
m_items2BUpdateAll.append(desktopFilePath);
|
m_items2BUpdateAll.append(desktopFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SignalTransformer::handleItemDelete(const QString &desktopFilePath)
|
void SignalTransformer::handleItemDelete(const QString &desktopFilePath)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&s_mutex);
|
QMutexLocker locker(&s_mutex);
|
||||||
|
if ((m_signalType ^ SignalType::Invalid) && (m_signalType ^ SignalType::Delete)) {
|
||||||
|
transform();
|
||||||
|
}
|
||||||
|
m_signalType = SignalType::Delete;
|
||||||
m_items2BDelete.append(desktopFilePath);
|
m_items2BDelete.append(desktopFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,10 +34,16 @@ class SignalTransformer : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum SignalType{
|
||||||
|
Invalid = -1,
|
||||||
|
Delete = 0,
|
||||||
|
Insert,
|
||||||
|
UpdateAll,
|
||||||
|
Update
|
||||||
|
};
|
||||||
static SignalTransformer *getTransformer();
|
static SignalTransformer *getTransformer();
|
||||||
|
|
||||||
static QMutex s_mutex;
|
static QMutex s_mutex;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void handleItemUpdate(const ApplicationInfoMap &item);
|
void handleItemUpdate(const ApplicationInfoMap &item);
|
||||||
void handleItemUpdateAll(const QString &desktopFilePath);
|
void handleItemUpdateAll(const QString &desktopFilePath);
|
||||||
|
@ -49,11 +55,13 @@ private:
|
||||||
SignalTransformer(QObject *parent = nullptr);
|
SignalTransformer(QObject *parent = nullptr);
|
||||||
SignalTransformer(const SignalTransformer &) = delete;
|
SignalTransformer(const SignalTransformer &) = delete;
|
||||||
SignalTransformer& operator = (const SignalTransformer&) = delete;
|
SignalTransformer& operator = (const SignalTransformer&) = delete;
|
||||||
|
void transform();
|
||||||
|
|
||||||
ApplicationInfoMap m_items2BUpdate;
|
ApplicationInfoMap m_items2BUpdate;
|
||||||
QStringList m_items2BUpdateAll;
|
QStringList m_items2BUpdateAll;
|
||||||
QStringList m_items2BInsert;
|
QStringList m_items2BInsert;
|
||||||
QStringList m_items2BDelete;
|
QStringList m_items2BDelete;
|
||||||
|
SignalType m_signalType = SignalType::Invalid;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void appDBItemsUpdateAll(const QStringList&);
|
void appDBItemsUpdateAll(const QStringList&);
|
||||||
|
|
Loading…
Reference in New Issue