19#include <QApplication>
36 const QModelIndex &right)
const
44 qleft = sourceModel()->data(left);
45 qright = sourceModel()->data(right);
46 l_bytes = qleft.toString().toUtf8();
47 r_bytes = qright.toString().toUtf8();
62 :QItemDelegate(parent)
64 QFont f = QApplication::font();
74 const QStyleOptionViewItem &
option,
75 const QModelIndex &index)
const
77 QStyleOptionViewItem opt = QItemDelegate::setOptions(index,
option);
84 if (txt ==
"cityname") {
85 font.setCapitalization(QFont::SmallCaps);
89 if (txt ==
"hstate_verbose") {
93 if (txt ==
"prodplus") {
94 txt = index.data().toString();
95 if (txt.toInt() < 0) {
97 palette.setColor(QPalette::Text, QColor(255, 0, 0));
99 opt.palette = palette;
103 QItemDelegate::paint(painter, opt, index);
110 const QModelIndex &index)
const
112 QSize s = QItemDelegate::sizeHint(
option, index);
150 if (role == Qt::UserRole && column == 0) {
151 return QVariant::fromValue((
void *)
i_city);
153 if (role != Qt::DisplayRole) {
159 return QString(buf).trimmed();
184 emit dataChanged(index(row, 0), index(row,
columnCount() - 1));
192 if (!index.isValid()) {
195 if (index.row() >= 0 && index.row() <
rowCount() && index.column() >= 0
197 return city_list[index.row()]->data(index.column(), role);
208 if (!index.isValid() || role != Qt::DisplayRole) {
211 if (index.row() >= 0 && index.row() <
rowCount() && index.column() >= 0
213 bool change =
city_list[index.row()]->setData(index.column(), value, role);
233 if (role == Qt::DisplayRole) {
238 return QString(buf).trimmed();
240 if (role == Qt::ToolTipRole) {
305 for (
int i = 0; i <
city_list.count(); i++) {
307 if (pcity ==
item->get_city()) {
329 QItemSelection selection;
339 qvar = i.data(Qt::UserRole);
343 pcity =
reinterpret_cast<city *
>(qvar.value<
void *>());
345 selection.append(QItemSelectionRange(i));
348 selectionModel()->select(selection, QItemSelectionModel::Rows
349 | QItemSelectionModel::SelectCurrent);
359 setItemDelegate(
c_i_d);
366 setRootIsDecorated(
false);
367 setAllColumnsShowFocus(
true);
368 setSortingEnabled(
true);
369 setSelectionMode(QAbstractItemView::ExtendedSelection);
370 setSelectionBehavior(QAbstractItemView::SelectRows);
371 setItemsExpandable(
false);
373 setProperty(
"uniformRowHeights",
"true");
374 setAlternatingRowColors(
true);
375 header()->setContextMenuPolicy(Qt::CustomContextMenu);
376 header()->setMinimumSectionSize(10);
377 setContextMenuPolicy(Qt::CustomContextMenu);
379 connect(header(), &QWidget::customContextMenuRequested,
381 connect(selectionModel(),
382 SIGNAL(selectionChanged(
const QItemSelection &,
383 const QItemSelection &)),
385 const QItemSelection &)));
386 connect(
this, &QAbstractItemView::doubleClicked,
this,
388 connect(
this, &QWidget::customContextMenuRequested,
412 Q_ASSERT(pcity != NULL);
429 Q_ASSERT(pcity != NULL);
442 Q_ASSERT(pcity != NULL);
458 Q_ASSERT(pcity != NULL);
460 gui()->game_tab_widget->setCurrentIndex(0);
468 QMap<QString, cid> custom_labels;
469 QMap<QString, int> cma_labels;
473 struct city *pcity_outer;
476 QAction wl_clear(
_(
"Clear"), 0);
477 QAction wl_empty(
_(
"(no worklists defined)"), 0);
478 bool worklist_defined =
true;
483 list_menu =
new QMenu(
this);
485 some_menu = list_menu->addMenu(
_(
"Production"));
486 tmp_menu = some_menu->addMenu(
_(
"Change"));
489 tmp_menu = some_menu->addMenu(
_(
"Add next"));
492 tmp_menu = some_menu->addMenu(
_(
"Add before last"));
495 tmp_menu = some_menu->addMenu(
_(
"Add last"));
499 tmp_menu = some_menu->addMenu(
_(
"Worklist"));
500 tmp_menu->addAction(&wl_clear);
502 tmp2_menu = tmp_menu->addMenu(
_(
"Add"));
504 if (cma_labels.count() == 0) {
505 tmp2_menu->addAction(&wl_empty);
506 worklist_defined =
false;
509 tmp2_menu = tmp_menu->addMenu(
_(
"Change"));
510 if (cma_labels.count() == 0) {
511 tmp2_menu->addAction(&wl_empty);
512 worklist_defined =
false;
515 some_menu = list_menu->addMenu(
_(
"Governor"));
518 some_menu = list_menu->addMenu(
_(
"Sell"));
523 some_menu = list_menu->addMenu(
_(
"Select"));
526 char buy_costs_label[200];
529 some_menu = list_menu->addMenu(
_(
"City/Buy"));
531 connect(some_menu->addAction(
_(
"View")), &QAction::triggered,
this,
533 connect(some_menu->addAction(
_(
"Center")), &QAction::triggered,
this,
540 fc_snprintf(buy_costs_label,
sizeof(buy_costs_label),
541 _(
"Buy ( Cost: %d )"), buy_costs);
542 connect(some_menu->addAction(buy_costs_label), &QAction::triggered,
this,
546 list_menu->setAttribute(Qt::WA_DeleteOnClose);
547 connect(list_menu, &QMenu::triggered,
this,
549 QVariant qvar, qvar2;
554 const char *imprname;
557 struct city *pcity_mid;
559 bool need_clear =
true;
560 bool sell_ask =
true;
566 qvar2 = act->property(
"FC");
573 if (NULL != iter_city) {
645 if (
nullptr != pcity_mid) {
667 _(
"Are you sure you want to sell those %s?"),
670 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
671 ask->setDefaultButton(QMessageBox::Cancel);
673 ask->setAttribute(Qt::WA_DeleteOnClose);
674 city_id = pcity_mid->
id;
676 connect(ask, &hud_message_box::accepted,
this, [=]() {
680 if (!pcity || !building) {
691 if (NULL != pcity_mid) {
702 if (worklist_defined) {
709 if (worklist_defined) {
715 if (NULL != pcity_mid) {
727 list_menu->popup(QCursor::pos());
734 QMap<QString, cid> &custom_labels,
739 m1 = menu->addMenu(
_(
"Buildings"));
740 m2 = menu->addMenu(
_(
"Units"));
741 m3 = menu->addMenu(
_(
"Wonders"));
755 QMap<QString, cid> &custom_labels, QMenu *menu)
758 QMap<QString, cid>::const_iterator map_iter;
760 map_iter = custom_labels.constBegin();
761 while (map_iter != custom_labels.constEnd()) {
762 action = menu->addAction(map_iter.key());
763 action->setData(map_iter.value());
764 action->setProperty(
"FC", which);
767 if (custom_labels.isEmpty()) {
768 menu->setDisabled(
true);
793 QItemSelection selection;
801 qvar = i.data(Qt::UserRole);
805 pcity =
reinterpret_cast<city *
>(qvar.value<
void *>());
807 selection.append(QItemSelectionRange(i));
811 selectionModel()->select(selection, QItemSelectionModel::Rows
812 | QItemSelectionModel::SelectCurrent);
821 QItemSelection selection;
828 qvar = i.data(Qt::UserRole);
832 pcity =
reinterpret_cast<city *
>(qvar.value<
void *>());
833 if (pcity == spcity) {
834 selection.append(QItemSelectionRange(i));
837 selectionModel()->select(selection, QItemSelectionModel::Rows
838 | QItemSelectionModel::Select);
847 QItemSelection selection;
855 qvar = i.data(Qt::UserRole);
859 pcity =
reinterpret_cast<city *
>(qvar.value<
void *>());
862 selection.append(QItemSelectionRange(i));
865 selectionModel()->select(selection, QItemSelectionModel::Rows
866 | QItemSelectionModel::SelectCurrent);
874 QItemSelection selection;
882 qvar = i.data(Qt::UserRole);
886 pcity =
reinterpret_cast<city *
>(qvar.value<
void *>());
891 selection.append(QItemSelectionRange(i));
895 selectionModel()->select(selection, QItemSelectionModel::Rows
896 | QItemSelectionModel::SelectCurrent);
905 QItemSelection selection;
915 qvar = i.data(Qt::UserRole);
919 pcity =
reinterpret_cast<city *
>(qvar.value<
void *>());
920 act = qobject_cast<QAction *>(sender());
922 str = qvar.toString();
928 selection.append(QItemSelectionRange(i));
930 selection.append(QItemSelectionRange(i));
931 }
else if (
str ==
"wonder"
934 selection.append(QItemSelectionRange(i));
938 selectionModel()->select(selection, QItemSelectionModel::Rows
939 | QItemSelectionModel::SelectCurrent);
960 QMap<QString, cid> custom_labels;
962 act = menu->addAction(
_(
"All Cities"));
964 act = menu->addAction(
_(
"No Cities"));
966 act = menu->addAction(
_(
"Invert Selection"));
968 menu->addSeparator();
969 act = menu->addAction(
_(
"Coastal Cities"));
971 act = menu->addAction(
_(
"Same Island"));
974 act->setDisabled(
true);
976 menu->addSeparator();
977 act = menu->addAction(
_(
"Building Units"));
978 act->setData(
"unit");
980 act = menu->addAction(
_(
"Building Improvements"));
981 act->setData(
"impr");
983 act = menu->addAction(
_(
"Building Wonders"));
984 act->setData(
"wonder");
986 menu->addSeparator();
987 tmp_menu = menu->addMenu(
_(
"Improvements in City"));
991 tmp_menu = menu->addMenu(
_(
"Wonders in City"));
995 menu->addSeparator();
996 tmp_menu = menu->addMenu(
_(
"Supported Units"));
1000 tmp_menu = menu->addMenu(
_(
"Units Present"));
1004 menu->addSeparator();
1005 tmp_menu = menu->addMenu(
_(
"Available Units"));
1009 tmp_menu = menu->addMenu(
_(
"Available Improvements"));
1013 tmp_menu = menu->addMenu(
_(
"Available Wonders"));
1034 QMap<QString, cid> &
list,
1036 bool append_wonders,
1042 int i,
item, targets_used;
1046 struct city **city_data;
1059 city_data[i] = pcity;
1063 for (i = 0; i < num_sel; i++) {
1072 for (i = 0; i < 4; i++) {
1083 str =
str + QString(txt);
1102 QFont f = QApplication::font();
1108 setUpdatesEnabled(
false);
1111 header()->resizeSections(QHeaderView::ResizeToContents);
1112 for (
int j = 0; j <
filter_model->columnCount(); j++) {
1114 if (
str.contains(
'\n')) {
1115 sl =
str.split(
'\n');
1118 width = qMax(
width, fm.horizontalAdvance(s));
1120 header()->resizeSection(j,
width + 10);
1123 setUpdatesEnabled(
true);
1131 QMenu *hideshow_column =
new QMenu(
this);
1134 hideshow_column->setTitle(
_(
"Column visibility"));
1136 QAction *myAct = hideshow_column->addAction(
1138 myAct->setCheckable(
true);
1139 myAct->setChecked(!isColumnHidden(i));
1142 hideshow_column->setAttribute(Qt::WA_DeleteOnClose);
1143 connect(hideshow_column, &QMenu::triggered,
this,
1153 setColumnHidden(col, !isColumnHidden(col));
1156 if (!isColumnHidden(col) && columnWidth(col) <= 5)
1157 setColumnWidth(col, 100);
1159 hideshow_column->popup(QCursor::pos());
1171 setColumnHidden(col, !isColumnHidden(col));
1181 const QItemSelection &ds)
1183 QModelIndexList indexes = selectionModel()->selectedIndexes();
1190 if (indexes.isEmpty()) {
1193 foreach(i,indexes) {
1194 qvar = i.data(Qt::UserRole);
1195 if (qvar.isNull()) {
1198 pcity =
reinterpret_cast<city *
>(qvar.value<
void *>());
1219 gui()->qt_settings.city_repo_sort_col = header()->sortIndicatorSection();
1220 gui()->qt_settings.city_report_sort = header()->sortIndicatorOrder();
1228 layout =
new QVBoxLayout;
1230 if (
gui()->qt_settings.city_repo_sort_col != -1) {
1231 city_wdg->sortByColumn(
gui()->qt_settings.city_repo_sort_col,
1232 gui()->qt_settings.city_report_sort);
1243 gui()->remove_repo_dlg(
"CTS");
1251 gui()->gimme_place(
this,
"CTS");
1253 gui()->game_tab_widget->setCurrentIndex(
index);
1281 if (!
gui()->is_repo_dlg_open(
"CTS")) {
1286 i =
gui()->gimme_index_of(
"CTS");
1288 w =
gui()->game_tab_widget->widget(i);
1289 if (w->isVisible()) {
1290 gui()->game_tab_widget->setCurrentIndex(0);
1294 gui()->game_tab_widget->setCurrentWidget(cr);
1308 if (
gui()->is_repo_dlg_open(
"CTS")) {
1309 i =
gui()->gimme_index_of(
"CTS");
1310 if (
gui()->game_tab_widget->currentIndex() == i) {
1311 w =
gui()->game_tab_widget->widget(i);
1327 if (
gui()->is_repo_dlg_open(
"CTS")) {
1328 i =
gui()->gimme_index_of(
"CTS");
1329 if (
gui()->game_tab_widget->currentIndex() == i) {
1330 w =
gui()->game_tab_widget->widget(i);
1346 if (
gui()->is_repo_dlg_open(
"CTS")) {
1347 i =
gui()->gimme_index_of(
"CTS");
1349 w =
gui()->game_tab_widget->widget(i);
static struct action * actions[MAX_NUM_ACTIONS]
struct canvas int int struct sprite int int int width
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
bool can_city_build_now(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
#define cities_iterate_end
#define city_list_iterate(citylist, pcity)
#define cities_iterate(pcity)
#define city_list_iterate_end
void qtg_real_city_dialog_popup(struct city *pcity)
void get_city_dialog_production_row(char *buf[], size_t column_size, struct universal *target, struct city *pcity)
int city_set_worklist(struct city *pcity, const struct worklist *pworklist)
int city_buy_production(struct city *pcity)
bool city_queue_insert(struct city *pcity, int position, struct universal *item)
bool city_queue_insert_worklist(struct city *pcity, int position, const struct worklist *worklist)
bool city_set_queue(struct city *pcity, const struct worklist *pqueue)
int city_change_production(struct city *pcity, struct universal *target)
int city_sell_improvement(struct city *pcity, Impr_type_id sell_id)
bool city_can_buy(const struct city *pcity)
void real_city_report_dialog_update(void *unused)
void real_city_report_update_city(struct city *pcity)
void toggle_city_hilite(struct city *pcity, bool on_off)
void hilite_cities_from_canvas(void)
void city_report_dialog_popup(bool raise)
void popdown_city_report()
bool can_city_sell_universal(const struct city *pcity, const struct universal *target)
struct city_report_spec * city_report_specs
int cityrepfield_compare(const char *str1, const char *str2)
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
city_item_delegate(QObject *parent)
QVariant data(int column, int role=Qt::DisplayRole) const
city_item(struct city *pcity)
bool setData(int column, const QVariant &value, int role=Qt::DisplayRole)
void city_changed(struct city *pcity)
QVariant headerData(int section, Qt::Orientation orientation, int role) const
QVariant hide_data(int section) const
int columnCount(const QModelIndex &parent=QModelIndex()) const
QVariant menu_data(int section) const
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
QList< city_item * > city_list
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::DisplayRole)
city_model(QObject *parent=0)
int rowCount(const QModelIndex &index=QModelIndex()) const
void notify_city_changed(int row)
void update_city(struct city *pcity)
bool lessThan(const QModelIndex &left, const QModelIndex &right) const
int set_text_title(QString s1, QString s2, bool return_exec=false)
bool can_client_issue_orders(void)
bool client_has_player(void)
bool city_unit_supported(const struct city *pcity, const struct universal *target)
void cityrep_buy(struct city *pcity)
void name_and_sort_items(struct universal *targets, int num_targets, struct item *items, bool show_cost, struct city *pcity)
cid cid_encode(struct universal target)
bool city_building_present(const struct city *pcity, const struct universal *target)
struct universal cid_decode(cid id)
bool can_city_build_now_client(const struct city *pcity, const struct universal *target)
bool city_unit_present(const struct city *pcity, const struct universal *target)
int collect_production_targets(struct universal *targets, struct city **selected_cities, int num_selected_cities, bool append_units, bool append_wonders, bool change_prod, TestCityFunc test_func)
#define MAX_NUM_PRODUCTION_TARGETS
bool(* TestCityFunc)(const struct city *, const struct universal *)
static struct fc_sockaddr_list * list
void cma_put_city_under_agent(struct city *pcity, const struct cm_parameter *const parameter)
void cma_release_city(struct city *pcity)
char * cmafec_preset_get_descr(int idx)
const struct cm_parameter * cmafec_preset_get_parameter(int idx)
int cmafec_preset_num(void)
struct city * game_city_by_number(int id)
struct global_worklist * global_worklist_by_id(int id)
const char * global_worklist_name(const struct global_worklist *pgwl)
int global_worklist_id(const struct global_worklist *pgwl)
const struct worklist * global_worklist_get(const struct global_worklist *pgwl)
#define global_worklists_iterate(pgwl)
#define global_worklists_iterate_end
#define CAPTURE_DEFAULT_THIS
struct impr_type * improvement_by_number(const Impr_type_id id)
Impr_type_id improvement_number(const struct impr_type *pimprove)
bool is_wonder(const struct impr_type *pimprove)
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
const char * improvement_name_translation(const struct impr_type *pimprove)
#define fc_assert_ret(condition)
#define fc_assert(condition)
void center_tile_mapcanvas(const struct tile *ptile)
struct client_options gui_options
struct city_list * cities
const char *(* func)(const struct city *pcity, const void *data)
struct universal production
struct city::@17::@20 client
bool center_when_popup_city
struct city_list * cities
int fc_snprintf(char *str, size_t n, const char *format,...)
bool is_terrain_class_near_tile(const struct civ_map *nmap, const struct tile *ptile, enum terrain_class tclass)
#define tile_continent(_tile)
const struct impr_type * building
void worklist_init(struct worklist *pwl)
int worklist_length(const struct worklist *pwl)