Project

Profile

Help

HostedRedmine.com has moved to the Planio platform. All logins and passwords remained the same. All users will be able to login and use Redmine just as before. Read more...

Bug #918786 » 0005-Qt-Fix-foreach-inside-foreach-shadow-warnings-from-m.patch

master - Marko Lindqvist, 2021-01-30 08:21 PM

View differences:

client/gui-qt/menu.cpp
207 207
  }
208 208
}
209 209

  
210
/**********************************************************************//**
211
  Inner foreach() loop of trade_generator::calculate()
212
  Implemented as separate function to avoid shadow warnings about
213
  internal variables of foreach() inside foreach()
214
**************************************************************************/
215
void trade_generator::calculate_inner(trade_city *tc)
216
{
217
  trade_city *ttc;
218

  
219
  foreach (ttc, cities) {
220
    if (!have_cities_trade_route(tc->city, ttc->city)
221
        && can_establish_trade_route(tc->city, ttc->city)) {
222
      tc->poss_trade_num++;
223
      tc->pos_cities.append(ttc->city);
224
    }
225
    tc->over_max = tc->trade_num + tc->poss_trade_num
226
      - max_trade_routes(tc->city);
227
  }
228
}
229

  
210 230
/**********************************************************************//**
211 231
  Finds trade routes to establish
212 232
**************************************************************************/
213 233
void trade_generator::calculate()
214 234
{
215 235
  trade_city *tc;
216
  trade_city *ttc;
217 236
  int i;
218 237
  bool tdone;
219 238

  
......
249 268
      tc->new_tr_cities.clear();
250 269
      tc->curr_tr_cities.clear();
251 270
      tc->done = false;
252
      foreach (ttc, cities) {
253
        if (!have_cities_trade_route(tc->city, ttc->city)
254
            && can_establish_trade_route(tc->city, ttc->city)) {
255
          tc->poss_trade_num++;
256
          tc->pos_cities.append(ttc->city);
257
        }
258
        tc->over_max = tc->trade_num + tc->poss_trade_num
259
                       - max_trade_routes(tc->city);
260
      }
271
      calculate_inner(tc);
261 272
    }
262 273

  
263 274
    find_certain_routes();
......
402 413
  return false;
403 414
}
404 415

  
416
/**********************************************************************//**
417
  Inner foreach() loop of trade_generator::find_certain_routes()
418
  Implemented as separate function to avoid shadow warnings about
419
  internal variables of foreach() inside foreach()
420
**************************************************************************/
421
void trade_generator::find_certain_routes_inner(trade_city *tc)
422
{
423
  trade_city *ttc;
424

  
425
  foreach (ttc, cities) {
426
    if (ttc->done || ttc->over_max > 0
427
        || tc == ttc || tc->done || tc->over_max > 0) {
428
      continue;
429
    }
430
    if (tc->pos_cities.contains(ttc->city)
431
        && ttc->pos_cities.contains(tc->city)) {
432
      struct qtiles gilles;
433

  
434
      tc->pos_cities.removeOne(ttc->city);
435
      ttc->pos_cities.removeOne(tc->city);
436
      tc->poss_trade_num--;
437
      ttc->poss_trade_num--;
438
      tc->new_tr_cities.append(ttc->city);
439
      ttc->new_tr_cities.append(ttc->city);
440
      tc->trade_num++;
441
      ttc->trade_num++;
442
      tc->over_max--;
443
      ttc->over_max--;
444
      check_if_done(tc, ttc);
445
      gilles.t1 = tc->city->tile;
446
      gilles.t2 = ttc->city->tile;
447
      gilles.autocaravan = nullptr;
448
      lines.append(gilles);
449
    }
450
  }
451
}
452

  
405 453
/**********************************************************************//**
406 454
  Adds routes for cities which can only have maximum possible trade routes
407 455
**************************************************************************/
408 456
void trade_generator::find_certain_routes()
409 457
{
410 458
  trade_city *tc;
411
  trade_city *ttc;
412 459

  
413 460
  foreach (tc, cities) {
414 461
    if (tc->done || tc->over_max > 0) {
415 462
      continue;
416 463
    }
417
    foreach (ttc, cities) {
418
      if (ttc->done || ttc->over_max > 0
419
          || tc == ttc || tc->done || tc->over_max > 0) {
420
        continue;
421
      }
422
      if (tc->pos_cities.contains(ttc->city)
423
          && ttc->pos_cities.contains(tc->city)) {
424
        struct qtiles gilles;
425
        tc->pos_cities.removeOne(ttc->city);
426
        ttc->pos_cities.removeOne(tc->city);
427
        tc->poss_trade_num--;
428
        ttc->poss_trade_num--;
429
        tc->new_tr_cities.append(ttc->city);
430
        ttc->new_tr_cities.append(ttc->city);
431
        tc->trade_num++;
432
        ttc->trade_num++;
433
        tc->over_max--;
434
        ttc->over_max--;
435
        check_if_done(tc, ttc);
436
        gilles.t1 = tc->city->tile;
437
        gilles.t2 = ttc->city->tile;
438
        gilles.autocaravan = nullptr;
439
        lines.append(gilles);
440
      }
441
    }
464
    find_certain_routes_inner(tc);
442 465
  }
443 466
}
444 467

  
......
1158 1181
  menu_list.insert(NOT_4_OBS, act);
1159 1182
  connect(act, &QAction::triggered, this, &mr_menu::slot_unit_filter);
1160 1183

  
1161

  
1162 1184
  /* Unit Menu */
1163 1185
  menu = this->addMenu(_("Unit"));
