Author: mir3x Date: Wed Sep 17 09:40:18 2014 New Revision: 26480 URL: http://svn.gna.org/viewcvs/freeciv?rev=26480&view=rev Log: Fixed double refresh of current and supported units Patched some memory leaks.
See patch #5237 Modified: trunk/client/gui-qt/citydlg.cpp trunk/client/gui-qt/citydlg.h Modified: trunk/client/gui-qt/citydlg.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/citydlg.cpp?rev=26480&r1=26479&r2=26480&view=diff ============================================================================== --- trunk/client/gui-qt/citydlg.cpp (original) +++ trunk/client/gui-qt/citydlg.cpp Wed Sep 17 09:40:18 2014 @@ -77,8 +77,10 @@ /**************************************************************************** Class representing one unit, allows context menu, holds pixmap for it ****************************************************************************/ -unit_item::unit_item(struct unit *punit, bool supp, int hppy_cost) : QLabel() -{ +unit_item::unit_item(QWidget *parent, struct unit *punit, + bool supp, int hppy_cost) : QLabel() +{ + setParent(parent); happy_cost = hppy_cost; supported = supp; unit_pixmap = NULL; @@ -401,9 +403,10 @@ /**************************************************************************** Class representing list of units ( unit_item 's) ****************************************************************************/ -unit_info::unit_info(bool supp) : QWidget() -{ - layout = new QHBoxLayout; +unit_info::unit_info(QWidget *parent, bool supp) : QWidget() +{ + setParent(parent); + layout = new QHBoxLayout(this); init_layout(); supports = supp; } @@ -448,12 +451,16 @@ int i = unit_list.count(); int j; unit_item *ui; + setUpdatesEnabled(false); + hide(); for (j = 0; j < i; j++) { ui = unit_list[j]; layout->addWidget(ui, 0, Qt::AlignVCenter); } + show(); setUpdatesEnabled(true); + layout->update(); } /**************************************************************************** @@ -464,7 +471,7 @@ int i = unit_list.count(); unit_item *ui; int j; - + setUpdatesEnabled(false); setMouseTracking(false); for (j = 0; j < i; j++) { ui = unit_list[j]; @@ -475,7 +482,7 @@ unit_list.removeFirst(); } setMouseTracking(true); - + setUpdatesEnabled(true); } /**************************************************************************** @@ -680,9 +687,9 @@ /** Overview tab initiazlization */ { - QGroupBox *map_box = new QGroupBox; + QGroupBox *map_box = new QGroupBox(this); QVBoxLayout *v_layout = new QVBoxLayout; - QGroupBox *prod_box = new QGroupBox; + QGroupBox *prod_box = new QGroupBox(this); QGridLayout *prod_layout = new QGridLayout; QScrollArea *scroll; QScrollArea *scroll2; @@ -734,7 +741,7 @@ production_combo->setMinimumWidth(200); connect(production_table, SIGNAL(itemDoubleClicked(QTableWidgetItem *)), SLOT(dbl_click(QTableWidgetItem *))); - citizens_label = new city_label(FEELING_FINAL); + citizens_label = new city_label(FEELING_FINAL, this); citizen_pixmap = NULL; view = new city_map(this); v_layout->addWidget(view); @@ -742,13 +749,13 @@ map_box->setTitle(_("City map")); supp_units = new QLabel(); curr_units = new QLabel(); - supported_units = new unit_info(true); + supported_units = new unit_info(this, true); scroll = new QScrollArea; scroll->setWidgetResizable(true); scroll->setMaximumHeight(tileset_tile_height(tileset) * 2); scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); scroll->setWidget(supported_units); - current_units = new unit_info(false); + current_units = new unit_info(this, false); scroll2 = new QScrollArea; scroll2->setWidgetResizable(true); scroll2->setMaximumHeight(tileset_tile_height(tileset) * 2); @@ -928,9 +935,9 @@ << N_("Nationality:") << N_("Units:") << N_("Wonders:"); info_nr = info_list.count(); for (int i = 0; i < info_list.count(); i++) { - lab_table[i] = new city_label(1 + i); + lab_table[i] = new city_label(1 + i, this); gridl->addWidget(lab_table[i], i, 1, 1, 1); - lab2 = new QLabel; + lab2 = new QLabel(this); lab2->setFont(*small_font); lab2->setAlignment(Qt::AlignRight | Qt::AlignVCenter); lab2->setText(info_list.at(i)); @@ -1001,7 +1008,7 @@ for (int i = 0; i < str_list.count(); i++) { some_label = new QLabel(str_list.at(i)); slider_grid->addWidget(some_label, i + 1, 0, 1, 1); - some_label = new QLabel("0"); + some_label = new QLabel("0", this); some_label->setMinimumWidth(25); if (i != str_list.count() - 1) { slider = new QSlider(Qt::Horizontal); @@ -1126,6 +1133,15 @@ city_dialog::~city_dialog() { + if (citizen_pixmap) { + delete citizen_pixmap; + } + cma_table->clear(); + production_table->clear(); + p_table_p->clear(); + nationality_table->clear(); + current_units->clear_layout(); + supported_units->clear_layout(); ::city_dlg_created = false; } @@ -1559,7 +1575,6 @@ if (citizen_pixmap) { delete citizen_pixmap; } - citizen_pixmap = new QPixmap(width, height); for (j = 0, i = 0; i < num_citizens; i++, j++) { dest_rect.moveTo(i * w, 0); @@ -1613,6 +1628,7 @@ ****************************************************************************/ void city_dialog::refresh() { + setUpdatesEnabled(false); production_combo->blockSignals(true); production_combo_p->blockSignals(true); if (pcity) { @@ -1636,6 +1652,7 @@ } production_combo_p->blockSignals(false); production_combo->blockSignals(false); + setUpdatesEnabled(true); } void city_dialog::update_settings() @@ -1909,6 +1926,7 @@ int n; int happy_cost; int free_unhappy = get_city_bonus(pcity, EFT_MAKE_CONTENT_MIL); + supported_units->setUpdatesEnabled(false); supported_units->clear_layout(); if (NULL != client.conn.playing @@ -1920,15 +1938,16 @@ unit_list_iterate(units, punit) { happy_cost = city_unit_unhappiness(punit, &free_unhappy); - ui = new unit_item(punit, true, happy_cost); + ui = new unit_item(this, punit, true, happy_cost); ui->init_pix(); supported_units->add_item(ui); } unit_list_iterate_end; - n = unit_list_size(units); fc_snprintf(buf, sizeof(buf), _("Supported units %d"), n); supp_units->setText(QString(buf)); supported_units->update_units(); + supported_units->setUpdatesEnabled(true); + current_units->setUpdatesEnabled(true); current_units->clear_layout(); if (NULL != client.conn.playing @@ -1939,7 +1958,7 @@ } unit_list_iterate(units, punit) { - ui = new unit_item(punit, false); + ui = new unit_item(this ,punit, false); ui->init_pix(); current_units->add_item(ui); } unit_list_iterate_end; @@ -1949,6 +1968,7 @@ curr_units->setText(QString(buf)); current_units->update_units(); + current_units->setUpdatesEnabled(true); } @@ -2140,7 +2160,7 @@ targets_used = collect_already_built_targets(targets, pcity); name_and_sort_items(targets, targets_used, items, false, pcity); - production_table->clearContents(); + production_table->clear(); production_table->setRowCount(0); total = 0; @@ -2256,7 +2276,7 @@ { production_widget *pw; - pw = new production_widget(pcity, false, 0, 0, true); + pw = new production_widget(this, pcity, false, 0, 0, true); pw->show(); } @@ -2286,7 +2306,7 @@ when = 4; } - pw = new production_widget(pcity, future, when, selected_row_p, + pw = new production_widget(this, pcity, future, when, selected_row_p, show_units); pw->show(); } @@ -2610,8 +2630,10 @@ /**************************************************************************** Production item constructor ****************************************************************************/ -production_item::production_item(struct universal *ptarget): QObject() -{ +production_item::production_item(struct universal *ptarget, + QObject *parent): QObject() +{ + setParent(parent); target = ptarget; } @@ -2705,7 +2727,7 @@ if (future_t || can_city_build_now(mcity, items[item].item)) { renegade = new universal(items[item].item); /* renagade deleted in production_item destructor */ - pi = new production_item(renegade); + pi = new production_item(renegade, this); if (VUT_UTYPE == renegade->kind) { str = utype_name_translation(renegade->value.utype); sh.setX(qMax(sh.x(), fm.width(str))); @@ -2720,7 +2742,7 @@ } } renegade = NULL; - pi = new production_item(renegade); + pi = new production_item(renegade, this); city_target_list << pi; sh.setX(sh.y() + sh.x()); } @@ -2748,8 +2770,8 @@ when - where to insert curr - current index to insert ****************************************************************************/ -production_widget::production_widget(struct city *pcity, bool future, - int when, int curr, +production_widget::production_widget(QWidget *parent, struct city *pcity, + bool future, int when, int curr, bool show_units): QTableView() { QPoint pos, sh; @@ -2764,7 +2786,7 @@ sh_units = show_units; pw_city = pcity; when_change = when; - list_model = new city_production_model(pw_city, future, show_units); + list_model = new city_production_model(pw_city, future, show_units, this); sh = list_model->sh; c_p_d = new city_production_delegate(sh, this, pw_city); setItemDelegate(c_p_d); @@ -2895,5 +2917,6 @@ { delete c_p_d; delete list_model; -} - + removeEventFilter(this); +} + Modified: trunk/client/gui-qt/citydlg.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/citydlg.h?rev=26480&r1=26479&r2=26480&view=diff ============================================================================== --- trunk/client/gui-qt/citydlg.h (original) +++ trunk/client/gui-qt/citydlg.h Wed Sep 17 09:40:18 2014 @@ -77,7 +77,7 @@ QAction *unload_trans; public: - unit_item(struct unit *punit, bool supp = false, int happy_cost = 0); + unit_item(QWidget *parent ,struct unit *punit, bool supp = false, int happy_cost = 0); ~unit_item(); void init_pix(); @@ -116,7 +116,7 @@ Q_OBJECT public: - unit_info(bool supp); + unit_info(QWidget *parent, bool supp); ~unit_info(); void add_item(unit_item *item); void init_layout(); @@ -191,7 +191,7 @@ Q_OBJECT public: - production_item(struct universal *ptarget); + production_item(struct universal *ptarget, QObject *parent); ~production_item(); inline int columnCount() const { return 1; @@ -247,8 +247,8 @@ city_production_delegate *c_p_d; public: - production_widget(struct city *pcity, bool future, int when, int curr, - bool show_units); + production_widget(QWidget *parent, struct city *pcity, bool future, + int when, int curr, bool show_units); ~production_widget(); public slots: _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits