Correctly update profile widget when a profile was changed/deleted

parent 8eef9e38
......@@ -37,6 +37,7 @@ ProfilesDialog::ProfilesDialog(const QString &profileDescription, QWidget *paren
: QDialog(parent)
, m_profileIsModified(false)
, m_isCustomProfile(false)
, m_profilesChanged(false)
{
// ask profile repository for a refresh
......@@ -94,6 +95,7 @@ ProfilesDialog::ProfilesDialog(const QString &profilePath, bool, QWidget *parent
, m_profileIsModified(false)
, m_isCustomProfile(true)
, m_customProfilePath(profilePath)
, m_profilesChanged(false)
{
m_view.setupUi(this);
......@@ -281,6 +283,7 @@ bool ProfilesDialog::slotSaveProfile()
m_profileIsModified = false;
fillList(profileDesc);
m_view.button_create->setEnabled(true);
m_profilesChanged = true;
return true;
}
......@@ -306,6 +309,7 @@ void ProfilesDialog::slotDeleteProfile()
const QString path = m_view.profiles_list->itemData(m_view.profiles_list->currentIndex()).toString();
bool success = ProfileRepository::get()->deleteProfile(path);
if (success) {
m_profilesChanged = true;
fillList();
}
}
......@@ -355,3 +359,8 @@ void ProfilesDialog::slotUpdateDisplay(QString currentProfile)
}
m_profileIsModified = false;
}
bool ProfilesDialog::profileTreeChanged() const
{
return m_profilesChanged;
}
......@@ -35,6 +35,7 @@ public:
/** @brief Using this constructor, the dialog only allows editing one profile. */
explicit ProfilesDialog(const QString &profilePath, bool, QWidget *parent = nullptr);
void fillList(const QString &selectedProfile = QString());
bool profileTreeChanged() const;
protected:
void closeEvent(QCloseEvent *event) override;
......@@ -58,6 +59,8 @@ private:
bool m_isCustomProfile;
/** @brief If we are in single profile editing, should contain the path for this profile. */
QString m_customProfilePath;
/** @brief True if a profile was saved / deleted and profile tree requires a reload. */
bool m_profilesChanged;
KMessageWidget *m_infoMessage;
void saveProfile(const QString &path);
bool askForSave();
......
......@@ -49,10 +49,15 @@ std::unique_ptr<ProfileRepository> &ProfileRepository::get()
return instance;
}
void ProfileRepository::refresh()
void ProfileRepository::refresh(bool fullRefresh)
{
QWriteLocker locker(&m_mutex);
if (fullRefresh) {
// Reset all profiles
m_profiles.clear();
}
// Helper function to check a profile and print debug info
auto check_profile = [&](std::unique_ptr<ProfileModel> &profile, const QString &file) {
if (m_profiles.count(file) > 0) {
......@@ -202,7 +207,7 @@ void ProfileRepository::saveProfile(ProfileInfo *profile, QString profilePath)
KMessageBox::error(nullptr, i18n("Cannot write to file %1", profilePath));
}
file.close();
refresh();
refresh(true);
}
bool ProfileRepository::deleteProfile(const QString &path)
......@@ -214,5 +219,6 @@ bool ProfileRepository::deleteProfile(const QString &path)
if (!success) {
qCDebug(KDENLIVE_LOG) << "//// Cannot delete profile " << path << ", does not seem to be custom one";
}
refresh(true);
return success;
}
......@@ -45,7 +45,7 @@ public:
static std::unique_ptr<ProfileRepository> &get();
/* @brief Reloads all the profiles from the disk */
void refresh();
void refresh(bool fullRefresh = false);
/* @brief Returns a list of all the pairs (description, path) of all the profiles loaded */
QVector<QPair<QString, QString>> getAllProfiles() const;
......
......@@ -98,14 +98,8 @@ ProfileWidget::ProfileWidget(QWidget *parent)
lay->addWidget(profileSplitter);
profileSplitter->setStretchFactor(0, 2);
profileSplitter->setStretchFactor(1, 1);
auto all_fps = ProfileRepository::get()->getAllFps();
QLocale locale;
locale.setNumberOptions(QLocale::OmitGroupSeparator);
fpsFilt->addItem("Any", -1);
for (double fps : all_fps) {
fpsFilt->addItem(locale.toString(fps), fps);
}
refreshFpsCombo();
auto updateFps = [&]() {
double current = fpsFilt->currentData().toDouble();
KdenliveSettings::setProfile_fps_filter(fpsFilt->currentText());
......@@ -140,6 +134,29 @@ ProfileWidget::~ProfileWidget()
{
}
void ProfileWidget::refreshFpsCombo()
{
QLocale locale;
QVariant currentValue;
if (fpsFilt->count() > 1) {
// remember last selected value
currentValue = fpsFilt->currentData();
}
fpsFilt->clear();
locale.setNumberOptions(QLocale::OmitGroupSeparator);
fpsFilt->addItem("Any", -1);
auto all_fps = ProfileRepository::get()->getAllFps();
for (double fps : all_fps) {
fpsFilt->addItem(locale.toString(fps), fps);
}
if (currentValue.isValid()) {
int ix = fpsFilt->findData(currentValue);
if (ix > -1) {
fpsFilt->setCurrentIndex(ix);
}
}
}
void ProfileWidget::loadProfile(const QString &profile)
{
auto index = m_treeModel->findProfile(profile);
......@@ -162,7 +179,14 @@ void ProfileWidget::slotEditProfiles()
{
auto *w = new ProfilesDialog(m_currentProfile);
w->exec();
loadProfile(m_currentProfile);
if (w->profileTreeChanged()) {
// Rebuild profiles tree
m_treeModel.reset();
m_treeModel = ProfileTreeModel::construct(this);
m_filter->setSourceModel(m_treeModel.get());
refreshFpsCombo();
loadProfile(m_currentProfile);
}
delete w;
}
......
......@@ -81,6 +81,9 @@ private:
/** @brief Slot to be called whenever filtering changes */
void slotFilterChanged();
/** @brief Reload available fps values */
void refreshFpsCombo();
signals:
void profileChanged();
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment