From 4363e1267174abe8ec84f39d2b323823371feb4f Mon Sep 17 00:00:00 2001 From: Bernardo Cunha Vieira Date: Thu, 27 Feb 2025 13:44:27 -0300 Subject: [PATCH] File DeviceFilterWidget: Correction based on https://doc.qt.io/qt-6/qcombobox.html#setView, Note: If you want to use the convenience views (like QListWidget, QTableWidget or QTreeWidget), make sure to call setModel() on the combobox with the convenience widgets model before calling this function. File RundowWidget.cpp: open on dir of the last opened file, to avoid going to the entire path again to open a file on the same directory. File RundownTreeWidget.cpp: on save as, open folder of the active Rundown or HomeDir if active == DEFAULT_NAME Files src/Core/Commands/TemplateCommand.cpp, src/Core/Commands/TemplateCommand.h: Uses QT Json library to convert to single line json. Avoids errors on new lines and other caracters that could break the update function call. --- src/Core/Commands/TemplateCommand.cpp | 11 ++++++----- src/Core/Commands/TemplateCommand.h | 2 ++ src/Widgets/Library/DeviceFilterWidget.cpp | 3 ++- src/Widgets/Rundown/RundownTreeWidget.cpp | 19 +++++++++++++------ src/Widgets/Rundown/RundownWidget.cpp | 14 +++++++++++--- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/Core/Commands/TemplateCommand.cpp b/src/Core/Commands/TemplateCommand.cpp index bf0ed1fd8..bd4954e18 100755 --- a/src/Core/Commands/TemplateCommand.cpp +++ b/src/Core/Commands/TemplateCommand.cpp @@ -54,14 +54,15 @@ const QString TemplateCommand::getTemplateData() const { if (this->sendAsJson) { - templateData.append("{"); + QJsonObject jsonObject; foreach (KeyValueModel model, this->models) { - templateData.append(QString("\\\"%1\\\":\\\"%2\\\",").arg(model.getKey()) - .arg((this->useUppercaseData == true) ? model.getValue().toUpper() : model.getValue())); + jsonObject[model.getKey()] = (this->useUppercaseData == true) ? model.getValue().toUpper() : model.getValue(); } - templateData.chop(1); - templateData.append("}"); + QJsonDocument jsonDocument(jsonObject); + QString strJson(jsonDocument.toJson(QJsonDocument::Compact)); + strJson.replace("\"", "\\\""); + templateData.append(strJson); } else { diff --git a/src/Core/Commands/TemplateCommand.h b/src/Core/Commands/TemplateCommand.h index b100baf5a..3f8a1bf1d 100755 --- a/src/Core/Commands/TemplateCommand.h +++ b/src/Core/Commands/TemplateCommand.h @@ -10,6 +10,8 @@ #include #include +#include +#include class QObject; class QXmlStreamWriter; diff --git a/src/Widgets/Library/DeviceFilterWidget.cpp b/src/Widgets/Library/DeviceFilterWidget.cpp index adc3856c4..4140170cc 100644 --- a/src/Widgets/Library/DeviceFilterWidget.cpp +++ b/src/Widgets/Library/DeviceFilterWidget.cpp @@ -25,8 +25,9 @@ DeviceFilterWidget::DeviceFilterWidget(QWidget* parent) this->listWidget.addItem(item); this->lineEditDeviceFilter->setText(item->text()); - this->comboBoxDeviceFilter->setView(&this->listWidget); this->comboBoxDeviceFilter->setModel(this->listWidget.model()); + this->comboBoxDeviceFilter->setView(&this->listWidget); + QObject::connect(&this->listWidget, SIGNAL(itemPressed(QListWidgetItem*)), this, SLOT(itemPressed(QListWidgetItem*))); QObject::connect(&DeviceManager::getInstance(), SIGNAL(deviceRemoved()), this, SLOT(deviceRemoved())); diff --git a/src/Widgets/Rundown/RundownTreeWidget.cpp b/src/Widgets/Rundown/RundownTreeWidget.cpp index 3f5623f6a..3af33fba8 100644 --- a/src/Widgets/Rundown/RundownTreeWidget.cpp +++ b/src/Widgets/Rundown/RundownTreeWidget.cpp @@ -707,17 +707,24 @@ void RundownTreeWidget::saveRundown(bool saveAs) return; QString path; - if (saveAs) - path = QFileDialog::getSaveFileName(this, "Save Rundown", QDir::homePath(), "Rundown (*.xml)"); + if (saveAs) { + if (this->activeRundown == Rundown::DEFAULT_NAME) { + path = QDir::homePath(); + } + else { + QFileInfo fi(this->activeRundown); + path = fi.absolutePath(); + } + path = QFileDialog::getSaveFileName(this, "Save Rundown", path, "Rundown (*.xml)"); + } else path = (this->activeRundown == Rundown::DEFAULT_NAME) ? QFileDialog::getSaveFileName(this, "Save Rundown", QDir::homePath(), "Rundown (*.xml)") : this->activeRundown; - // Make sure we have an extension. On *nix system it will not be appended by default. - if (!path.toLower().endsWith(".xml")) - path.append(".xml"); - if (!path.isEmpty()) { + // Make sure we have an extension. On *nix system it will not be appended by default. + if (!path.toLower().endsWith(".xml")) + path.append(".xml"); EventManager::getInstance().fireStatusbarEvent(StatusbarEvent("Saving rundown...")); QFile file(path); diff --git a/src/Widgets/Rundown/RundownWidget.cpp b/src/Widgets/Rundown/RundownWidget.cpp index e65bb34d3..0b49725fd 100644 --- a/src/Widgets/Rundown/RundownWidget.cpp +++ b/src/Widgets/Rundown/RundownWidget.cpp @@ -279,9 +279,17 @@ void RundownWidget::openRundown(const OpenRundownEvent& event) { QString path = ""; - if (event.getPath().isEmpty()) - path = QFileDialog::getOpenFileName(this, "Open Rundown", QDir::homePath(), "Rundown (*.xml)"); - else + if (event.getPath().isEmpty()){ + QList paths = DatabaseManager::getInstance().getOpenRecent(); + if(paths.count() > 0){ + path = paths.at(0); + QFileInfo fi(path); + path = fi.absolutePath(); + }else{ + path = QDir::homePath(); + } + path = QFileDialog::getOpenFileName(this, "Open Rundown", path , "Rundown (*.xml)"); + }else path = event.getPath(); if (!path.isEmpty())