добавил обновление списков в реальном времени

исправил поиск пользователя
убрал лишние qDebug
This commit is contained in:
2026-02-09 22:24:24 +03:00
parent cbb875f3f8
commit 39f0c447c1
11 changed files with 440 additions and 189 deletions
+185 -24
View File
@@ -55,8 +55,39 @@ void FSingleGrid::toGrid(QString aName, QString aFile)
void FSingleGrid::on_btnAdd_clicked()
{
toGrid(ui->edtName->text(), ui->edtFileName->text());
db->SaveTableWidget(ui->sg);
QString name = ui->edtName->text().trimmed();
QString filePath = ui->edtFileName->text().trimmed();
if (name.isEmpty()) {
QMessageBox::warning(this, "Внимание", "Введите название!");
return;
}
if (filePath.isEmpty()) {
QMessageBox::warning(this, "Внимание", "Введите путь к файлу!");
return;
}
// Добавляем в соответствующий менеджер
if (!addToManager(name, filePath)) {
QMessageBox::warning(this, "Ошибка",
currentManagerType == TemplateManager ?
"Не удалось добавить шаблон. Возможно, такое имя уже существует." :
"Не удалось добавить файл. Возможно, такое имя уже существует.");
return;
}
// Добавляем в таблицу
toGrid(name, filePath);
// Сохраняем в БД
if (db) {
db->SaveTableWidget(ui->sg);
}
// Очищаем поля
ui->edtName->clear();
ui->edtFileName->clear();
}
void FSingleGrid::setDatabase(uDataBase *database)
@@ -66,62 +97,90 @@ void FSingleGrid::setDatabase(uDataBase *database)
void FSingleGrid::on_btnDel_clicked()
{
// Проверяем, есть ли выделенная строка
if (!ui->sg->currentItem()) {
QMessageBox::warning(this, "Внимание", "Выберите строку для удаления!");
return;
}
// Получаем индекс выделенной строки
int row = ui->sg->currentItem()->row();
QString name = ui->sg->item(row, 0)->text();
// Удаляем строку
// Удаляем из менеджера
if (!removeFromManager(name)) {
QMessageBox::warning(this, "Ошибка", "Не удалось удалить из менеджера!");
return;
}
// Удаляем строку из таблицы
ui->sg->removeRow(row);
db->SaveTableWidget(ui->sg);
// Сохраняем в БД
if (db) {
db->SaveTableWidget(ui->sg);
}
}
void FSingleGrid::on_btnEdt_clicked()
{
// Проверяем, есть ли выделенная строка
if (!ui->sg->currentItem()) {
QMessageBox::warning(this, "Внимание", "Выберите строку для редактирования!");
return;
}
// Получаем индекс выделенной строки
int row = ui->sg->currentItem()->row();
QString oldName = ui->sg->item(row, 0)->text();
QString newName = ui->edtName->text().trimmed();
QString newFilePath = ui->edtFileName->text().trimmed();
// Получаем данные из выбранной строки
ui->sg->item(row, 0)->setText(ui->edtName->text());
ui->sg->item(row, 1)->setText(ui->edtFileName->text());
db->SaveTableWidget(ui->sg);
if (newName.isEmpty()) {
QMessageBox::warning(this, "Внимание", "Введите новое название!");
return;
}
if (newFilePath.isEmpty()) {
QMessageBox::warning(this, "Внимание", "Введите новый путь к файлу!");
return;
}
// Обновляем в менеджере
if (!updateInManager(oldName, newName, newFilePath)) {
QMessageBox::warning(this, "Ошибка",
currentManagerType == TemplateManager ?
"Не удалось обновить шаблон. Возможно, новое имя уже существует." :
"Не удалось обновить файл. Возможно, новое имя уже существует.");
return;
}
// Обновляем в таблице
ui->sg->item(row, 0)->setText(newName);
ui->sg->item(row, 1)->setText(newFilePath);
// Сохраняем в БД
if (db) {
db->SaveTableWidget(ui->sg);
}
}
void FSingleGrid::on_btnOpen_clicked()
{
// Диалог выбора файла
QString fileName = QFileDialog::getOpenFileName(
this, // родительское окно
"Выберите файл", // заголовок окна
QDir::homePath(), // начальная директория
"Все файлы (*.*);;" // фильтры файлов
this,
"Выберите файл",
QDir::homePath(),
"Все файлы (*.*);;"
"Текстовые файлы (*.txt);;"
"Аудио (*.mp3);;"
"Приложения (*.exe *.bat *.cmd)"
);
// Если файл выбран (не нажата кнопка "Отмена")
if (!fileName.isEmpty()) {
// Записываем путь к файлу в поле ввода
ui->edtFileName->setText(fileName);
// Опционально: автоматически заполняем поле имени из названия файла
if (ui->edtName->text().isEmpty()) {
QFileInfo fileInfo(fileName);
QString baseName = fileInfo.baseName(); // Имя файла без расширения
ui->edtName->setText(baseName);
ui->edtName->setText(fileInfo.baseName());
}
}
}
@@ -129,8 +188,110 @@ void FSingleGrid::on_btnOpen_clicked()
void FSingleGrid::on_sg_cellClicked(int row, int column)
{
ui->edtName->setText(ui->sg->item(row,0)->text());
ui->edtFileName->setText(ui->sg->item(row,1)->text());
Q_UNUSED(column);
if (row >= 0 && row < ui->sg->rowCount()) {
ui->edtName->setText(ui->sg->item(row, 0)->text());
ui->edtFileName->setText(ui->sg->item(row, 1)->text());
}
}
void FSingleGrid::setSoundManager(MediaFileManager *manager)
{
soundManager = manager;
currentManagerType = SoundManager;
}
void FSingleGrid::setTextManager(MediaFileManager *manager)
{
textManager = manager;
currentManagerType = TextManager;
}
void FSingleGrid::setTemplateManager(NeuralTemplateManager *manager)
{
templateManager = manager;
currentManagerType = TemplateManager;
}
void FSingleGrid::setManagerType(ManagerType type)
{
currentManagerType = type;
}
bool FSingleGrid::addToManager(const QString& name, const QString& filePath)
{
switch (currentManagerType) {
case SoundManager:
if (soundManager) {
qDebug() << "добавляем ебаный звук";
return soundManager->addFile(name, filePath);
}
break;
case TextManager:
if (textManager) {
qDebug() << "добавляем ебаный текст";
return textManager->addFile(name, filePath);
}
break;
case TemplateManager:
if (templateManager) {
qDebug() << "добавляем ебаный шаблон";
return templateManager->addTemplate(name, filePath);
}
break;
default:
qDebug() << "добавляем ебаный нихуя";
break;
}
return false;
}
bool FSingleGrid::removeFromManager(const QString& name)
{
switch (currentManagerType) {
case SoundManager:
if (soundManager) {
return soundManager->removeFile(name);
}
break;
case TextManager:
if (textManager) {
return textManager->removeFile(name);
}
break;
case TemplateManager:
if (templateManager) {
return templateManager->removeTemplate(name);
}
break;
default:
break;
}
return false;
}
bool FSingleGrid::updateInManager(const QString& oldName, const QString& newName, const QString& newFilePath)
{
switch (currentManagerType) {
case SoundManager:
if (soundManager) {
return soundManager->updateFile(oldName, newName, newFilePath);
}
break;
case TextManager:
if (textManager) {
return textManager->updateFile(oldName, newName, newFilePath);
}
break;
case TemplateManager:
if (templateManager) {
return templateManager->updateTemplate(oldName, newName, newFilePath);
}
break;
default:
break;
}
return false;
}