Freeciv-3.3: /fast/freeciv/nightly/main/client/gui-qt/cityrep.h Source File

Freeciv-3.3

Loading...
Searching...
No Matches
cityrep.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifndef FC__CITYREP_H
15#define FC__CITYREP_H
16
17#ifdef HAVE_CONFIG_H
18#include <fc_config.h>
19#endif
20
21extern "C" {
22#include "cityrep_g.h"
23}
24
25// Qt
26#include <QAbstractListModel>
27#include <QItemDelegate>
28#include <QMenu>
29#include <QSortFilterProxyModel>
30#include <QTreeView>
31#include <QWidget>
32
33//common
34#include "city.h"
35
36//client
37#include "citydlg_common.h"
38#include "cityrepdata.h"
39#include "climisc.h"
40#include "global_worklist.h"
41
42//agents
43#include "cma_fec.h"
44
45// gui-qt
46#include "sprite.h"
47
48#define NEG_VAL(x) ((x)<0 ? (x) : (-x))
49#define CMA_NONE (10000)
50#define CMA_CUSTOM (10001)
51
52class QMenu;
53class QHBoxLayout;
54class QLabel;
55class QPushButton;
56class QSortFilterProxyModel;
57class QTableWidget;
58class QVBoxLayout;
59class city_report;
60
61 class city_sort_model:public QSortFilterProxyModel
62{
63 bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
64};
65
66/***************************************************************************
67 Item delegate for painting in model of city table
68***************************************************************************/
69 class city_item_delegate:public QItemDelegate {
70 Q_OBJECT
71
72public:
73 city_item_delegate(QObject *parent);
74 ~city_item_delegate() {}
75 void paint(QPainter *painter, const QStyleOptionViewItem &option,
76 const QModelIndex &index) const;
77 QSize sizeHint (const QStyleOptionViewItem & option,
78 const QModelIndex & index) const;
79private:
80 int item_height;
81};
82
83/***************************************************************************
84 Single item in model of city view table
85***************************************************************************/
86 class city_item: public QObject {
87 Q_OBJECT
88
89public:
90 city_item(struct city *pcity);
91 inline int columnCount() const { return NUM_CREPORT_COLS; }
92 QVariant data(int column, int role = Qt::DisplayRole) const;
93 bool setData(int column, const QVariant &value, int role = Qt::DisplayRole);
94 struct city* get_city();
95private:
96 struct city *i_city;
97};
98
99/***************************************************************************
100 City model
101***************************************************************************/
102 class city_model : public QAbstractListModel
103{
104 Q_OBJECT
105public:
106 city_model(QObject *parent = 0);
107 ~city_model();
108 inline int rowCount(const QModelIndex &index = QModelIndex()) const {
109 Q_UNUSED(index);
110 return city_list.size();
111 }
112 int columnCount(const QModelIndex &parent = QModelIndex()) const {
113 Q_UNUSED(parent);
114 return NUM_CREPORT_COLS;
115 }
116 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
117 bool setData(const QModelIndex &index, const QVariant &value,
118 int role = Qt::DisplayRole);
119 QVariant headerData(int section, Qt::Orientation orientation,
120 int role) const;
121 QVariant menu_data(int section) const;
122 QVariant hide_data(int section) const;
123 void populate();
124 void city_changed(struct city *pcity);
125 void all_changed();
126private slots:
127 void notify_city_changed(int row);
128private:
129 QList<city_item *> city_list;
130};
131
132/***************************************************************************
133 City widget to show city model
134***************************************************************************/
135 class city_widget: public QTreeView
136{
137 Q_OBJECT
138 city_model *list_model;
139 QSortFilterProxyModel *filter_model;
140 city_item_delegate *c_i_d;
141 city_report *cr;
142 enum menu_labels {
143 CHANGE_PROD_NOW = 1,
144 CHANGE_PROD_NEXT,
145 CHANGE_PROD_LAST,
146 CHANGE_PROD_BEF_LAST,
147 CMA,
148 SELL,
149 WORKLIST_ADD,
150 WORKLIST_CHANGE,
151 SELECT_IMPR,
152 SELECT_WONDERS,
153 SELECT_SUPP_UNITS,
154 SELECT_PRES_UNITS,
155 SELECT_AVAIL_UNITS,
156 SELECT_AVAIL_IMPR,
157 SELECT_AVAIL_WONDERS,
158 BUY
159 };
160public:
161 city_widget(city_report *ctr);
162 ~city_widget();
163 city_model *get_model() const;
164 QList<city *> selected_cities;
165 void update_model();
166 void update_city(struct city *pcity);
167public slots:
168 void display_header_menu(const QPoint &);
169 void hide_columns();
170 void city_doubleclick(const QModelIndex& index);
171 void city_view();
172 void clear_worlist();
173 void cities_selected(const QItemSelection &sl, const QItemSelection &ds);
174 void display_list_menu(const QPoint&);
175 void buy();
176 void center();
177 void select_all();
178 void select_none();
179 void invert_selection();
180 void select_coastal();
181 void select_building_something();
182 void select_same_island();
183private:
184 void restore_selection();
185 void select_city(struct city *pcity);
186 void gen_cma_labels(QMap<QString, int> &list);
187 void gen_select_labels(QMenu *menu);
188 void gen_worklist_labels(QMap<QString, int> &list);
189 void gen_production_labels(menu_labels which, QMap<QString, cid> &list,
190 bool append_units, bool append_wonders,
191 TestCityFunc test_func, bool global = false);
192 void fill_data(menu_labels which,QMap<QString, cid> &custom_labels,
193 QMenu *menu);
194 void fill_production_menus(city_widget::menu_labels what,
195 QMap<QString, cid> &custom_labels,
196 TestCityFunc test_func, QMenu *menu);
197};
198
199/***************************************************************************
200 Widget to show as tab widget in cities view.
201***************************************************************************/
202 class city_report: public QWidget
203{
204 Q_OBJECT
205 city_widget *city_wdg;
206 QVBoxLayout *layout;
207public:
208 city_report();
209 ~city_report();
210 void update_report();
211 void update_city(struct city *pcity);
212 void init();
213private:
214 int index;
215};
216
217void popdown_city_report();
218
219#endif // FC__CITYREP_H
city.h
citydlg_common.h
cityrep_g.h
cityrepdata.h
NUM_CREPORT_COLS
#define NUM_CREPORT_COLS
Definition cityrepdata.h:25
city_item_delegate
Definition cityrep.h:69
city_item_delegate::item_height
int item_height
Definition cityrep.h:80
city_item_delegate::sizeHint
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition cityrep.cpp:109
city_item_delegate::paint
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition cityrep.cpp:73
city_item_delegate::~city_item_delegate
~city_item_delegate()
Definition cityrep.h:74
city_item
Definition cityrep.h:86
city_item::columnCount
int columnCount() const
Definition cityrep.h:91
city_item::get_city
struct city * get_city()
Definition cityrep.cpp:129
city_item::data
QVariant data(int column, int role=Qt::DisplayRole) const
Definition cityrep.cpp:145
city_item::i_city
struct city * i_city
Definition cityrep.h:96
city_item::setData
bool setData(int column, const QVariant &value, int role=Qt::DisplayRole)
Definition cityrep.cpp:137
city_model
Definition cityrep.h:103
city_model::city_changed
void city_changed(struct city *pcity)
Definition cityrep.cpp:299
city_model::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const
Definition cityrep.cpp:226
city_model::hide_data
QVariant hide_data(int section) const
Definition cityrep.cpp:265
city_model::populate
void populate()
Definition cityrep.cpp:279
city_model::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition cityrep.h:112
city_model::menu_data
QVariant menu_data(int section) const
Definition cityrep.cpp:251
city_model::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition cityrep.cpp:190
city_model::all_changed
void all_changed()
Definition cityrep.cpp:316
city_model::~city_model
~city_model()
Definition cityrep.cpp:173
city_model::city_list
QList< city_item * > city_list
Definition cityrep.h:129
city_model::setData
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::DisplayRole)
Definition cityrep.cpp:205
city_model::rowCount
int rowCount(const QModelIndex &index=QModelIndex()) const
Definition cityrep.h:108
city_model::notify_city_changed
void notify_city_changed(int row)
Definition cityrep.cpp:182
city_report
Definition cityrep.h:203
city_report::city_report
city_report()
Definition cityrep.cpp:1225
city_report::index
int index
Definition cityrep.h:214
city_report::init
void init()
Definition cityrep.cpp:1248
city_report::layout
QVBoxLayout * layout
Definition cityrep.h:206
city_report::~city_report
~city_report()
Definition cityrep.cpp:1240
city_report::update_report
void update_report()
Definition cityrep.cpp:1258
city_report::city_wdg
city_widget * city_wdg
Definition cityrep.h:205
city_report::update_city
void update_city(struct city *pcity)
Definition cityrep.cpp:1266
city_sort_model
Definition cityrep.h:62
city_sort_model::lessThan
bool lessThan(const QModelIndex &left, const QModelIndex &right) const
Definition cityrep.cpp:35
city_widget
Definition cityrep.h:136
city_widget::city_view
void city_view()
Definition cityrep.cpp:403
city_widget::buy
void buy()
Definition cityrep.cpp:437
city_widget::select_city
void select_city(struct city *pcity)
Definition cityrep.cpp:818
city_widget::fill_data
void fill_data(menu_labels which, QMap< QString, cid > &custom_labels, QMenu *menu)
Definition cityrep.cpp:754
city_widget::city_doubleclick
void city_doubleclick(const QModelIndex &index)
Definition cityrep.cpp:395
city_widget::center
void center()
Definition cityrep.cpp:450
city_widget::update_model
void update_model()
Definition cityrep.cpp:1099
city_widget::c_i_d
city_item_delegate * c_i_d
Definition cityrep.h:140
city_widget::filter_model
QSortFilterProxyModel * filter_model
Definition cityrep.h:139
city_widget::fill_production_menus
void fill_production_menus(city_widget::menu_labels what, QMap< QString, cid > &custom_labels, TestCityFunc test_func, QMenu *menu)
Definition cityrep.cpp:733
city_widget::cr
city_report * cr
Definition cityrep.h:141
city_widget::select_coastal
void select_coastal()
Definition cityrep.cpp:844
city_widget::gen_production_labels
void gen_production_labels(menu_labels which, QMap< QString, cid > &list, bool append_units, bool append_wonders, TestCityFunc test_func, bool global=false)
Definition cityrep.cpp:1032
city_widget::select_building_something
void select_building_something()
Definition cityrep.cpp:902
city_widget::display_header_menu
void display_header_menu(const QPoint &)
Definition cityrep.cpp:1128
city_widget::hide_columns
void hide_columns()
Definition cityrep.cpp:1164
city_widget::clear_worlist
void clear_worlist()
Definition cityrep.cpp:422
city_widget::update_city
void update_city(struct city *pcity)
Definition cityrep.cpp:1090
city_widget::list_model
city_model * list_model
Definition cityrep.h:138
city_widget::select_all
void select_all()
Definition cityrep.cpp:775
city_widget::select_none
void select_none()
Definition cityrep.cpp:783
city_widget::display_list_menu
void display_list_menu(const QPoint &)
Definition cityrep.cpp:466
city_widget::gen_worklist_labels
void gen_worklist_labels(QMap< QString, int > &list)
Definition cityrep.cpp:1021
city_widget::cities_selected
void cities_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition cityrep.cpp:1179
city_widget::gen_cma_labels
void gen_cma_labels(QMap< QString, int > &list)
Definition cityrep.cpp:943
city_widget::~city_widget
~city_widget()
Definition cityrep.cpp:1213
city_widget::get_model
city_model * get_model() const
Definition cityrep.cpp:1205
city_widget::selected_cities
QList< city * > selected_cities
Definition cityrep.h:164
city_widget::restore_selection
void restore_selection()
Definition cityrep.cpp:327
city_widget::invert_selection
void invert_selection()
Definition cityrep.cpp:791
city_widget::gen_select_labels
void gen_select_labels(QMenu *menu)
Definition cityrep.cpp:954
city_widget::select_same_island
void select_same_island()
Definition cityrep.cpp:871
city_widget::menu_labels
menu_labels
Definition cityrep.h:142
city_widget::CHANGE_PROD_BEF_LAST
@ CHANGE_PROD_BEF_LAST
Definition cityrep.h:146
city_widget::SELECT_AVAIL_UNITS
@ SELECT_AVAIL_UNITS
Definition cityrep.h:155
city_widget::SELL
@ SELL
Definition cityrep.h:148
city_widget::SELECT_AVAIL_WONDERS
@ SELECT_AVAIL_WONDERS
Definition cityrep.h:157
city_widget::SELECT_SUPP_UNITS
@ SELECT_SUPP_UNITS
Definition cityrep.h:153
city_widget::CHANGE_PROD_NOW
@ CHANGE_PROD_NOW
Definition cityrep.h:143
city_widget::CHANGE_PROD_LAST
@ CHANGE_PROD_LAST
Definition cityrep.h:145
city_widget::SELECT_AVAIL_IMPR
@ SELECT_AVAIL_IMPR
Definition cityrep.h:156
city_widget::CMA
@ CMA
Definition cityrep.h:147
city_widget::WORKLIST_CHANGE
@ WORKLIST_CHANGE
Definition cityrep.h:150
city_widget::WORKLIST_ADD
@ WORKLIST_ADD
Definition cityrep.h:149
city_widget::SELECT_WONDERS
@ SELECT_WONDERS
Definition cityrep.h:152
city_widget::SELECT_IMPR
@ SELECT_IMPR
Definition cityrep.h:151
city_widget::CHANGE_PROD_NEXT
@ CHANGE_PROD_NEXT
Definition cityrep.h:144
city_widget::SELECT_PRES_UNITS
@ SELECT_PRES_UNITS
Definition cityrep.h:154
city_widget::BUY
@ BUY
Definition cityrep.h:158
climisc.h
TestCityFunc
bool(* TestCityFunc)(const struct city *, const struct universal *)
Definition climisc.h:85
list
static struct fc_sockaddr_list * list
Definition clinet.c:102
cma_fec.h
incite_cost
char * incite_cost
Definition comments.c:74
global_worklist.h
popdown_city_report
void popdown_city_report()
Definition cityrep.cpp:1339
sprite.h
slots
struct player_slot * slots
Definition player.c:51
city
Definition city.h:320
option
Definition options.c:514
section
Definition section_file.h:28
test_func
Definition mapgen.c:684