refs #693, GUI dialog when application closes

This commit is contained in:
Klaus Basan
2016-06-29 22:46:53 +02:00
parent 744c7235e6
commit 6650f18e57
5 changed files with 224 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
/* Copyright (C) 2013
* swift project Community / Contributors
*
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "applicationclosedialog.h"
#include "ui_applicationclosedialog.h"
#include "blackgui/guiapplication.h"
#include "blackgui/guiutility.h"
#include "blackmisc/settingscache.h"
#include "blackmisc/logmessage.h"
#include <QStringListModel>
#include <QModelIndexList>
using namespace BlackMisc;
using namespace BlackGui;
namespace BlackGui
{
namespace Components
{
CApplicationCloseDialog::CApplicationCloseDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::CApplicationCloseDialog)
{
ui->setupUi(this);
this->setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
this->initSettingsView();
connect(this, &CApplicationCloseDialog::accepted, this, &CApplicationCloseDialog::ps_onAccepted);
}
CApplicationCloseDialog::~CApplicationCloseDialog()
{ }
void CApplicationCloseDialog::ps_onAccepted()
{
QModelIndexList indexes = ui->lv_UnsavedSettings->selectionModel()->selectedIndexes();
if (indexes.isEmpty()) { return; }
const QList<int> rows = CGuiUtility::indexToUniqueRows(indexes);
QStringList saveKeys;
for (int r : rows)
{
const QString key = this->m_settingskeys.at(r);
saveKeys.append(key);
}
CStatusMessage msg = sApp->saveSettingsByKey(saveKeys);
if (msg.isFailure()) { CLogMessage::preformatted(msg); }
}
void CApplicationCloseDialog::initSettingsView()
{
QStringList settings(CSettingsCache::instance()->getAllUnsavedKeys());
settings.sort();
QStringListModel *model = new QStringListModel(settings, this);
ui->lv_UnsavedSettings->setModel(model);
ui->lv_UnsavedSettings->selectAll();
this->m_settingskeys = settings;
}
} // ns
} // ns

View File

@@ -0,0 +1,50 @@
/* Copyright (C) 2013
* swift project Community / Contributors
*
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKGUI_COMPONENTS_APPLICATIONCLOSEDIALOG_H
#define BLACKGUI_COMPONENTS_APPLICATIONCLOSEDIALOG_H
#include <QDialog>
#include <QScopedPointer>
namespace Ui { class CApplicationCloseDialog; }
namespace BlackGui
{
namespace Components
{
/*!
* Close dialog for application
*/
class CApplicationCloseDialog : public QDialog
{
Q_OBJECT
public:
//! Constructor
explicit CApplicationCloseDialog(QWidget *parent = nullptr);
//! Destructor
~CApplicationCloseDialog();
private slots:
//! Accepted
void ps_onAccepted();
private:
QScopedPointer<Ui::CApplicationCloseDialog> ui;
QStringList m_settingskeys;
//! Init the settings view
void initSettingsView();
};
} // ns
} // ns
#endif // guard

View File

@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CApplicationCloseDialog</class>
<widget class="QDialog" name="CApplicationCloseDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>200</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QFrame" name="fr_UnsavedSettings">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="lbl_UnsavedSettings">
<property name="text">
<string>Save the following settings:</string>
</property>
</widget>
</item>
<item>
<widget class="QListView" name="lv_UnsavedSettings">
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="bb_ApplicationCloseDialog">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>bb_ApplicationCloseDialog</sender>
<signal>accepted()</signal>
<receiver>CApplicationCloseDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>bb_ApplicationCloseDialog</sender>
<signal>rejected()</signal>
<receiver>CApplicationCloseDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -327,4 +327,16 @@ namespace BlackGui
Q_UNUSED(ok);
return QMargins(l, t, r, b);
}
QList<int> CGuiUtility::indexToUniqueRows(const QModelIndexList &indexes)
{
QList<int> rows;
for (const QModelIndex i : indexes)
{
const int r = i.row();
if (rows.contains(r)) { continue; }
rows.append(r);
}
return rows;
}
} // ns

View File

@@ -19,6 +19,7 @@
#include <QPoint>
#include <QString>
#include <QWidgetList>
#include <QModelIndexList>
class QCheckBox;
class QComboBox;
@@ -100,6 +101,9 @@ namespace BlackGui
//! Convert from string
static QMargins stringToMargins(const QString &str);
//! Only the row part and unique (so no rows is twice in the list)
static QList<int> indexToUniqueRows(const QModelIndexList &indexes);
private:
//! Constructor, use static methods only
CGuiUtility() {}