добавил создание, хранение, удаление действий
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
#include "actionmanager.h"
|
||||
|
||||
ActionManager::ActionManager(uDataBase *db, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_db(db)
|
||||
{
|
||||
}
|
||||
|
||||
bool ActionManager::addAction(const ActionData &action)
|
||||
{
|
||||
if (!m_db) return false;
|
||||
if (!m_db->saveAction(action)) return false;
|
||||
|
||||
// Перезагрузим все действия, чтобы получить свежий ID
|
||||
loadFromDatabase();
|
||||
emit dataChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ActionManager::updateAction(int id, const ActionData &action)
|
||||
{
|
||||
if (!m_db) return false;
|
||||
if (!m_db->updateAction(id, action)) return false;
|
||||
|
||||
for (int i = 0; i < m_actions.size(); ++i) {
|
||||
if (m_actions[i].id == id) {
|
||||
m_actions[i] = action;
|
||||
m_actions[i].id = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
emit dataChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ActionManager::deleteAction(int id)
|
||||
{
|
||||
if (!m_db) return false;
|
||||
if (!m_db->deleteAction(id)) return false;
|
||||
|
||||
for (int i = 0; i < m_actions.size(); ++i) {
|
||||
if (m_actions[i].id == id) {
|
||||
m_actions.removeAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
emit dataChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
QList<ActionData> ActionManager::getAllActions() const
|
||||
{
|
||||
return m_actions;
|
||||
}
|
||||
|
||||
bool ActionManager::loadFromDatabase()
|
||||
{
|
||||
if (!m_db) return false;
|
||||
m_actions = m_db->loadAllActions();
|
||||
emit dataChanged();
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user