49 lines
1.4 KiB
C
49 lines
1.4 KiB
C
|
|
#ifndef UNSAVEDDOCUMENTSDIALOG_H
|
||
|
|
#define UNSAVEDDOCUMENTSDIALOG_H
|
||
|
|
|
||
|
|
#include "SqlDocument.h"
|
||
|
|
#include <QDialog>
|
||
|
|
#include <QList>
|
||
|
|
#include <functional>
|
||
|
|
#include <memory>
|
||
|
|
|
||
|
|
class QListWidget;
|
||
|
|
|
||
|
|
/** Lists modified documents with a checkbox per document. The user picks
|
||
|
|
* whether the checked documents should be saved or discarded.
|
||
|
|
*/
|
||
|
|
class UnsavedDocumentsDialog : public QDialog {
|
||
|
|
Q_OBJECT
|
||
|
|
public:
|
||
|
|
enum class Choice {
|
||
|
|
Cancel,
|
||
|
|
Save,
|
||
|
|
Discard
|
||
|
|
};
|
||
|
|
|
||
|
|
UnsavedDocumentsDialog(const QList<std::shared_ptr<SqlDocument>> &docs, QWidget *parent = nullptr);
|
||
|
|
|
||
|
|
Choice choice() const { return m_choice; }
|
||
|
|
QList<std::shared_ptr<SqlDocument>> checkedDocuments() const;
|
||
|
|
QList<std::shared_ptr<SqlDocument>> uncheckedDocuments() const;
|
||
|
|
|
||
|
|
private:
|
||
|
|
QList<std::shared_ptr<SqlDocument>> m_docs;
|
||
|
|
QListWidget *m_list;
|
||
|
|
Choice m_choice = Choice::Cancel;
|
||
|
|
};
|
||
|
|
|
||
|
|
/** Selects the documents that are closed when every editor for which
|
||
|
|
* isClosing returns true is closed. Only modified documents are returned.
|
||
|
|
*/
|
||
|
|
QList<std::shared_ptr<SqlDocument>> documentsClosedWith(const QList<std::shared_ptr<SqlDocument>> &docs,
|
||
|
|
const std::function<bool(const QWidget*)> &isClosing);
|
||
|
|
|
||
|
|
/** Asks the user what to do with the modified documents. Returns true when
|
||
|
|
* the close may continue, i.e. nothing was cancelled, no save failed and
|
||
|
|
* every listed document was checked.
|
||
|
|
*/
|
||
|
|
bool confirmClose(QWidget *parent, const QList<std::shared_ptr<SqlDocument>> &docs);
|
||
|
|
|
||
|
|
#endif // UNSAVEDDOCUMENTSDIALOG_H
|