17 #include <QApplication>
18 #include <QHeaderView>
19 #include <QVBoxLayout>
43 const QModelIndex &right)
const
51 qleft = sourceModel()->data(left);
52 qright = sourceModel()->data(right);
53 l_bytes = qleft.toString().toLocal8Bit();
54 r_bytes = qright.toString().toLocal8Bit();
64 : QItemDelegate(parent)
66 QFont f = QApplication::font();
76 const QStyleOptionViewItem &
option,
77 const QModelIndex &index)
const
79 QStyleOptionViewItem opt = QItemDelegate::setOptions(index,
option);
86 if (txt == QLatin1String(
"cityname")) {
87 font.setCapitalization(QFont::SmallCaps);
91 if (txt == QLatin1String(
"hstate_verbose")) {
95 if (txt == QLatin1String(
"prodplus")) {
96 txt = index.data().toString();
97 if (txt.toInt() < 0) {
99 palette.setColor(QPalette::Text, QColor(255, 0, 0));
101 opt.palette = palette;
105 QItemDelegate::paint(painter, opt, index);
112 const QModelIndex &index)
const
114 QSize s = QItemDelegate::sizeHint(
option, index);
146 if (role == Qt::UserRole && column == 0) {
147 return QVariant::fromValue((
void *)
i_city);
149 if (role != Qt::DisplayRole) {
153 return spec.func(
i_city, spec.data).trimmed();
178 emit dataChanged(index(row, 0), index(row,
columnCount() - 1));
186 if (!index.isValid()) {
189 if (index.row() >= 0 && index.row() <
rowCount() && index.column() >= 0
191 return city_list[index.row()]->data(index.column(), role);
202 if (!index.isValid() || role != Qt::DisplayRole) {
205 if (index.row() >= 0 && index.row() <
rowCount() && index.column() >= 0
208 city_list[index.row()]->setData(index.column(), value, role);
227 if (role == Qt::DisplayRole) {
228 QString buf = QStringLiteral(
"%1\n%2").arg(
229 spec.title1 ? spec.title1 :
"", spec.title2 ? spec.title2 :
"");
234 return buf.trimmed();
236 if (role == Qt::ToolTipRole) {
237 return QString(spec.explanation);
239 if (role == Qt::DecorationRole) {
310 for (
int i = 0; i <
city_list.count(); i++) {
312 if (pcity ==
item->get_city()) {
334 QItemSelection selection;
344 qvar = i.data(Qt::UserRole);
348 pcity =
reinterpret_cast<city *
>(qvar.value<
void *>());
350 selection.append(QItemSelectionRange(i));
353 selectionModel()->select(selection,
354 QItemSelectionModel::Rows
355 | QItemSelectionModel::SelectCurrent);
365 setItemDelegate(
c_i_d);
372 setRootIsDecorated(
false);
373 setAllColumnsShowFocus(
true);
374 setSortingEnabled(
true);
375 setSelectionMode(QAbstractItemView::ExtendedSelection);
376 setSelectionBehavior(QAbstractItemView::SelectRows);
377 setItemsExpandable(
false);
379 setProperty(
"uniformRowHeights",
"true");
380 setAlternatingRowColors(
true);
381 header()->setContextMenuPolicy(Qt::CustomContextMenu);
382 header()->setMinimumSectionSize(10);
383 setContextMenuPolicy(Qt::CustomContextMenu);
385 connect(header(), &QWidget::customContextMenuRequested,
this,
387 connect(selectionModel(), &QItemSelectionModel::selectionChanged,
this,
389 connect(
this, &QAbstractItemView::doubleClicked,
this,
391 connect(
this, &QWidget::customContextMenuRequested,
this,
416 Q_ASSERT(pcity !=
nullptr);
431 const auto saved_selection =
433 for (
auto *pcity : saved_selection) {
434 Q_ASSERT(pcity !=
nullptr);
447 std::sort(saved_selection.begin(), saved_selection.end(),
448 [](
const city *lhs,
const city *rhs) {
449 return lhs->client.buy_cost < rhs->client.buy_cost;
453 for (
auto *pcity : saved_selection) {
469 Q_ASSERT(pcity !=
nullptr);
484 bool select_only =
false;
487 QAction cty_view(
style()->standardIcon(QStyle::SP_CommandLink),
488 Q_(
"?verb:View"), 0);
494 sell_gold = sell_gold + pcity->client.buy_cost;
499 list_menu =
new QMenu(
this);
501 QString(
_(
"Buy ( Cost: %1 )")).arg(QString::number(sell_gold));
503 QAction *cty_buy =
new QAction(QString(buf), list_menu);
504 QAction *cty_center =
new QAction(
505 style()->standardIcon(QStyle::SP_ArrowRight),
_(
"Center"), list_menu);
506 QAction *wl_clear =
new QAction(
_(
"Clear"), list_menu);
507 QAction *wl_empty =
new QAction(
_(
"(no worklists defined)"), list_menu);
508 bool worklist_defined =
true;
511 some_menu = list_menu->addMenu(
_(
"Production"));
512 tmp_menu = some_menu->addMenu(
_(
"Change"));
515 tmp_menu = some_menu->addMenu(
_(
"Add next"));
518 tmp_menu = some_menu->addMenu(
_(
"Add before last"));
521 tmp_menu = some_menu->addMenu(
_(
"Add last"));
525 tmp_menu = some_menu->addMenu(
_(
"Worklist"));
526 tmp_menu->addAction(wl_clear);
527 connect(wl_clear, &QAction::triggered,
this,
529 tmp2_menu = tmp_menu->addMenu(
_(
"Add"));
531 if (cma_labels.count() == 0) {
532 tmp2_menu->addAction(wl_empty);
533 worklist_defined =
false;
536 tmp2_menu = tmp_menu->addMenu(
_(
"Change"));
537 if (cma_labels.count() == 0) {
538 tmp2_menu->addAction(wl_empty);
539 worklist_defined =
false;
542 some_menu = list_menu->addMenu(
_(
"Governor"));
545 some_menu = list_menu->addMenu(
_(
"Sell"));
550 some_menu = list_menu->addMenu(
_(
"Select"));
553 list_menu->addAction(&cty_view);
555 list_menu->addAction(cty_buy);
557 list_menu->addAction(cty_center);
562 list_menu->setAttribute(Qt::WA_DeleteOnClose);
563 connect(list_menu, &QMenu::triggered,
this, [=](QAction *act) {
564 QVariant qvar, qvar2;
572 bool need_clear =
true;
573 bool sell_ask =
true;
579 qvar2 = act->property(
"FC");
587 if (
nullptr != iter_city) {
659 const auto saved_selection =
661 for (
auto *pcity : saved_selection) {
662 if (
nullptr != pcity) {
682 QString buf = QString(
_(
"Are you sure you want to sell the %1?"))
685 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Yes);
686 ask->setDefaultButton(QMessageBox::No);
687 ask->button(QMessageBox::Yes)->setText(
_(
"Yes Sell"));
689 ask->setAttribute(Qt::WA_DeleteOnClose);
692 connect(ask, &hud_message_box::accepted,
this, [=]() {
695 if (!pcity || !building) {
714 if (worklist_defined) {
721 if (worklist_defined) {
732 list_menu->popup(QCursor::pos());
744 m1 = menu->addMenu(
_(
"Buildings"));
745 m2 = menu->addMenu(
_(
"Units"));
746 m3 = menu->addMenu(
_(
"Wonders"));
764 map_iter = custom_labels.constBegin();
765 while (map_iter != custom_labels.constEnd()) {
766 action = menu->addAction(map_iter.key());
767 action->setData(map_iter.value());
768 action->setProperty(
"FC", which);
771 if (custom_labels.isEmpty()) {
772 menu->setDisabled(
true);
791 QItemSelection selection;
798 qvar = i.data(Qt::UserRole);
802 pcity =
reinterpret_cast<city *
>(qvar.value<
void *>());
804 selection.append(QItemSelectionRange(i));
808 selectionModel()->select(selection,
809 QItemSelectionModel::Rows
810 | QItemSelectionModel::SelectCurrent);
818 QItemSelection selection;
825 qvar = i.data(Qt::UserRole);
829 pcity =
reinterpret_cast<city *
>(qvar.value<
void *>());
830 if (pcity == spcity) {
831 selection.append(QItemSelectionRange(i));
834 selectionModel()->select(selection, QItemSelectionModel::Rows
835 | QItemSelectionModel::Select);
843 QItemSelection selection;
851 qvar = i.data(Qt::UserRole);
855 pcity =
reinterpret_cast<city *
>(qvar.value<
void *>());
858 selection.append(QItemSelectionRange(i));
861 selectionModel()->select(selection,
862 QItemSelectionModel::Rows
863 | QItemSelectionModel::SelectCurrent);
871 QItemSelection selection;
878 qvar = i.data(Qt::UserRole);
882 pcity =
reinterpret_cast<city *
>(qvar.value<
void *>());
886 selection.append(QItemSelectionRange(i));
890 selectionModel()->select(selection,
891 QItemSelectionModel::Rows
892 | QItemSelectionModel::SelectCurrent);
901 QItemSelection selection;
911 qvar = i.data(Qt::UserRole);
915 pcity =
reinterpret_cast<city *
>(qvar.value<
void *>());
916 act = qobject_cast<QAction *>(sender());
918 str = qvar.toString();
919 if (
nullptr != pcity) {
920 if (str == QLatin1String(
"impr")
925 selection.append(QItemSelectionRange(i));
926 }
else if (str == QLatin1String(
"unit")
928 selection.append(QItemSelectionRange(i));
929 }
else if (str == QLatin1String(
"wonder")
932 selection.append(QItemSelectionRange(i));
936 selectionModel()->select(selection,
937 QItemSelectionModel::Rows
938 | QItemSelectionModel::SelectCurrent);
961 act = menu->addAction(
_(
"All Cities"));
963 act = menu->addAction(
_(
"No Cities"));
965 act = menu->addAction(
_(
"Invert Selection"));
967 menu->addSeparator();
968 act = menu->addAction(
_(
"Coastal Cities"));
970 act = menu->addAction(
_(
"Same Island"));
973 act->setDisabled(
true);
975 menu->addSeparator();
976 act = menu->addAction(
_(
"Building Units"));
977 act->setData(
"unit");
978 connect(act, &QAction::triggered,
this,
980 act = menu->addAction(
_(
"Building Improvements"));
981 act->setData(
"impr");
982 connect(act, &QAction::triggered,
this,
984 act = menu->addAction(
_(
"Building Wonders"));
985 act->setData(
"wonder");
986 connect(act, &QAction::triggered,
this,
988 menu->addSeparator();
989 tmp_menu = menu->addMenu(
_(
"Improvements in City"));
993 tmp_menu = menu->addMenu(
_(
"Wonders in City"));
997 menu->addSeparator();
998 tmp_menu = menu->addMenu(
_(
"Supported Units"));
1002 tmp_menu = menu->addMenu(
_(
"Units Present"));
1006 menu->addSeparator();
1007 tmp_menu = menu->addMenu(
_(
"Available Units"));
1011 tmp_menu = menu->addMenu(
_(
"Available Improvements"));
1015 tmp_menu = menu->addMenu(
_(
"Available Wonders"));
1040 bool append_wonders,
1046 int i,
item, targets_used;
1049 struct city **city_data;
1057 std::vector<struct city *> array;
1058 array.resize(num_sel);
1069 for (i = 0; i < num_sel; i++) {
1073 city_data = &array[0];
1084 QString txt = QStringLiteral(
"%1 ").arg(buf);
1104 setUpdatesEnabled(
false);
1107 header()->resizeSections(QHeaderView::ResizeToContents);
1108 setUpdatesEnabled(
true);
1116 QMenu *hideshow_column =
new QMenu(
this);
1119 hideshow_column->setTitle(
_(
"Column visibility"));
1123 myAct->setCheckable(
true);
1124 myAct->setChecked(!isColumnHidden(i));
1127 hideshow_column->setAttribute(Qt::WA_DeleteOnClose);
1128 connect(hideshow_column, &QMenu::triggered,
this, [=](QAction *act) {
1136 setColumnHidden(col, !isColumnHidden(col));
1138 if (!isColumnHidden(col) && columnWidth(col) <= 5) {
1139 setColumnWidth(col, 100);
1142 hideshow_column->popup(QCursor::pos());
1154 setColumnHidden(col, !isColumnHidden(col));
1164 const QItemSelection &ds)
1168 QModelIndexList indexes = selectionModel()->selectedIndexes();
1174 if (indexes.isEmpty()) {
1177 for (
auto i : qAsConst(indexes)) {
1178 qvar = i.data(Qt::UserRole);
1179 if (qvar.isNull()) {
1182 pcity =
reinterpret_cast<city *
>(qvar.value<
void *>());
1204 layout =
new QVBoxLayout;
1206 if (
king()->qt_settings.city_repo_sort_col != -1) {
1207 city_wdg->sortByColumn(
king()->qt_settings.city_repo_sort_col,
1208 king()->qt_settings.city_report_sort);
1255 if (!
queen()->isRepoDlgOpen(QStringLiteral(
"CTS"))) {
1263 if (w->isVisible()) {
1279 if (
queen()->isRepoDlgOpen(QStringLiteral(
"CTS"))) {
1281 if (
queen()->game_tab_widget->currentIndex() == i) {
1318 if (
queen()->isRepoDlgOpen(QStringLiteral(
"CTS"))) {
static struct action * actions[MAX_NUM_ACTIONS]
bool can_city_build_now(const struct city *pcity, const struct universal *target)
Returns whether city can immediately build given target, unit or improvement.
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Return TRUE iff the city has this building in it.
#define cities_iterate_end
#define city_list_iterate(citylist, pcity)
#define cities_iterate(pcity)
#define city_list_iterate_end
void real_city_dialog_popup(struct city *pcity)
Pop up (or bring to the front) a dialog for the given city.
int city_set_worklist(struct city *pcity, const struct worklist *pworklist)
Set the worklist for a given city.
bool city_queue_insert(struct city *pcity, int position, struct universal *item)
Insert an item into the city's queue.
bool city_queue_insert_worklist(struct city *pcity, int position, const struct worklist *worklist)
Insert the worklist into the city's queue at the given position.
bool city_set_queue(struct city *pcity, const struct worklist *pqueue)
Set the city current production and the worklist, like it should be.
int city_change_production(struct city *pcity, struct universal *target)
Change the production of a given city.
int city_sell_improvement(struct city *pcity, Impr_type_id sell_id)
Change the production of a given city.
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
City item delgate paint event.
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
Size hint for city item delegate.
city_item_delegate(QObject *parent)
City item delegate constructor.
struct city * get_city()
Returns used city pointer for city item creation.
QVariant data(int column, int role=Qt::DisplayRole) const
Returns data from city item (or city pointer from Qt::UserRole)
city_item(struct city *pcity)
Constructor for city item.
bool setData(int column, const QVariant &value, int role=Qt::DisplayRole)
Sets nothing, but must be declared.
void city_changed(struct city *pcity)
Notifies about changed item.
QVariant hide_data(int section) const
Hides given column if show is false.
int rowCount(const QModelIndex &index=QModelIndex()) const override
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Returns header data for given section(column)
void populate()
Creates city model.
QVariant menu_data(int section) const
Returns header information about section.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
void all_changed()
Notifies about whole model changed.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::DisplayRole) override
Sets data in model under index.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Returns stored data in index.
QList< city_item * > city_list
~city_model() override
Destructor for city model.
city_model(QObject *parent=0)
Constructor for city model.
void notify_city_changed(int row)
Notifies about changed row.
~city_report() override
Destructor for city report.
city_report()
Constructor for city report.
void init()
Inits place in game tab widget.
void update_report()
Updates whole report.
void update_city(struct city *pcity)
Updates single city.
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
Overriden compare for sorting items.
QIcon get(const QString &id)
void set_text_title(const QString &s1, const QString &s2)
Sets text and title and shows message box.
void center_on_tile(tile *tile, bool animate=true)
Centers the view on a tile.
int gimmeIndexOf(const QString &str)
Returns index on game tab page of given report dialog.
int addGameTab(QWidget *widget)
Inserts tab widget to game view page.
void removeRepoDlg(const QString &str)
Removes report dialog string from the list marking it as closed.
void gimmePlace(QWidget *widget, const QString &str)
Finds not used index on game_view_tab and returns it.
fc_game_tab_widget * game_tab_widget
bool client_has_player()
Either controlling or observing.
struct player * client_player()
Either controlling or observing.
bool can_client_issue_orders()
Returns TRUE iff the client can issue orders (such as giving unit commands).
bool city_unit_supported(const struct city *pcity, const struct universal *target)
Return TRUE if the city supports at least one unit of the given production type (returns FALSE if the...
void cityrep_buy(struct city *pcity)
Called when the "Buy" button is pressed in the city report for every selected city.
void name_and_sort_items(struct universal *targets, int num_targets, struct item *items, bool show_cost, struct city *pcity)
Takes an array of compound ids (cids).
cid cid_encode(struct universal target)
Encode a CID for the target production.
bool city_building_present(const struct city *pcity, const struct universal *target)
A TestCityFunc to tell whether the item is a building and is present.
struct universal cid_decode(cid id)
Decode the CID into a city_production structure.
bool city_unit_present(const struct city *pcity, const struct universal *target)
Return TRUE if the city has present at least one unit of the given production type (returns FALSE if ...
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)
Return possible production targets for the current player's cities.
#define MAX_NUM_PRODUCTION_TARGETS
bool(* TestCityFunc)(const struct city *, const struct universal *)
class fc_client * king()
Return fc_client instance.
struct city * game_city_by_number(int id)
Often used function to get a city pointer from a city ID.
struct global_worklist * global_worklist_by_id(int id)
Returns the global worklist corresponding to this id.
int global_worklist_id(const struct global_worklist *pgwl)
Returns the id of the global worklist.
const char * global_worklist_name(const struct global_worklist *pgwl)
Return the name of the global worklist.
const struct worklist * global_worklist_get(const struct global_worklist *pgwl)
Returns the worklist of this global worklist or nullptr if it's not valid.
#define global_worklists_iterate(pgwl)
#define global_worklists_iterate_end
int cmafec_preset_num()
Returns the total number of presets.
const struct cm_parameter * cmafec_preset_get_parameter(int idx)
Returns the indexed preset's parameter.
char * cmafec_preset_get_descr(int idx)
Returns the indexed preset's description.
void cma_put_city_under_agent(struct city *pcity, const struct cm_parameter *const parameter)
Put city under governor control.
void cma_release_city(struct city *pcity)
Release city from governor control.
struct impr_type * improvement_by_number(const Impr_type_id id)
Returns the improvement type for the given index/ID.
Impr_type_id improvement_number(const struct impr_type *pimprove)
Return the improvement index.
bool is_wonder(const struct impr_type *pimprove)
Returns whether improvement is some kind of wonder.
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
Return TRUE if the impr has this flag otherwise FALSE.
const char * improvement_name_translation(const struct impr_type *pimprove)
Return the (translated) name of the given improvement.
#define fc_assert_ret(condition)
#define fc_assert(condition)
client_options * gui_options
struct city_list * cities
pageGame * queen()
Return game instandce.
const char * universal_name_translation(const struct universal *psource, char *buf, size_t bufsz)
Make user-friendly text for the source.
struct universal production
bool center_when_popup_city
Qt::SortOrder city_report_sort
The base class for options.
struct city_list * cities
bool is_terrain_class_near_tile(const struct tile *ptile, enum terrain_class tclass)
Is there terrain of the given class near tile? (Does not check ptile itself.)
#define tile_continent(_tile)
void top_bar_show_map()
Callback to show map.
const struct impr_type * building
void city_report_dialog_popup()
Display the city report dialog.
void real_city_report_dialog_update(void *unused)
Update (refresh) the entire city report dialog.
void real_city_report_update_city(struct city *pcity)
Update the information for a single city in the city report.
static void update_city_report(struct city *pcity)
void popdown_city_report()
Closes city report.
bool can_city_sell_universal(const struct city *pcity, const struct universal *target)
Same as can_city_sell_building(), but with universal argument.
int cityrepfield_compare(const char *str1, const char *str2)
The real function: split the two strings, and compare them.
std::vector< city_report_spec > city_report_specs
void worklist_init(struct worklist *pwl)
Initialize a worklist to be empty.
int worklist_length(const struct worklist *pwl)
Returns the number of entries in the worklist.