Freeciv-3.2
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
61class 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***************************************************************************/
69class city_item_delegate:public QItemDelegate {
71
72public:
73 city_item_delegate(QObject *parent);
76 const QModelIndex &index) const;
78 const QModelIndex & index) const;
79private:
81};
82
83/***************************************************************************
84 Single item in model of city view table
85***************************************************************************/
86class city_item: public QObject {
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***************************************************************************/
102class city_model : public QAbstractListModel
103{
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 }
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:
130};
131
132/***************************************************************************
133 City widget to show city model
134***************************************************************************/
135class city_widget: public QTreeView
136{
139 QSortFilterProxyModel *filter_model;
160public:
162 ~city_widget();
163 city_model *get_model() const;
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();
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();
182 void select_same_island();
183private:
184 void restore_selection();
185 void select_city(struct city *pcity);
187 void gen_select_labels(QMenu *menu);
190 bool append_units, bool append_wonders,
191 TestCityFunc test_func, bool global = false);
193 QMenu *menu);
196 TestCityFunc test_func, QMenu *menu);
197};
198
199/***************************************************************************
200 Widget to show as tab widget in cities view.
201***************************************************************************/
202class city_report: public QWidget
203{
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
218
219#endif // FC__CITYREP_H
#define NUM_CREPORT_COLS
Definition cityrepdata.h:25
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition cityrep.cpp:109
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition cityrep.cpp:73
int columnCount() const
Definition cityrep.h:91
struct city * get_city()
Definition cityrep.cpp:129
QVariant data(int column, int role=Qt::DisplayRole) const
Definition cityrep.cpp:145
struct city * i_city
Definition cityrep.h:96
bool setData(int column, const QVariant &value, int role=Qt::DisplayRole)
Definition cityrep.cpp:137
void city_changed(struct city *pcity)
Definition cityrep.cpp:299
QVariant headerData(int section, Qt::Orientation orientation, int role) const
Definition cityrep.cpp:226
QVariant hide_data(int section) const
Definition cityrep.cpp:265
void populate()
Definition cityrep.cpp:279
int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition cityrep.h:112
QVariant menu_data(int section) const
Definition cityrep.cpp:251
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition cityrep.cpp:190
void all_changed()
Definition cityrep.cpp:316
QList< city_item * > city_list
Definition cityrep.h:129
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::DisplayRole)
Definition cityrep.cpp:205
int rowCount(const QModelIndex &index=QModelIndex()) const
Definition cityrep.h:108
void notify_city_changed(int row)
Definition cityrep.cpp:182
void init()
Definition cityrep.cpp:1247
QVBoxLayout * layout
Definition cityrep.h:206
void update_report()
Definition cityrep.cpp:1257
city_widget * city_wdg
Definition cityrep.h:205
void update_city(struct city *pcity)
Definition cityrep.cpp:1265
bool lessThan(const QModelIndex &left, const QModelIndex &right) const
Definition cityrep.cpp:35
void city_view()
Definition cityrep.cpp:403
void buy()
Definition cityrep.cpp:437
void select_city(struct city *pcity)
Definition cityrep.cpp:818
void fill_data(menu_labels which, QMap< QString, cid > &custom_labels, QMenu *menu)
Definition cityrep.cpp:754
void city_doubleclick(const QModelIndex &index)
Definition cityrep.cpp:395
void center()
Definition cityrep.cpp:450
void update_model()
Definition cityrep.cpp:1098
city_item_delegate * c_i_d
Definition cityrep.h:140
QSortFilterProxyModel * filter_model
Definition cityrep.h:139
void fill_production_menus(city_widget::menu_labels what, QMap< QString, cid > &custom_labels, TestCityFunc test_func, QMenu *menu)
Definition cityrep.cpp:733
city_report * cr
Definition cityrep.h:141
void select_coastal()
Definition cityrep.cpp:844
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:1031
void select_building_something()
Definition cityrep.cpp:902
void display_header_menu(const QPoint &)
Definition cityrep.cpp:1127
void hide_columns()
Definition cityrep.cpp:1163
void clear_worlist()
Definition cityrep.cpp:422
void update_city(struct city *pcity)
Definition cityrep.cpp:1089
city_model * list_model
Definition cityrep.h:138
void select_all()
Definition cityrep.cpp:775
void select_none()
Definition cityrep.cpp:783
void display_list_menu(const QPoint &)
Definition cityrep.cpp:466
void gen_worklist_labels(QMap< QString, int > &list)
Definition cityrep.cpp:1020
void cities_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition cityrep.cpp:1178
void gen_cma_labels(QMap< QString, int > &list)
Definition cityrep.cpp:943
city_model * get_model() const
Definition cityrep.cpp:1204
QList< city * > selected_cities
Definition cityrep.h:164
void restore_selection()
Definition cityrep.cpp:327
void invert_selection()
Definition cityrep.cpp:791
void gen_select_labels(QMenu *menu)
Definition cityrep.cpp:954
void select_same_island()
Definition cityrep.cpp:871
@ CHANGE_PROD_BEF_LAST
Definition cityrep.h:146
@ SELECT_AVAIL_UNITS
Definition cityrep.h:155
@ SELECT_AVAIL_WONDERS
Definition cityrep.h:157
@ SELECT_SUPP_UNITS
Definition cityrep.h:153
@ CHANGE_PROD_NOW
Definition cityrep.h:143
@ CHANGE_PROD_LAST
Definition cityrep.h:145
@ SELECT_AVAIL_IMPR
Definition cityrep.h:156
@ WORKLIST_CHANGE
Definition cityrep.h:150
@ SELECT_WONDERS
Definition cityrep.h:152
@ CHANGE_PROD_NEXT
Definition cityrep.h:144
@ SELECT_PRES_UNITS
Definition cityrep.h:154
bool(* TestCityFunc)(const struct city *, const struct universal *)
Definition climisc.h:87
static struct fc_sockaddr_list * list
Definition clinet.c:102
char * incite_cost
Definition comments.c:75
void popdown_city_report()
Definition cityrep.cpp:1338
struct player_slot * slots
Definition player.c:51
Definition city.h:320