2021-01-18 07:28:54 +00:00
|
|
|
/* Copyright 2013-2021 MultiMC Contributors
|
2014-06-01 23:49:53 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2014-07-15 23:13:40 +01:00
|
|
|
#include <functional>
|
2023-08-02 17:35:35 +01:00
|
|
|
#include <memory>
|
|
|
|
#include "ui/pages/BasePage.h"
|
2014-06-01 23:49:53 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
class BasePageProvider {
|
|
|
|
public:
|
|
|
|
virtual QList<BasePage*> getPages() = 0;
|
2014-06-01 23:49:53 +01:00
|
|
|
virtual QString dialogTitle() = 0;
|
|
|
|
};
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
class GenericPageProvider : public BasePageProvider {
|
2023-10-23 05:34:11 +01:00
|
|
|
using PageCreator = std::function<BasePage*()>;
|
2023-08-02 17:35:35 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
explicit GenericPageProvider(const QString& dialogTitle) : m_dialogTitle(dialogTitle) {}
|
2018-06-28 22:18:45 +01:00
|
|
|
virtual ~GenericPageProvider() {}
|
2014-07-15 23:13:40 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
QList<BasePage*> getPages() override
|
2014-07-15 23:13:40 +01:00
|
|
|
{
|
2023-08-02 17:35:35 +01:00
|
|
|
QList<BasePage*> pages;
|
|
|
|
for (PageCreator creator : m_creators) {
|
2014-07-15 23:13:40 +01:00
|
|
|
pages.append(creator());
|
|
|
|
}
|
|
|
|
return pages;
|
|
|
|
}
|
|
|
|
QString dialogTitle() override { return m_dialogTitle; }
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
void setDialogTitle(const QString& title) { m_dialogTitle = title; }
|
|
|
|
void addPageCreator(PageCreator page) { m_creators.append(page); }
|
2014-07-15 23:13:40 +01:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
template <typename PageClass>
|
2014-07-15 23:13:40 +01:00
|
|
|
void addPage()
|
|
|
|
{
|
2023-08-02 17:35:35 +01:00
|
|
|
addPageCreator([]() { return new PageClass(); });
|
2014-07-15 23:13:40 +01:00
|
|
|
}
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
private:
|
2014-07-15 23:13:40 +01:00
|
|
|
QList<PageCreator> m_creators;
|
|
|
|
QString m_dialogTitle;
|
|
|
|
};
|