2022-10-08 22:32:02 +02:00
|
|
|
/*
|
|
|
|
* townbuildingswidget.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
2022-09-18 01:23:17 +02:00
|
|
|
|
2022-10-16 13:37:01 +02:00
|
|
|
#include "../StdInc.h"
|
2022-09-18 01:23:17 +02:00
|
|
|
#include <QDialog>
|
|
|
|
#include "../lib/mapObjects/CGTownInstance.h"
|
|
|
|
|
|
|
|
namespace Ui {
|
2024-06-24 03:23:26 +02:00
|
|
|
class TownBuildingsWidget;
|
2022-09-18 01:23:17 +02:00
|
|
|
}
|
|
|
|
|
2022-12-22 19:58:13 +02:00
|
|
|
std::string defaultBuildingIdConversion(BuildingID bId);
|
|
|
|
|
2024-07-26 20:42:16 +02:00
|
|
|
QStandardItem * getBuildingParentFromTreeModel(const CBuilding * building, QStandardItemModel & model);
|
|
|
|
|
2024-08-01 22:28:23 +02:00
|
|
|
QVariantList getBuildingVariantsFromModel(QStandardItemModel & model, int modelColumn, Qt::CheckState checkState);
|
2024-07-26 20:42:16 +02:00
|
|
|
|
2024-06-24 03:23:26 +02:00
|
|
|
class TownBuildingsWidget : public QDialog
|
2022-09-18 01:23:17 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
QStandardItem * addBuilding(const CTown & ctown, int bId, std::set<si32> & remaining);
|
|
|
|
|
|
|
|
public:
|
2024-06-08 16:33:55 +02:00
|
|
|
enum Column
|
|
|
|
{
|
|
|
|
TYPE, ENABLED, BUILT
|
|
|
|
};
|
2024-06-24 03:23:26 +02:00
|
|
|
explicit TownBuildingsWidget(CGTownInstance &, QWidget *parent = nullptr);
|
|
|
|
~TownBuildingsWidget();
|
2024-06-08 16:33:55 +02:00
|
|
|
|
2022-09-18 01:23:17 +02:00
|
|
|
void addBuildings(const CTown & ctown);
|
|
|
|
std::set<BuildingID> getForbiddenBuildings();
|
|
|
|
std::set<BuildingID> getBuiltBuildings();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void on_treeView_expanded(const QModelIndex &index);
|
|
|
|
|
|
|
|
void on_treeView_collapsed(const QModelIndex &index);
|
|
|
|
|
2024-06-08 23:13:17 +02:00
|
|
|
void on_buildAll_clicked();
|
|
|
|
|
|
|
|
void on_demolishAll_clicked();
|
|
|
|
|
|
|
|
void on_enableAll_clicked();
|
|
|
|
|
|
|
|
void on_disableAll_clicked();
|
|
|
|
|
2024-06-08 16:33:55 +02:00
|
|
|
void onItemChanged(QStandardItem * item);
|
|
|
|
|
2022-09-18 01:23:17 +02:00
|
|
|
private:
|
2022-10-08 22:32:02 +02:00
|
|
|
std::set<BuildingID> getBuildingsFromModel(int modelColumn, Qt::CheckState checkState);
|
2024-06-08 16:33:55 +02:00
|
|
|
void setRowColumnCheckState(QStandardItem * item, Column column, Qt::CheckState checkState);
|
2024-06-08 23:13:17 +02:00
|
|
|
void setAllRowsColumnCheckState(Column column, Qt::CheckState checkState);
|
2024-06-08 16:33:55 +02:00
|
|
|
|
2024-06-24 03:23:26 +02:00
|
|
|
Ui::TownBuildingsWidget *ui;
|
2022-09-18 01:23:17 +02:00
|
|
|
CGTownInstance & town;
|
|
|
|
mutable QStandardItemModel model;
|
|
|
|
};
|
|
|
|
|
|
|
|
class TownBuildingsDelegate : public QStyledItemDelegate
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
using QStyledItemDelegate::QStyledItemDelegate;
|
|
|
|
|
|
|
|
TownBuildingsDelegate(CGTownInstance &);
|
|
|
|
|
|
|
|
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
|
|
|
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
|
|
|
|
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
CGTownInstance & town;
|
|
|
|
//std::set<BuildingID>
|
|
|
|
};
|
|
|
|
|