46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <QObject>
|
|
#include <QQmlApplicationEngine>
|
|
#include <QPointer>
|
|
#include <QList>
|
|
|
|
class FileStore;
|
|
|
|
// Создание окон приложения (мульти-хранилища: новое хранилище — новое окно).
|
|
class WindowController : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(int windowCount READ windowCount NOTIFY windowsChanged)
|
|
Q_PROPERTY(QStringList openVaults READ openVaults NOTIFY windowsChanged)
|
|
|
|
public:
|
|
WindowController(QQmlApplicationEngine *engine, const QString &mainWindowUrl,
|
|
QObject *parent = nullptr);
|
|
|
|
int windowCount() const;
|
|
QStringList openVaults() const;
|
|
|
|
// Открывает окно с заданным хранилищем. Возвращает nullptr при ошибке.
|
|
Q_INVOKABLE QObject *openWindow(const QString &vaultPath);
|
|
|
|
Q_INVOKABLE int indexOfVault(const QString &vaultPath) const;
|
|
|
|
signals:
|
|
void windowsChanged();
|
|
void windowOpened(const QString &vaultPath);
|
|
void windowClosed(const QString &vaultPath);
|
|
|
|
private:
|
|
struct Window {
|
|
QString vault;
|
|
QPointer<QObject> object;
|
|
FileStore *fileStore = nullptr;
|
|
};
|
|
|
|
QQmlApplicationEngine *m_engine;
|
|
QString m_mainWindowUrl;
|
|
QList<Window> m_windows;
|
|
QQmlComponent *m_component = nullptr;
|
|
}; |