1164 1186
  act = menu->addAction(_("Go to Tile"));
......
1708 1730
  }
1709 1731
}
1710 1732

  
1733
/**********************************************************************//**
1734
  Inner foreach() loop of mr_menu::execute_shortcut()
1735
  Implemented as separate function to avoid shadow warnings about
1736
  internal variables of foreach() inside foreach()
1737
**************************************************************************/
1738
bool mr_menu::execute_shortcut_inner(const QMenu *m, QKeySequence seq)
1739
{
1740
  foreach (QAction *a, m->actions()) {
1741
    if (a->shortcut() == seq && a->isEnabled()) {
1742
      a->activate(QAction::Trigger);
1743
      return TRUE;
1744
    }
1745
  }
1746

  
1747
  return FALSE;
1748
}
1749

  
1711 1750
/**********************************************************************//**
1712 1751
  Finds QAction bounded to given shortcut and triggers it
1713 1752
**************************************************************************/
......
1726 1765
  seq = QKeySequence(shortcut_to_string(fcs));
1727 1766

  
1728 1767
  menus = findChildren<QMenu*>();
1729
    foreach (const QMenu *m, menus) {
1730
        foreach (QAction *a, m->actions()) {
1731
          if (a->shortcut() == seq && a->isEnabled()) {
1732
            a->activate(QAction::Trigger);
1733
            return;
1734
          }
1735
        }
1768
  foreach (const QMenu *m, menus) {
1769
    if (execute_shortcut_inner(m, seq)) {
1770
      return;
1736 1771
    }
1772
  }
1773
}
1774

  
1775
/**********************************************************************//**
1776
  Inner foreach() loop of mr_menu::shortcut_exist()
1777
  Implemented as separate function to avoid shadow warnings about
1778
  internal variables of foreach() inside foreach()
1779
**************************************************************************/
1780
bool mr_menu::shortcut_exist_inner(const QMenu *m, QKeySequence seq,
1781
                                   fc_shortcut *fcs, QString *ret)
1782
{
1783
  foreach (QAction *a, m->actions()) {
1784
    if (a->shortcut() == seq && fcs->mouse == Qt::AllButtons) {
1785
      *ret = a->text();
1786

  
1787
      return TRUE;
1788
    }
1789
  }
1790

  
1791
  return FALSE;
1737 1792
}
1738 1793

  
1739 1794
/**********************************************************************//**
......
1747 1802
  seq = QKeySequence(shortcut_to_string(fcs));
1748 1803
  menus = findChildren<QMenu *>();
1749 1804
  foreach (const QMenu *m, menus) {
1750
    foreach (QAction *a, m->actions()) {
1751
      if (a->shortcut() == seq && fcs->mouse == Qt::AllButtons) {
1752
        return a->text();
1753
      }
1805
    QString ret;
1806

  
1807
    if (shortcut_exist_inner(m, seq, fcs, &ret)) {
1808
      return ret;
1754 1809
    }
1755 1810
  }
1756 1811

  
1757 1812
  return QString();
1758 1813
}
1759 1814

  
1815
/**********************************************************************//**
1816
  Inner foreach() loop of mr_menu::shortcut_2_menustring()
1817
  Implemented as separate function to avoid shadow warnings about
1818
  internal variables of foreach() inside foreach()
1819
**************************************************************************/
1820
bool mr_menu::shortcut_2_menustring_inner(const QMenu *m, QKeySequence seq,
1821
                                          QString *ret)
1822
{
1823
  foreach (QAction *a, m->actions()) {
1824
    if (a->shortcut() == seq) {
1825
      *ret = a->text() + " ("
1826
        + a->shortcut().toString(QKeySequence::NativeText) + ")";
1827

  
1828
      return TRUE;
1829
    }
1830
  }
1831

  
1832
  return FALSE;
1833
}
1834

  
1760 1835
/**********************************************************************//**
1761 1836
  Returns string bounded to given shortcut
1762 1837
**************************************************************************/
......
1771 1846

  
1772 1847
  menus = findChildren<QMenu *>();
1773 1848
  foreach (const QMenu *m, menus) {
1774
    foreach (QAction *a, m->actions()) {
1775
      if (a->shortcut() == seq) {
1776
        return (a->text() + " ("
1777
                + a->shortcut().toString(QKeySequence::NativeText) + ")");
1778
      }
1849
    QString ret;
1850

  
1851
    if (shortcut_2_menustring_inner(m, seq, &ret)) {
1852
      return ret;
1779 1853
    }
1780 1854
  }
1855

  
1781 1856
  return QString();
1782 1857
}
1783 1858

  
client/gui-qt/menu.h
196 196
  void discard();
197 197
  void discard_trade(trade_city *tc1, trade_city *tc2);
198 198
  void find_certain_routes();
199
  void find_certain_routes_inner(trade_city *tc);
200
  void calculate_inner(trade_city *tc);
199 201
};
200 202

  
201 203

  
......
413 415
  void slot_traveler();
414 416

  
415 417
private:
416
  struct tile* find_last_unit_pos(struct unit* punit, int pos);
418
  struct tile *find_last_unit_pos(struct unit *punit, int pos);
419
  bool execute_shortcut_inner(const QMenu *m, QKeySequence seq);
420
  bool shortcut_exist_inner(const QMenu *m, QKeySequence seq,
421
                            fc_shortcut *fcs, QString *ret);
422
  bool shortcut_2_menustring_inner(const QMenu *m, QKeySequence seq,
423
                                   QString *ret);
417 424
};
418 425

  
419 426
#endif /* FC__MENU_H */
420
- 
(1-1/2)