OpenClonk
C4ConsoleQtNewScenario.h
Go to the documentation of this file.
1 /*
2 * OpenClonk, http://www.openclonk.org
3 *
4 * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5 * Copyright (c) 2013, The OpenClonk Team and contributors
6 *
7 * Distributed under the terms of the ISC license; see accompanying file
8 * "COPYING" for details.
9 *
10 * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11 * See accompanying file "TRADEMARK" for details.
12 *
13 * To redistribute this file separately, substitute the full license texts
14 * for the above references.
15 */
16 
17 /* Proplist table view */
18 
19 #ifndef INC_C4ConsoleQtNewScenario
20 #define INC_C4ConsoleQtNewScenario
21 #ifdef WITH_QT_EDITOR
22 
23 #include "C4Include.h" // needed for automoc
24 #include "editor/C4ConsoleGUI.h" // for OpenGL
25 #include "editor/C4ConsoleQt.h"
26 #include "ui_C4ConsoleQtNewScenario.h"
27 #include "landscape/C4Scenario.h"
28 
29 // Definition file view for selection in New Scenario dialogue
30 class C4ConsoleQtDefinitionFileListModel : public QAbstractItemModel
31 {
32  Q_OBJECT
33 
34 public:
35  C4ConsoleQtDefinitionFileListModel();
36  ~C4ConsoleQtDefinitionFileListModel() override;
37  void AddExtraDef(const char *def);
38  std::list<const char *> GetUserSelectedDefinitions() const;
39  std::list<const char *> GetSelectedDefinitions() const;
40  void SetForcedSelection(const std::list<const char *> &defs);
41 
42 private:
43 
44  // Cached def file info: Children loaded on demand (if user expands into tree)
45  class DefFileInfo
46  {
47  DefFileInfo *parent{nullptr};
48  C4Group grp;
49  std::vector< std::unique_ptr<DefFileInfo> > children;
50  StdCopyStrBuf filename, root_path, full_filename;
51  bool was_opened{true}, is_root{true};
52  bool user_selected{false}, force_selected{false};
53 
54  bool OpenGroup();
55  public:
56  DefFileInfo(DefFileInfo *parent, const char *filename, const char *root_path);
57  DefFileInfo(); // init as root
58  int32_t GetChildCount();
59  DefFileInfo *GetParent() const { return parent; }
60  DefFileInfo *GetChild(int32_t index);
61  int32_t GetChildIndex(const DefFileInfo *child);
62  const char *GetName() const { return filename.getData(); }
63  bool IsRoot() const { return is_root; }
64  void SetSelected(bool to_val, bool forced);
65  bool IsUserSelected() const { return user_selected; }
66  bool IsForceSelected() const { return force_selected; }
67  bool IsSelected() const { return user_selected || force_selected; }
68  bool IsDisabled() const { return force_selected || (parent && parent->IsSelected()); }
69  void AddUserSelectedDefinitions(std::list<const char *> *result) const;
70  void AddSelectedDefinitions(std::list<const char *> *result) const;
71  void SetForcedSelection(const char *selected_def_filepath);
72  void AddExtraDef(const char *def);
73  };
74 
75  mutable DefFileInfo root;
76 
77 protected:
78  int rowCount(const QModelIndex & parent = QModelIndex()) const override;
79  int columnCount(const QModelIndex & parent = QModelIndex()) const override;
80  QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
81  QModelIndex index(int row, int column, const QModelIndex &parent) const override;
82  QModelIndex parent(const QModelIndex &index) const override;
83  Qt::ItemFlags flags(const QModelIndex &index) const override;
84  bool setData(const QModelIndex& index, const QVariant& value, int role) override;
85 };
86 
87 class C4ConsoleQtNewScenarioDlg : public QDialog
88 {
89  Q_OBJECT
90 
91  Ui::NewScenarioDialog ui;
92  StdCopyStrBuf filename;
93  bool has_custom_filename;
94  C4ConsoleQtDefinitionFileListModel def_file_model;
95  std::vector<C4Scenario> all_template_c4s;
96 
97 public:
98  C4ConsoleQtNewScenarioDlg(class QMainWindow *parent_window);
99  const char *GetFilename() const { return filename.getData(); }
100  bool IsHostAsNetwork() const;
101 
102 private:
103  void InitScenarioTemplateList();
104  void AddScenarioTemplate(C4Group &parent, const char *filename, bool is_default);
105  bool CreateScenario();
106  void DoError(const char *msg);
107 
108 protected slots:
109  void CreatePressed();
110  void BrowsePressed();
111  void TitleChanged(const QString &new_title);
112  void SelectedTemplateChanged(int new_selection);
113 };
114 
115 #endif // WITH_QT_EDITOR
116 #endif // INC_C4ConsoleQtNewScenario
char * GetFilename(char *szPath)
Definition: StdFile.cpp:42
const char * getData() const
Definition: StdBuf.h:442