Freeciv21
Develop your civilization from humble roots to a global empire
freeciv::improvement_seller Class Reference

Helper class to safely sell a city improvement. More...

#include <improvement_seller.h>

Public Member Functions

 improvement_seller (QWidget *parent, int city_id, int improvement_id)
 Constructor. More...
 
void operator() ()
 Asks for confirmation then sells the improvement. More...
 

Static Public Member Functions

static QAction * add_to_menu (QWidget *parent, QMenu *menu, const city *city, int improvement_id)
 Adds a menu item to sell an improvement in a city. More...
 

Private Attributes

int m_city
 
int m_improvement
 
QWidget * m_parent
 

Detailed Description

Helper class to safely sell a city improvement.

This class adds an action to a menu (via add_to_menu) to sell a city improvement. When the item is activated, the potential gain is displayed and the user is prompted for confirmation. If the user confirms, the improvement is sold.

The seller can also be used directly with its operator().

This class handles all corner cases where the city may be disbanded or the improvement disappear for some reason.

Definition at line 16 of file improvement_seller.h.

Constructor & Destructor Documentation

◆ improvement_seller()

freeciv::improvement_seller::improvement_seller ( QWidget *  parent,
int  city_id,
int  improvement_id 
)

Constructor.

Definition at line 41 of file improvement_seller.cpp.

Referenced by add_to_menu().

Member Function Documentation

◆ add_to_menu()

QAction * freeciv::improvement_seller::add_to_menu ( QWidget *  parent,
QMenu *  menu,
const city city,
int  improvement_id 
)
static

Adds a menu item to sell an improvement in a city.

The parent parameter is used as the parent for the confirmation popup. It may not be null. The parent must outlive the menu.

Definition at line 100 of file improvement_seller.cpp.

Referenced by freeciv::upkeep_widget::contextMenuEvent().

◆ operator()()

void freeciv::improvement_seller::operator() ( )

Asks for confirmation then sells the improvement.

Definition at line 50 of file improvement_seller.cpp.

Member Data Documentation

◆ m_city

int freeciv::improvement_seller::m_city
private

Definition at line 26 of file improvement_seller.h.

Referenced by operator()().

◆ m_improvement

int freeciv::improvement_seller::m_improvement
private

Definition at line 26 of file improvement_seller.h.

Referenced by operator()().

◆ m_parent

QWidget* freeciv::improvement_seller::m_parent
private

Definition at line 27 of file improvement_seller.h.

Referenced by operator()().