добавил создание, хранение, удаление действий
This commit is contained in:
+169
@@ -452,7 +452,22 @@ void uGeneral::initializeManagers()
|
||||
m_commandProcessor->setContext(context);
|
||||
}
|
||||
|
||||
m_actionManager = new ActionManager(db, this);
|
||||
// Настройка таблицы sgActions
|
||||
ui->sgActions->setColumnCount(2);
|
||||
ui->sgActions->setHorizontalHeaderLabels({"Тип", "Параметры"});
|
||||
ui->sgActions->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
ui->sgActions->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
ui->sgActions->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
ui->sgActions->horizontalHeader()->setStretchLastSection(true);
|
||||
ui->sgActions->setColumnWidth(0, 120);
|
||||
connect(m_actionManager, &ActionManager::dataChanged, this, &uGeneral::updateActionsTable);
|
||||
// Устанавливаем фильтр событий для поля ввода комбинации клавиш
|
||||
ui->edtKeyLine->installEventFilter(this);
|
||||
|
||||
// Загружаем действия из БД
|
||||
m_actionManager->loadFromDatabase();
|
||||
updateActionsTable();
|
||||
}
|
||||
|
||||
|
||||
@@ -3550,3 +3565,157 @@ void uGeneral::on_btnActionAudioOpen_clicked()
|
||||
|
||||
}
|
||||
|
||||
bool uGeneral::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (obj == ui->edtKeyLine && event->type() == QEvent::KeyPress) {
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
|
||||
int key = keyEvent->key();
|
||||
Qt::KeyboardModifiers mods = keyEvent->modifiers();
|
||||
|
||||
// Игнорируем одиночные модификаторы
|
||||
if (key == Qt::Key_Control || key == Qt::Key_Shift || key == Qt::Key_Alt || key == Qt::Key_Meta) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Обработка Backspace – очистка поля
|
||||
if (key == Qt::Key_Backspace) {
|
||||
ui->edtKeyLine->clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Формируем строку комбинации
|
||||
QString sequence = QKeySequence(mods + key).toString();
|
||||
ui->edtKeyLine->setText(sequence);
|
||||
return true; // событие обработано, дальше не передаём
|
||||
}
|
||||
return QMainWindow::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
|
||||
void uGeneral::on_btnAddAction_clicked()
|
||||
{
|
||||
ActionData action;
|
||||
action.type = ui->cbActions->currentIndex();
|
||||
|
||||
// Заполняем данные в зависимости от типа
|
||||
switch (action.type) {
|
||||
case 0: // клавиши
|
||||
action.keyCombination = ui->edtKeyLine->text();
|
||||
break;
|
||||
case 1: // звук
|
||||
action.audioFile = ui->edtActionAudio->text();
|
||||
break;
|
||||
case 2: // уведомление
|
||||
action.notificationTitle = ui->lineEdit_3->text();
|
||||
action.notificationDescription = ui->lineEdit_4->text();
|
||||
action.notificationImage = ui->edtActionPic->text();
|
||||
action.notificationSound = ui->edtActionSound->text();
|
||||
break;
|
||||
}
|
||||
|
||||
// Валидация (минимальная)
|
||||
if (action.type == 0 && action.keyCombination.isEmpty()) {
|
||||
QMessageBox::warning(this, "Ошибка", "Введите комбинацию клавиш");
|
||||
return;
|
||||
}
|
||||
if (action.type == 1 && action.audioFile.isEmpty()) {
|
||||
QMessageBox::warning(this, "Ошибка", "Выберите аудиофайл");
|
||||
return;
|
||||
}
|
||||
if (action.type == 2 && action.notificationTitle.isEmpty()) {
|
||||
QMessageBox::warning(this, "Ошибка", "Введите заголовок уведомления");
|
||||
return;
|
||||
}
|
||||
|
||||
m_actionManager->addAction(action);
|
||||
|
||||
}
|
||||
|
||||
void uGeneral::on_btnDelAction_clicked()
|
||||
{
|
||||
int row = ui->sgActions->currentRow();
|
||||
if (row < 0) {
|
||||
QMessageBox::warning(this, "Ошибка", "Выберите действие для удаления");
|
||||
return;
|
||||
}
|
||||
|
||||
int id = ui->sgActions->item(row, 0)->data(Qt::UserRole).toInt();
|
||||
if (QMessageBox::question(this, "Подтверждение", "Удалить выбранное действие?") == QMessageBox::Yes) {
|
||||
m_actionManager->deleteAction(id);
|
||||
if (m_currentActionId == id) {
|
||||
m_currentActionId = -1;
|
||||
clearActionInputs();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void uGeneral::on_sgActions_cellClicked(int row, int column)
|
||||
{
|
||||
Q_UNUSED(column);
|
||||
int id = ui->sgActions->item(row, 0)->data(Qt::UserRole).toInt();
|
||||
auto actions = m_actionManager->getAllActions();
|
||||
for (const ActionData &a : actions) {
|
||||
if (a.id == id) {
|
||||
m_currentActionId = id;
|
||||
// Устанавливаем тип в комбобокс
|
||||
ui->cbActions->setCurrentIndex(a.type);
|
||||
// Заполняем поля
|
||||
ui->edtKeyLine->setText(a.keyCombination);
|
||||
ui->edtActionAudio->setText(a.audioFile);
|
||||
ui->lineEdit_3->setText(a.notificationTitle);
|
||||
ui->lineEdit_4->setText(a.notificationDescription);
|
||||
ui->edtActionPic->setText(a.notificationImage);
|
||||
ui->edtActionSound->setText(a.notificationSound);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void uGeneral::on_sgActions_cellDoubleClicked(int row, int column)
|
||||
{
|
||||
// Можно сделать то же, что и при клике, либо открыть расширенное редактирование
|
||||
on_sgActions_cellClicked(row, column);
|
||||
}
|
||||
|
||||
void uGeneral::updateActionsTable()
|
||||
{
|
||||
ui->sgActions->setRowCount(0);
|
||||
auto actions = m_actionManager->getAllActions();
|
||||
|
||||
for (const ActionData &a : actions) {
|
||||
int row = ui->sgActions->rowCount();
|
||||
ui->sgActions->insertRow(row);
|
||||
|
||||
QString typeStr;
|
||||
QString paramStr;
|
||||
switch (a.type) {
|
||||
case 0:
|
||||
typeStr = "Нажатие";
|
||||
paramStr = a.keyCombination;
|
||||
break;
|
||||
case 1:
|
||||
typeStr = "Звук";
|
||||
paramStr = QFileInfo(a.audioFile).fileName();
|
||||
break;
|
||||
case 2:
|
||||
typeStr = "Уведомление";
|
||||
paramStr = a.notificationTitle;
|
||||
break;
|
||||
}
|
||||
|
||||
QTableWidgetItem *typeItem = new QTableWidgetItem(typeStr);
|
||||
typeItem->setData(Qt::UserRole, a.id);
|
||||
ui->sgActions->setItem(row, 0, typeItem);
|
||||
ui->sgActions->setItem(row, 1, new QTableWidgetItem(paramStr));
|
||||
}
|
||||
}
|
||||
|
||||
void uGeneral::clearActionInputs()
|
||||
{
|
||||
ui->edtKeyLine->clear();
|
||||
ui->edtActionAudio->clear();
|
||||
ui->lineEdit_3->clear();
|
||||
ui->lineEdit_4->clear();
|
||||
ui->edtActionPic->clear();
|
||||
ui->edtActionSound->clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user