Freeciv-3.4
Loading...
Searching...
No Matches
cityrep.cpp
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#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18// Qt
19#include <QApplication>
20#include <QHeaderView>
21#include <QVBoxLayout>
22
23// client
24#include "client_main.h"
25
26// gui-qt
27#include "cityrep.h"
28#include "fc_client.h"
29#include "gui_main.h"
30#include "hudwidget.h"
31
32/***********************************************************************/
36 const QModelIndex &right) const
37{
40 int i;
43
44 qleft = sourceModel()->data(left);
45 qright = sourceModel()->data(right);
46 l_bytes = qleft.toString().toUtf8();
47 r_bytes = qright.toString().toUtf8();
48 i = cityrepfield_compare(l_bytes.data(), r_bytes.data());
49
50 if (i >= 0) {
51 return true;
52 } else {
53 return false;
54 }
55}
56
57
58/***********************************************************************/
62 :QItemDelegate(parent)
63{
64 QFont f = QApplication::font();
66
67 item_height = fm.height() + 4;
68}
69
70/***********************************************************************/
75 const QModelIndex &index) const
76{
77 QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option);
79 QFont font;
81 struct city_report_spec *spec;
82 spec = city_report_specs + index.column();
83 txt = spec->tagname;
84 if (txt == "cityname") {
85 font.setCapitalization(QFont::SmallCaps);
86 font.setBold(true);
87 opt.font = font;
88 }
89 if (txt == "hstate_verbose") {
90 font.setItalic(true);
91 opt.font = font;
92 }
93 if (txt == "prodplus") {
94 txt = index.data().toString();
95 if (txt.toInt() < 0) {
96 font.setBold(true);
97 palette.setColor(QPalette::Text, QColor(255, 0, 0));
98 opt.font = font;
99 opt.palette = palette;
100 }
101 }
102
103 QItemDelegate::paint(painter, opt, index);
104}
105
106/***********************************************************************/
110 const QModelIndex &index) const
111{
112 QSize s = QItemDelegate::sizeHint(option, index);
113
114 s.setHeight(item_height + 4);
115 return s;
116}
117
118/***********************************************************************/
122{
123 i_city = pcity;
124}
125
126/***********************************************************************/
130{
131 return i_city;
132}
133
134/***********************************************************************/
137bool city_item::setData(int column, const QVariant &value, int role)
138{
139 return false;
140}
141
142/***********************************************************************/
146{
147 struct city_report_spec *spec;
148 char buf[64];
149
150 if (role == Qt::UserRole && column == 0) {
151 return QVariant::fromValue((void *)i_city);
152 }
153 if (role != Qt::DisplayRole) {
154 return QVariant();
155 }
157 fc_snprintf(buf, sizeof(buf), "%*s", NEG_VAL(spec->width),
158 spec->func(i_city, spec->data));
159 return QString(buf).trimmed();
160}
161
162/***********************************************************************/
165city_model::city_model(QObject *parent): QAbstractListModel(parent)
166{
167 populate();
168}
169
170/***********************************************************************/
178
179/***********************************************************************/
183{
184 emit dataChanged(index(row, 0), index(row, columnCount() - 1));
185}
186
187/***********************************************************************/
191{
192 if (!index.isValid()) {
193 return QVariant();
194 }
195 if (index.row() >= 0 && index.row() < rowCount() && index.column() >= 0
196 && index.column() < columnCount()) {
197 return city_list[index.row()]->data(index.column(), role);
198 }
199 return QVariant();
200}
201
202/***********************************************************************/
205bool city_model::setData(const QModelIndex &index, const QVariant &value,
206 int role)
207{
208 if (!index.isValid() || role != Qt::DisplayRole) {
209 return false;
210 }
211 if (index.row() >= 0 && index.row() < rowCount() && index.column() >= 0
212 && index.column() < columnCount()) {
213 bool change = city_list[index.row()]->setData(index.column(), value, role);
214
215 if (change) {
216 notify_city_changed(index.row());
217 }
218 return change;
219 }
220 return false;
221}
222
223/***********************************************************************/
227 int role) const
228{
229 char buf[64];
230 struct city_report_spec *spec;
231
232 if (orientation == Qt::Horizontal && section < NUM_CREPORT_COLS) {
233 if (role == Qt::DisplayRole) {
234 spec = city_report_specs + section;
235 fc_snprintf(buf, sizeof(buf), "%*s\n%*s",
236 NEG_VAL(spec->width), spec->title1 ? spec->title1 : "",
237 NEG_VAL(spec->width), spec->title2 ? spec->title2 : "");
238 return QString(buf).trimmed();
239 }
240 if (role == Qt::ToolTipRole) {
241 spec = city_report_specs + section;
242 return QString(spec->explanation);
243 }
244 }
245 return QVariant();
246}
247
248/***********************************************************************/
252{
253 struct city_report_spec *spec;
254
256 spec = city_report_specs + section;
257 return QString(spec->explanation);
258 }
259 return QVariant();
260}
261
262/***********************************************************************/
266{
267 struct city_report_spec *spec;
268
270 spec = city_report_specs + section;
271 return spec->show;
272 }
273 return QVariant();
274}
275
276/***********************************************************************/
280{
281 city_item *ci;
282
283 if (client_has_player()) {
285 ci = new city_item(pcity);
286 city_list << ci;
288 } else {
290 ci = new city_item(pcity);
291 city_list << ci;
293 }
294}
295
296/***********************************************************************/
300{
302
305 for (int i = 0; i < city_list.count(); i++) {
306 item = city_list.at(i);
307 if (pcity == item->get_city()) {
309 }
310 }
311}
312
313/***********************************************************************/
317{
318 city_list.clear();
320 populate();
322}
323
324/***********************************************************************/
328{
329 QItemSelection selection;
331 struct city *pcity;
333
334 if (selected_cities.isEmpty()) {
335 return;
336 }
337 for (int j = 0; j < filter_model->rowCount(); j++) {
338 i = filter_model->index(j, 0);
339 qvar = i.data(Qt::UserRole);
340 if (qvar.isNull()) {
341 continue;
342 }
343 pcity = reinterpret_cast<city *>(qvar.value<void *>());
344 if (selected_cities.contains(pcity)) {
345 selection.append(QItemSelectionRange(i));
346 }
347 }
348 selectionModel()->select(selection, QItemSelectionModel::Rows
349 | QItemSelectionModel::SelectCurrent);
350}
351
352/***********************************************************************/
356{
357 cr = ctr;
358 c_i_d = new city_item_delegate(this);
360 list_model = new city_model(this);
362 filter_model->setDynamicSortFilter(true);
363 filter_model->setSourceModel(list_model);
364 filter_model->setFilterRole(Qt::DisplayRole);
366 setRootIsDecorated(false);
368 setSortingEnabled(true);
369 setSelectionMode(QAbstractItemView::ExtendedSelection);
370 setSelectionBehavior(QAbstractItemView::SelectRows);
371 setItemsExpandable(false);
372 setAutoScroll(true);
373 setProperty("uniformRowHeights", "true");
375 header()->setContextMenuPolicy(Qt::CustomContextMenu);
376 header()->setMinimumSectionSize(10);
377 setContextMenuPolicy(Qt::CustomContextMenu);
378 hide_columns();
379 connect(header(), &QWidget::customContextMenuRequested,
381 connect(selectionModel(),
383 const QItemSelection &)),
385 const QItemSelection &)));
386 connect(this, &QAbstractItemView::doubleClicked, this,
388 connect(this, &QWidget::customContextMenuRequested,
390}
391
392/***********************************************************************/
396{
397 city_view();
398}
399
400/***********************************************************************/
404{
405 struct city *pcity;
406
407 if (selected_cities.isEmpty()) {
408 return;
409 }
411
412 Q_ASSERT(pcity != nullptr);
415 }
417}
418
419/***********************************************************************/
423{
424 struct worklist empty;
426 struct city *pcity;
427
428 foreach(pcity, selected_cities) {
429 Q_ASSERT(pcity != nullptr);
431 }
432}
433
434/***********************************************************************/
438{
439 struct city *pcity;
440
441 foreach(pcity, selected_cities) {
442 Q_ASSERT(pcity != nullptr);
444 }
445}
446
447/***********************************************************************/
451{
452 struct city *pcity;
453
454 if (selected_cities.isEmpty()) {
455 return;
456 }
458 Q_ASSERT(pcity != nullptr);
460 gui()->game_tab_widget->setCurrentIndex(0);
461}
462
463/***********************************************************************/
467{
470 QMenu *some_menu;
471 QMenu *tmp2_menu;
472 QMenu *tmp_menu;
473 struct city *pcity_outer;
474 QMenu *list_menu;
475
476 QAction wl_clear(_("Clear"), 0);
477 QAction wl_empty(_("(no worklists defined)"), 0);
478 bool worklist_defined = true;
479
481 return;
482 }
483 list_menu = new QMenu(this);
484 if (!selected_cities.isEmpty()) {
485 some_menu = list_menu->addMenu(_("Production"));
486 tmp_menu = some_menu->addMenu(_("Change"));
488 tmp_menu);
489 tmp_menu = some_menu->addMenu(_("Add next"));
491 tmp_menu);
492 tmp_menu = some_menu->addMenu(_("Add before last"));
495 tmp_menu = some_menu->addMenu(_("Add last"));
497 tmp_menu);
498
499 tmp_menu = some_menu->addMenu(_("Worklist"));
500 tmp_menu->addAction(&wl_clear);
501 connect(&wl_clear, &QAction::triggered, this, &city_widget::clear_worlist);
502 tmp2_menu = tmp_menu->addMenu(_("Add"));
504 if (cma_labels.count() == 0) {
505 tmp2_menu->addAction(&wl_empty);
506 worklist_defined = false;
507 }
509 tmp2_menu = tmp_menu->addMenu(_("Change"));
510 if (cma_labels.count() == 0) {
511 tmp2_menu->addAction(&wl_empty);
512 worklist_defined = false;
513 }
515 some_menu = list_menu->addMenu(_("Governor"));
518 some_menu = list_menu->addMenu(_("Sell"));
522 }
523 some_menu = list_menu->addMenu(_("Select"));
525 if (!selected_cities.isEmpty()) {
526 char buy_costs_label[200];
527 int buy_costs = 0;
528
529 some_menu = list_menu->addMenu(_("City/Buy"));
530 if (selected_cities.count() == 1) {
531 connect(some_menu->addAction(_("View")), &QAction::triggered, this,
533 connect(some_menu->addAction(_("Center")), &QAction::triggered, this,
535 }
536
537 foreach(pcity_outer, selected_cities) {
538 buy_costs = buy_costs + pcity_outer->client.buy_cost;
539 }
541 _("Buy ( Cost: %d )"), buy_costs);
542 connect(some_menu->addAction(buy_costs_label), &QAction::triggered, this,
544 }
545
546 list_menu->setAttribute(Qt::WA_DeleteOnClose);
547 connect(list_menu, &QMenu::triggered, this,
550 enum menu_labels m_state;
551 cid id;
552 struct universal target;
553 char buf[200];
554 const char *imprname;
555 const struct impr_type *building_outer;
557 struct city *pcity_mid;
558 int city_id;
559 bool need_clear = true;
560 bool sell_ask = true;
561
562 if (!act) {
563 return;
564 }
565
566 qvar2 = act->property("FC");
567 m_state = static_cast<menu_labels>(qvar2.toInt());
568 qvar = act->data();
569 id = qvar.toInt();
570 target = cid_decode(id);
571
573 if (iter_city != nullptr) {
574 switch (m_state) {
575 case SELECT_IMPR:
576 if (need_clear) {
578 }
579 need_clear = false;
580 if (city_building_present(iter_city, &target)) {
582 }
583 break;
584 case SELECT_WONDERS:
585 if (need_clear) {
587 }
588 need_clear = false;
589 if (city_building_present(iter_city, &target)) {
591 }
592 break;
594 if (need_clear) {
596 }
597 need_clear = false;
598 if (city_unit_supported(iter_city, &target)) {
600 }
601 break;
603 if (need_clear) {
605 }
606 need_clear = false;
607 if (city_unit_present(iter_city, &target)) {
609 }
610 break;
612 if (need_clear) {
614 }
615 need_clear = false;
616 if (can_city_build_now(&(wld.map), iter_city, &target,
617 RPT_CERTAIN)) {
619 }
620 break;
622 if (need_clear) {
624 }
625 need_clear = false;
626 if (can_city_build_now(&(wld.map), iter_city, &target,
627 RPT_CERTAIN)) {
629 }
630 break;
632 if (need_clear) {
634 }
635 need_clear = false;
636 if (can_city_build_now(&(wld.map), iter_city, &target,
637 RPT_CERTAIN)) {
639 }
640 break;
641 default:
642 break;
643 }
644 }
646
647 foreach (pcity_mid, selected_cities) {
648 if (pcity_mid != nullptr) {
649 switch (m_state) {
650 case CHANGE_PROD_NOW:
652 break;
653 case CHANGE_PROD_NEXT:
654 city_queue_insert(pcity_mid, 1, &target);
655 break;
658 &target);
659 break;
660 case CHANGE_PROD_LAST:
661 city_queue_insert(pcity_mid, -1, &target);
662 break;
663 case SELL:
665 if (sell_ask) {
666 hud_message_box *ask = new hud_message_box(gui()->central_wdg);
667
669 fc_snprintf(buf, sizeof(buf),
670 _("Are you sure you want to sell those %s?"),
671 imprname);
672 sell_ask = false;
673 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
674 ask->setDefaultButton(QMessageBox::Cancel);
675 ask->set_text_title(buf, _("Sell?"));
676 ask->setAttribute(Qt::WA_DeleteOnClose);
677 city_id = pcity_mid->id;
679 connect(ask, &hud_message_box::accepted, this, [=]() {
680 struct city *pcity = game_city_by_number(city_id);
681 struct impr_type *building = improvement_by_number(impr_id);
682
683 if (!pcity || !building) {
684 return;
685 }
686 if (!pcity->did_sell && city_has_building(pcity, building)) {
688 }
689 });
690 ask->show();
691 }
692 break;
693 case CMA:
694 if (pcity_mid != nullptr) {
695 if (CMA_NONE == id) {
697 } else {
700 }
701 }
702
703 break;
704 case WORKLIST_ADD:
705 if (worklist_defined) {
708 }
709 break;
710
711 case WORKLIST_CHANGE:
712 if (worklist_defined) {
715 }
716 break;
717 case BUY:
718 if (pcity_mid != nullptr) {
719 if (city_can_buy(pcity_mid)) {
721 }
722 }
723 break;
724 default:
725 break;
726 }
727 }
728 }
729 });
730 list_menu->popup(QCursor::pos());
731}
732
733/***********************************************************************/
738 TestCityFunc test_func, QMenu *menu)
739{
740 QMenu *m1, *m2, *m3;
741
742 m1 = menu->addMenu(_("Buildings"));
743 m2 = menu->addMenu(_("Units"));
744 m3 = menu->addMenu(_("Wonders"));
751}
752
753
754/***********************************************************************/
758 QMap<QString, cid> &custom_labels, QMenu *menu)
759{
761 QMap<QString, cid>::const_iterator map_iter;
762
763 map_iter = custom_labels.constBegin();
764 while (map_iter != custom_labels.constEnd()) {
765 action = menu->addAction(map_iter.key());
766 action->setData(map_iter.value());
767 action->setProperty("FC", which);
768 map_iter++;
769 }
770 if (custom_labels.isEmpty()) {
771 menu->setDisabled(true);
772 }
773}
774
775/***********************************************************************/
779{
780 selectAll();
781}
782
783/***********************************************************************/
790
791/***********************************************************************/
795{
796 QItemSelection selection;
798 struct city *pcity;
800
801 for (int j = 0; j < filter_model->rowCount(); j++) {
802 i = filter_model->index(j, 0);
803 qvar = i.data(Qt::UserRole);
804 if (qvar.isNull()) {
805 continue;
806 }
807 pcity = reinterpret_cast<city *>(qvar.value<void *>());
808 if (!selected_cities.contains(pcity)) {
809 selection.append(QItemSelectionRange(i));
810 }
811 }
813 selectionModel()->select(selection, QItemSelectionModel::Rows
814 | QItemSelectionModel::SelectCurrent);
815
816}
817
818/***********************************************************************/
822{
823 QItemSelection selection;
825 struct city *pcity;
827
828 for (int j = 0; j < filter_model->rowCount(); j++) {
829 i = filter_model->index(j, 0);
830 qvar = i.data(Qt::UserRole);
831 if (qvar.isNull()) {
832 continue;
833 }
834 pcity = reinterpret_cast<city *>(qvar.value<void *>());
835 if (pcity == spcity) {
836 selection.append(QItemSelectionRange(i));
837 }
838 }
839 selectionModel()->select(selection, QItemSelectionModel::Rows
840 | QItemSelectionModel::Select);
841
842}
843
844/***********************************************************************/
848{
849 QItemSelection selection;
851 struct city *pcity;
853
855 for (int j = 0; j < filter_model->rowCount(); j++) {
856 i = filter_model->index(j, 0);
857 qvar = i.data(Qt::UserRole);
858 if (qvar.isNull()) {
859 continue;
860 }
861 pcity = reinterpret_cast<city *>(qvar.value<void *>());
862 if (pcity != nullptr
864 selection.append(QItemSelectionRange(i));
865 }
866 }
867 selectionModel()->select(selection, QItemSelectionModel::Rows
868 | QItemSelectionModel::SelectCurrent);
869}
870
871/***********************************************************************/
875{
876 QItemSelection selection;
878 struct city *pcity;
879 struct city *pscity;
881
882 for (int j = 0; j < filter_model->rowCount(); j++) {
883 i = filter_model->index(j, 0);
884 qvar = i.data(Qt::UserRole);
885 if (qvar.isNull()) {
886 continue;
887 }
888 pcity = reinterpret_cast<city *>(qvar.value<void *>());
889 foreach (pscity, selected_cities) {
890 if (pcity != nullptr
892 == tile_continent(pscity->tile))) {
893 selection.append(QItemSelectionRange(i));
894 }
895 }
896 }
897 selectionModel()->select(selection, QItemSelectionModel::Rows
898 | QItemSelectionModel::SelectCurrent);
899}
900
901/***********************************************************************/
906{
907 QItemSelection selection;
909 struct city *pcity;
911 QAction *act;
912 QString str;
913
915 for (int j = 0; j < filter_model->rowCount(); j++) {
916 i = filter_model->index(j, 0);
917 qvar = i.data(Qt::UserRole);
918 if (qvar.isNull()) {
919 continue;
920 }
921 pcity = reinterpret_cast<city *>(qvar.value<void *>());
923 qvar = act->data();
924 str = qvar.toString();
925 if (pcity != nullptr) {
926 if (str == "impr" && VUT_IMPROVEMENT == pcity->production.kind
927 && !is_wonder(pcity->production.value.building)
928 && !is_convert_improvement(pcity->production.value.building)) {
929 selection.append(QItemSelectionRange(i));
930 } else if (str == "unit" && VUT_UTYPE == pcity->production.kind) {
931 selection.append(QItemSelectionRange(i));
932 } else if (str == "wonder"
933 && VUT_IMPROVEMENT == pcity->production.kind
934 && is_wonder(pcity->production.value.building)) {
935 selection.append(QItemSelectionRange(i));
936 }
937 }
938 }
939 selectionModel()->select(selection, QItemSelectionModel::Rows
940 | QItemSelectionModel::SelectCurrent);
941}
942
943/***********************************************************************/
947{
948 list.clear();
949 for (int i = 0; i < cmafec_preset_num(); i++) {
951 }
952}
953
954/***********************************************************************/
958{
959 QAction *act;
960 QMenu *tmp_menu;
962
963 act = menu->addAction(_("All Cities"));
964 connect(act, &QAction::triggered, this, &city_widget::select_all);
965 act = menu->addAction(_("No Cities"));
966 connect(act, &QAction::triggered, this, &city_widget::select_none);
967 act = menu->addAction(_("Invert Selection"));
968 connect(act, &QAction::triggered, this, &city_widget::invert_selection);
969 menu->addSeparator();
970 act = menu->addAction(_("Coastal Cities"));
971 connect(act, &QAction::triggered, this, &city_widget::select_coastal);
972 act = menu->addAction(_("Same Island"));
973 connect(act, &QAction::triggered, this, &city_widget::select_same_island);
974 if (selected_cities.isEmpty()) {
975 act->setDisabled(true);
976 }
977 menu->addSeparator();
978 act = menu->addAction(_("Building Units"));
979 act->setData("unit");
980 connect(act, &QAction::triggered, this, &city_widget::select_building_something);
981 act = menu->addAction(_("Building Improvements"));
982 act->setData("impr");
983 connect(act, &QAction::triggered, this, &city_widget::select_building_something);
984 act = menu->addAction(_("Building Wonders"));
985 act->setData("wonder");
986 connect(act, &QAction::triggered, this, &city_widget::select_building_something);
987 menu->addSeparator();
988 tmp_menu = menu->addMenu(_("Improvements in City"));
992 tmp_menu = menu->addMenu(_("Wonders in City"));
996 menu->addSeparator();
997 tmp_menu = menu->addMenu(_("Supported Units"));
999 city_unit_supported, true);
1001 tmp_menu = menu->addMenu(_("Units Present"));
1003 city_unit_present, true);
1005 menu->addSeparator();
1006 tmp_menu = menu->addMenu(_("Available Units"));
1010 tmp_menu = menu->addMenu(_("Available Improvements"));
1014 tmp_menu = menu->addMenu(_("Available Wonders"));
1018}
1019
1020/***********************************************************************/
1030
1031/***********************************************************************/
1036 bool append_units,
1037 bool append_wonders,
1039 bool global)
1040{
1041 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
1042 struct item items[MAX_NUM_PRODUCTION_TARGETS];
1043 int i, item, targets_used;
1044 QString str;
1045 char *row[4];
1046 char buf[4][64];
1047 struct city **city_data;
1048 int num_sel = 0;
1049
1050 if (global) {
1052 } else {
1053 num_sel = selected_cities.count();
1054 }
1055 city_data = (struct city **)fc_malloc(sizeof(struct city *) * num_sel);
1056
1057 if (global) {
1058 i = 0;
1060 city_data[i] = pcity;
1061 i++;
1063 } else {
1064 for (i = 0; i < num_sel; i++) {
1066 }
1067 }
1070 append_wonders, true, test_func);
1071 free(city_data);
1072 name_and_sort_items(targets, targets_used, items, true, nullptr);
1073 for (i = 0; i < 4; i++) {
1074 row[i] = buf[i];
1075 }
1076 list.clear();
1077 for (item = 0; item < targets_used; item++) {
1078 struct universal target = items[item].item;
1079 char txt[256];
1080
1081 str.clear();
1082 get_city_dialog_production_row(row, sizeof(buf[0]), &target, nullptr);
1083 fc_snprintf(txt, ARRAY_SIZE(txt), "%s ", row[0]);
1084 str = str + QString(txt);
1085 list.insert(str, cid_encode(target));
1086 }
1087}
1088
1089/***********************************************************************/
1097
1098/***********************************************************************/
1102{
1103 QFont f = QApplication::font();
1104 QFontMetrics fm(f);
1106 QString s, str;
1107 int width;
1108
1109 setUpdatesEnabled(false);
1112 header()->resizeSections(QHeaderView::ResizeToContents);
1113 for (int j = 0; j < filter_model->columnCount(); j++) {
1114 str = list_model->headerData(j, Qt::Horizontal, Qt::DisplayRole).toString();
1115 if (str.contains('\n')) {
1116 sl = str.split('\n');
1117 width = 0;
1118 foreach (s, sl) {
1119 width = qMax(width, fm.horizontalAdvance(s));
1120 }
1121 header()->resizeSection(j, width + 10);
1122 }
1123 }
1124 setUpdatesEnabled(true);
1125}
1126
1127/***********************************************************************/
1131{
1132 QMenu *hideshow_column = new QMenu(this);
1134
1135 hideshow_column->setTitle(_("Column visibility"));
1136 for (int i = 0; i < list_model->columnCount(); i++) {
1137 QAction *myAct = hideshow_column->addAction(
1138 list_model->menu_data(i).toString());
1139 myAct->setCheckable(true);
1140 myAct->setChecked(!isColumnHidden(i));
1141 actions.append(myAct);
1142 }
1143 hideshow_column->setAttribute(Qt::WA_DeleteOnClose);
1144 connect(hideshow_column, &QMenu::triggered, this,
1146 int col;
1147 struct city_report_spec *spec;
1148 if (!act) {
1149 return;
1150 }
1151
1152 col = actions.indexOf(act);
1153 fc_assert_ret(col >= 0);
1155 spec = city_report_specs + col;
1156 spec->show = !spec->show;
1157 if (!isColumnHidden(col) && columnWidth(col) <= 5)
1158 setColumnWidth(col, 100);
1159 });
1160 hideshow_column->popup(QCursor::pos());
1161}
1162
1163/***********************************************************************/
1167{
1168 int col;
1169
1170 for (col = 0; col < list_model->columnCount(); col++) {
1171 if (!list_model->hide_data(col).toBool()) {
1173 }
1174 }
1175}
1176
1177/***********************************************************************/
1182 const QItemSelection &ds)
1183{
1184 QModelIndexList indexes = selectionModel()->selectedIndexes();
1185 QModelIndex i;
1186 QVariant qvar;
1187 struct city *pcity;
1188
1189 selected_cities.clear();
1190
1191 if (indexes.isEmpty()) {
1192 return;
1193 }
1194 foreach(i,indexes) {
1195 qvar = i.data(Qt::UserRole);
1196 if (qvar.isNull()) {
1197 continue;
1198 }
1199 pcity = reinterpret_cast<city *>(qvar.value<void *>());
1201 }
1202}
1203
1204/***********************************************************************/
1208{
1209 return list_model;
1210}
1211
1212/***********************************************************************/
1216{
1217 delete c_i_d;
1218 delete list_model;
1219 delete filter_model;
1220 gui()->qt_settings.city_repo_columns = header()->saveState();
1221}
1222
1223/***********************************************************************/
1227{
1228 layout = new QVBoxLayout;
1229 city_wdg = new city_widget(this);
1230 if (!gui()->qt_settings.city_repo_columns.isEmpty()) {
1231 city_wdg->header()->restoreState(gui()->qt_settings.city_repo_columns);
1232 }
1233 layout->addWidget(city_wdg);
1235}
1236
1237/***********************************************************************/
1241{
1242 gui()->remove_repo_dlg("CTS");
1243}
1244
1245/***********************************************************************/
1249{
1250 gui()->gimme_place(this, "CTS");
1251 index = gui()->add_game_tab(this);
1252 gui()->game_tab_widget->setCurrentIndex(index);
1253}
1254
1255/***********************************************************************/
1262
1263/***********************************************************************/
1270
1271/***********************************************************************/
1275{
1276 int i;
1277 city_report *cr;
1278 QWidget *w;
1279
1280 if (!gui()->is_repo_dlg_open("CTS")) {
1281 cr = new city_report;
1282 cr->init();
1283 cr->update_report();
1284 } else {
1285 i = gui()->gimme_index_of("CTS");
1286 fc_assert(i != -1);
1287 w = gui()->game_tab_widget->widget(i);
1288 if (w->isVisible()) {
1289 gui()->game_tab_widget->setCurrentIndex(0);
1290 return;
1291 }
1292 cr = reinterpret_cast<city_report*>(w);
1293 gui()->game_tab_widget->setCurrentWidget(cr);
1294 cr->update_report();
1295 }
1296}
1297
1298/***********************************************************************/
1302{
1303 int i;
1304 city_report *cr;
1305 QWidget *w;
1306
1307 if (gui()->is_repo_dlg_open("CTS")) {
1308 i = gui()->gimme_index_of("CTS");
1309 if (gui()->game_tab_widget->currentIndex() == i) {
1310 w = gui()->game_tab_widget->widget(i);
1311 cr = reinterpret_cast<city_report *>(w);
1312 cr->update_report();
1313 }
1314 }
1315}
1316
1317/***********************************************************************/
1321{
1322 int i;
1323 city_report *cr;
1324 QWidget *w;
1325
1326 if (gui()->is_repo_dlg_open("CTS")) {
1327 i = gui()->gimme_index_of("CTS");
1328 if (gui()->game_tab_widget->currentIndex() == i) {
1329 w = gui()->game_tab_widget->widget(i);
1330 cr = reinterpret_cast<city_report *>(w);
1331 cr->update_city(pcity);
1332 }
1333 }
1334}
1335
1336/***********************************************************************/
1340{
1341 int i;
1342 city_report *cr;
1343 QWidget *w;
1344
1345 if (gui()->is_repo_dlg_open("CTS")) {
1346 i = gui()->gimme_index_of("CTS");
1347 fc_assert(i != -1);
1348 w = gui()->game_tab_widget->widget(i);
1349 cr = reinterpret_cast<city_report *>(w);
1350 cr->deleteLater();
1351 }
1352}
1353
1354/***********************************************************************/
1360{
1361 // PORTME
1362}
1363
1364/***********************************************************************/
1368{
1369 // PORTME
1370}
static struct action * actions[MAX_NUM_ACTIONS]
Definition actions.c:57
#define str
Definition astring.c:76
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1296
bool can_city_build_now(const struct civ_map *nmap, const struct city *pcity, const struct universal *target, const enum req_problem_type prob_type)
Definition city.c:1028
#define cities_iterate_end
Definition city.h:517
#define city_list_iterate(citylist, pcity)
Definition city.h:508
#define cities_iterate(pcity)
Definition city.h:512
#define city_list_iterate_end
Definition city.h:510
void qtg_real_city_dialog_popup(struct city *pcity)
Definition citydlg.cpp:3833
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)
Definition cityrep.cpp:1301
void real_city_report_update_city(struct city *pcity)
Definition cityrep.cpp:1320
void toggle_city_hilite(struct city *pcity, bool on_off)
Definition cityrep.cpp:1367
void hilite_cities_from_canvas(void)
Definition cityrep.cpp:1359
void city_report_dialog_popup(bool raise)
Definition cityrep.cpp:1274
void popdown_city_report()
Definition cityrep.cpp:1339
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)
#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
city_item_delegate(QObject *parent)
Definition cityrep.cpp:61
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
city_item(struct city *pcity)
Definition cityrep.cpp:121
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
city_model(QObject *parent=0)
Definition cityrep.cpp:165
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:1248
QVBoxLayout * layout
Definition cityrep.h:206
void update_report()
Definition cityrep.cpp:1258
city_widget * city_wdg
Definition cityrep.h:205
void update_city(struct city *pcity)
Definition cityrep.cpp:1266
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:821
city_widget(city_report *ctr)
Definition cityrep.cpp:355
void fill_data(menu_labels which, QMap< QString, cid > &custom_labels, QMenu *menu)
Definition cityrep.cpp:757
void city_doubleclick(const QModelIndex &index)
Definition cityrep.cpp:395
void center()
Definition cityrep.cpp:450
void update_model()
Definition cityrep.cpp:1101
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:736
city_report * cr
Definition cityrep.h:141
void select_coastal()
Definition cityrep.cpp:847
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:1034
void select_building_something()
Definition cityrep.cpp:905
void display_header_menu(const QPoint &)
Definition cityrep.cpp:1130
void hide_columns()
Definition cityrep.cpp:1166
void clear_worlist()
Definition cityrep.cpp:422
void update_city(struct city *pcity)
Definition cityrep.cpp:1092
city_model * list_model
Definition cityrep.h:138
void select_all()
Definition cityrep.cpp:778
void select_none()
Definition cityrep.cpp:786
void display_list_menu(const QPoint &)
Definition cityrep.cpp:466
void gen_worklist_labels(QMap< QString, int > &list)
Definition cityrep.cpp:1023
void cities_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition cityrep.cpp:1181
void gen_cma_labels(QMap< QString, int > &list)
Definition cityrep.cpp:946
city_model * get_model() const
Definition cityrep.cpp:1207
QList< city * > selected_cities
Definition cityrep.h:164
void restore_selection()
Definition cityrep.cpp:327
void invert_selection()
Definition cityrep.cpp:794
void gen_select_labels(QMenu *menu)
Definition cityrep.cpp:957
void select_same_island()
Definition cityrep.cpp:874
@ 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
struct civclient client
bool can_client_issue_orders(void)
bool client_has_player(void)
#define client_player()
bool city_unit_supported(const struct city *pcity, const struct universal *target)
Definition climisc.c:545
void cityrep_buy(struct city *pcity)
Definition climisc.c:1160
void name_and_sort_items(struct universal *targets, int num_targets, struct item *items, bool show_cost, struct city *pcity)
Definition climisc.c:650
cid cid_encode(struct universal target)
Definition climisc.c:483
bool city_building_present(const struct city *pcity, const struct universal *target)
Definition climisc.c:583
struct universal cid_decode(cid id)
Definition climisc.c:526
bool can_city_build_now_client(const struct city *pcity, const struct universal *target)
Definition climisc.c:593
bool city_unit_present(const struct city *pcity, const struct universal *target)
Definition climisc.c:564
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)
Definition climisc.c:700
#define MAX_NUM_PRODUCTION_TARGETS
Definition climisc.h:89
int cid
Definition climisc.h:31
bool(* TestCityFunc)(const struct city *, const struct universal *)
Definition climisc.h:87
static struct fc_sockaddr_list * list
Definition clinet.c:102
void cma_put_city_under_agent(struct city *pcity, const struct cm_parameter *const parameter)
Definition cma_core.c:524
void cma_release_city(struct city *pcity)
Definition cma_core.c:542
char * cmafec_preset_get_descr(int idx)
Definition cma_fec.c:169
const struct cm_parameter * cmafec_preset_get_parameter(int idx)
Definition cma_fec.c:182
int cmafec_preset_num(void)
Definition cma_fec.c:213
char * incite_cost
Definition comments.c:77
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
int int id
Definition editgui_g.h:28
int Impr_type_id
Definition fc_types.h:237
@ RPT_CERTAIN
Definition fc_types.h:516
#define _(String)
Definition fcintl.h:67
struct world wld
Definition game.c:63
struct city * game_city_by_number(int id)
Definition game.c:106
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 CMA_NONE
Definition cityrep.h:49
#define NEG_VAL(x)
Definition cityrep.h:48
#define CAPTURE_DEFAULT_THIS
Definition gui_main.h:23
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 is_convert_improvement(const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
#define fc_assert_ret(condition)
Definition log.h:192
#define fc_assert(condition)
Definition log.h:177
void center_tile_mapcanvas(const struct tile *ptile)
#define fc_malloc(sz)
Definition mem.h:34
static mpgui * gui
Definition mpgui_qt.cpp:53
struct client_options gui_options
Definition options.c:71
struct city_list * cities
Definition packhand.c:120
#define ARRAY_SIZE(x)
Definition shared.h:85
const char * tagname
Definition cityrepdata.h:35
const char *(* func)(const struct city *pcity, const void *data)
Definition cityrepdata.h:34
const char * title2
Definition cityrepdata.h:31
const char * explanation
Definition cityrepdata.h:32
const char * title1
Definition cityrepdata.h:30
Definition city.h:318
struct connection conn
Definition client_main.h:96
bool center_when_popup_city
Definition options.h:162
struct player * playing
Definition connection.h:151
Definition climisc.h:82
struct universal item
Definition climisc.h:83
struct city_list * cities
Definition player.h:281
int index
Definition unit.h:198
struct tile * tile
Definition unit.h:142
universals_u value
Definition fc_types.h:594
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
bool is_terrain_class_near_tile(const struct civ_map *nmap, const struct tile *ptile, enum terrain_class tclass)
Definition terrain.c:615
#define tile_continent(_tile)
Definition tile.h:93
const struct impr_type * building
Definition fc_types.h:529
void worklist_init(struct worklist *pwl)
Definition worklist.c:38
int worklist_length(const struct worklist *pwl)
Definition worklist.c:57