From e74b984a0aca752459cd1596d27590f9a488b9d6 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 14 Jul 2019 11:46:10 +0800 Subject: [PATCH 1/4] Rely on Qt ownership to delete class members --- src/gui/previewselectdialog.cpp | 4 +--- src/gui/properties/propertieswidget.cpp | 13 ++----------- src/gui/properties/proptabbar.cpp | 5 ----- src/gui/properties/proptabbar.h | 2 +- src/gui/rss/feedlistwidget.cpp | 5 ----- src/gui/rss/feedlistwidget.h | 1 - src/gui/torrentcontentfiltermodel.cpp | 5 ----- src/gui/torrentcontentfiltermodel.h | 4 ++-- src/gui/transferlistwidget.cpp | 12 +++--------- 9 files changed, 9 insertions(+), 42 deletions(-) diff --git a/src/gui/previewselectdialog.cpp b/src/gui/previewselectdialog.cpp index 2ea6ebd1f..d6f139006 100644 --- a/src/gui/previewselectdialog.cpp +++ b/src/gui/previewselectdialog.cpp @@ -61,7 +61,7 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, BitTorrent::TorrentHan Preferences *const pref = Preferences::instance(); // Preview list - m_previewListModel = new QStandardItemModel(0, NB_COLUMNS); + m_previewListModel = new QStandardItemModel(0, NB_COLUMNS, this); m_previewListModel->setHeaderData(NAME, Qt::Horizontal, tr("Name")); m_previewListModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size")); m_previewListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress")); @@ -118,8 +118,6 @@ PreviewSelectDialog::~PreviewSelectDialog() { saveWindowState(); - delete m_previewListModel; - delete m_listDelegate; delete m_ui; } diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index e011f3bce..9cd7e7b96 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -82,7 +82,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent) m_state = VISIBLE; // Set Properties list model - m_propListModel = new TorrentContentFilterModel(); + m_propListModel = new TorrentContentFilterModel(this); m_ui->filesList->setModel(m_propListModel); m_propListDelegate = new PropListDelegate(this); m_ui->filesList->setItemDelegate(m_propListDelegate); @@ -142,7 +142,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent) m_peerList = new PeerListWidget(this); m_ui->vBoxLayoutPeerPage->addWidget(m_peerList); // Tab bar - m_tabBar = new PropTabBar(); + m_tabBar = new PropTabBar(nullptr); m_tabBar->setContentsMargins(0, 5, 0, 0); m_ui->verticalLayout->addLayout(m_tabBar); connect(m_tabBar, &PropTabBar::tabChanged, m_ui->stackedProperties, &QStackedWidget::setCurrentIndex); @@ -168,17 +168,8 @@ PropertiesWidget::PropertiesWidget(QWidget *parent) PropertiesWidget::~PropertiesWidget() { - qDebug() << Q_FUNC_INFO << "ENTER"; - delete m_trackerList; - delete m_peerList; - delete m_speedWidget; - delete m_downloadedPieces; - delete m_piecesAvailability; - delete m_propListModel; - delete m_propListDelegate; delete m_tabBar; delete m_ui; - qDebug() << Q_FUNC_INFO << "EXIT"; } void PropertiesWidget::showPiecesAvailability(bool show) diff --git a/src/gui/properties/proptabbar.cpp b/src/gui/properties/proptabbar.cpp index edb2eaaa3..56dcf531d 100644 --- a/src/gui/properties/proptabbar.cpp +++ b/src/gui/properties/proptabbar.cpp @@ -107,11 +107,6 @@ PropTabBar::PropTabBar(QWidget *parent) btn->setFocusPolicy(Qt::NoFocus); } -PropTabBar::~PropTabBar() -{ - delete m_btnGroup; -} - int PropTabBar::currentIndex() const { return m_currentIndex; diff --git a/src/gui/properties/proptabbar.h b/src/gui/properties/proptabbar.h index aa73c51f4..b49cfa752 100644 --- a/src/gui/properties/proptabbar.h +++ b/src/gui/properties/proptabbar.h @@ -50,7 +50,7 @@ public: }; explicit PropTabBar(QWidget *parent = nullptr); - ~PropTabBar(); + int currentIndex() const; signals: diff --git a/src/gui/rss/feedlistwidget.cpp b/src/gui/rss/feedlistwidget.cpp index 954f6733b..20fc172c3 100644 --- a/src/gui/rss/feedlistwidget.cpp +++ b/src/gui/rss/feedlistwidget.cpp @@ -71,11 +71,6 @@ FeedListWidget::FeedListWidget(QWidget *parent) // setCurrentItem(m_unreadStickyItem); } -FeedListWidget::~FeedListWidget() -{ - delete m_unreadStickyItem; -} - void FeedListWidget::handleItemAdded(RSS::Item *rssItem) { auto parentItem = m_rssToTreeItemMapping.value( diff --git a/src/gui/rss/feedlistwidget.h b/src/gui/rss/feedlistwidget.h index ec82ea592..e3cd65411 100644 --- a/src/gui/rss/feedlistwidget.h +++ b/src/gui/rss/feedlistwidget.h @@ -47,7 +47,6 @@ class FeedListWidget : public QTreeWidget public: explicit FeedListWidget(QWidget *parent); - ~FeedListWidget(); QTreeWidgetItem *stickyUnreadItem() const; QList getAllOpenedFolders(QTreeWidgetItem *parent = nullptr) const; diff --git a/src/gui/torrentcontentfiltermodel.cpp b/src/gui/torrentcontentfiltermodel.cpp index 78f14dd49..abb22ed4b 100644 --- a/src/gui/torrentcontentfiltermodel.cpp +++ b/src/gui/torrentcontentfiltermodel.cpp @@ -44,11 +44,6 @@ TorrentContentFilterModel::TorrentContentFilterModel(QObject *parent) setSortCaseSensitivity(Qt::CaseInsensitive); } -TorrentContentFilterModel::~TorrentContentFilterModel() -{ - delete m_model; -} - TorrentContentModel *TorrentContentFilterModel::model() const { return m_model; diff --git a/src/gui/torrentcontentfiltermodel.h b/src/gui/torrentcontentfiltermodel.h index 72a701f65..dff54304d 100644 --- a/src/gui/torrentcontentfiltermodel.h +++ b/src/gui/torrentcontentfiltermodel.h @@ -41,7 +41,6 @@ class TorrentContentFilterModel : public QSortFilterProxyModel public: TorrentContentFilterModel(QObject *parent = nullptr); - ~TorrentContentFilterModel() override; TorrentContentModel *model() const; TorrentContentModelItem::ItemType itemType(const QModelIndex &index) const; @@ -60,8 +59,9 @@ protected: bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; private: - TorrentContentModel *m_model; bool hasFiltered(const QModelIndex &folder) const; + + TorrentContentModel *m_model; }; #endif // TORRENTCONTENTFILTERMODEL_H diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index f86a56391..26727617b 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -114,7 +114,7 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *mainWindow) // Create transfer list model m_listModel = new TransferListModel(this); - m_sortFilterModel = new TransferListSortModel(); + m_sortFilterModel = new TransferListSortModel(this); m_sortFilterModel->setDynamicSortFilter(true); m_sortFilterModel->setSourceModel(m_listModel); m_sortFilterModel->setFilterKeyColumn(TransferListModel::TR_NAME); @@ -207,14 +207,8 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *mainWindow) TransferListWidget::~TransferListWidget() { - qDebug() << Q_FUNC_INFO << "ENTER"; // Save settings saveSettings(); - // Clean up - delete m_sortFilterModel; - delete m_listModel; - delete m_listDelegate; - qDebug() << Q_FUNC_INFO << "EXIT"; } TransferListModel *TransferListWidget::getSourceModel() const @@ -227,7 +221,7 @@ void TransferListWidget::previewFile(const QString &filePath) Utils::Gui::openPath(filePath); } -inline QModelIndex TransferListWidget::mapToSource(const QModelIndex &index) const +QModelIndex TransferListWidget::mapToSource(const QModelIndex &index) const { Q_ASSERT(index.isValid()); if (index.model() == m_sortFilterModel) @@ -235,7 +229,7 @@ inline QModelIndex TransferListWidget::mapToSource(const QModelIndex &index) con return index; } -inline QModelIndex TransferListWidget::mapFromSource(const QModelIndex &index) const +QModelIndex TransferListWidget::mapFromSource(const QModelIndex &index) const { Q_ASSERT(index.isValid()); Q_ASSERT(index.model() == m_sortFilterModel); From f9932305828ed94393354b0c45fd22d6975b0745 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 14 Jul 2019 16:50:05 +0800 Subject: [PATCH 2/4] Use uniform initialization --- src/base/net/geoipmanager.cpp | 511 +++++++++++++++++----------------- 1 file changed, 254 insertions(+), 257 deletions(-) diff --git a/src/base/net/geoipmanager.cpp b/src/base/net/geoipmanager.cpp index 15ffa4a6d..02d95a561 100644 --- a/src/base/net/geoipmanager.cpp +++ b/src/base/net/geoipmanager.cpp @@ -129,266 +129,263 @@ QString GeoIPManager::lookup(const QHostAddress &hostAddr) const QString GeoIPManager::CountryName(const QString &countryISOCode) { - static QHash countries; - static bool initialized = false; + static const QHash countries = { + // ISO 3166-1 alpha-2 codes + // http://www.iso.org/iso/home/standards/country_codes/country_names_and_code_elements_txt-temp.htm - // ISO 3166-1 alpha-2 codes - // http://www.iso.org/iso/home/standards/country_codes/country_names_and_code_elements_txt-temp.htm - if (!initialized) { // Officially assigned - countries["AD"] = tr("Andorra"); - countries["AE"] = tr("United Arab Emirates"); - countries["AF"] = tr("Afghanistan"); - countries["AG"] = tr("Antigua and Barbuda"); - countries["AI"] = tr("Anguilla"); - countries["AL"] = tr("Albania"); - countries["AM"] = tr("Armenia"); - countries["AO"] = tr("Angola"); - countries["AQ"] = tr("Antarctica"); - countries["AR"] = tr("Argentina"); - countries["AS"] = tr("American Samoa"); - countries["AT"] = tr("Austria"); - countries["AU"] = tr("Australia"); - countries["AW"] = tr("Aruba"); - countries["AX"] = tr("Aland Islands"); - countries["AZ"] = tr("Azerbaijan"); - countries["BA"] = tr("Bosnia and Herzegovina"); - countries["BB"] = tr("Barbados"); - countries["BD"] = tr("Bangladesh"); - countries["BE"] = tr("Belgium"); - countries["BF"] = tr("Burkina Faso"); - countries["BG"] = tr("Bulgaria"); - countries["BH"] = tr("Bahrain"); - countries["BI"] = tr("Burundi"); - countries["BJ"] = tr("Benin"); - countries["BL"] = tr("Saint Barthelemy"); - countries["BM"] = tr("Bermuda"); - countries["BN"] = tr("Brunei Darussalam"); - countries["BO"] = tr("Bolivia, Plurinational State of"); - countries["BQ"] = tr("Bonaire, Sint Eustatius and Saba"); - countries["BR"] = tr("Brazil"); - countries["BS"] = tr("Bahamas"); - countries["BT"] = tr("Bhutan"); - countries["BV"] = tr("Bouvet Island"); - countries["BW"] = tr("Botswana"); - countries["BY"] = tr("Belarus"); - countries["BZ"] = tr("Belize"); - countries["CA"] = tr("Canada"); - countries["CC"] = tr("Cocos (Keeling) Islands"); - countries["CD"] = tr("Congo, The Democratic Republic of the"); - countries["CF"] = tr("Central African Republic"); - countries["CG"] = tr("Congo"); - countries["CH"] = tr("Switzerland"); - countries["CI"] = tr("Cote d'Ivoire"); - countries["CK"] = tr("Cook Islands"); - countries["CL"] = tr("Chile"); - countries["CM"] = tr("Cameroon"); - countries["CN"] = tr("China"); - countries["CO"] = tr("Colombia"); - countries["CR"] = tr("Costa Rica"); - countries["CU"] = tr("Cuba"); - countries["CV"] = tr("Cape Verde"); - countries["CW"] = tr("Curacao"); - countries["CX"] = tr("Christmas Island"); - countries["CY"] = tr("Cyprus"); - countries["CZ"] = tr("Czech Republic"); - countries["DE"] = tr("Germany"); - countries["DJ"] = tr("Djibouti"); - countries["DK"] = tr("Denmark"); - countries["DM"] = tr("Dominica"); - countries["DO"] = tr("Dominican Republic"); - countries["DZ"] = tr("Algeria"); - countries["EC"] = tr("Ecuador"); - countries["EE"] = tr("Estonia"); - countries["EG"] = tr("Egypt"); - countries["EH"] = tr("Western Sahara"); - countries["ER"] = tr("Eritrea"); - countries["ES"] = tr("Spain"); - countries["ET"] = tr("Ethiopia"); - countries["FI"] = tr("Finland"); - countries["FJ"] = tr("Fiji"); - countries["FK"] = tr("Falkland Islands (Malvinas)"); - countries["FM"] = tr("Micronesia, Federated States of"); - countries["FO"] = tr("Faroe Islands"); - countries["FR"] = tr("France"); - countries["GA"] = tr("Gabon"); - countries["GB"] = tr("United Kingdom"); - countries["GD"] = tr("Grenada"); - countries["GE"] = tr("Georgia"); - countries["GF"] = tr("French Guiana"); - countries["GG"] = tr("Guernsey"); - countries["GH"] = tr("Ghana"); - countries["GI"] = tr("Gibraltar"); - countries["GL"] = tr("Greenland"); - countries["GM"] = tr("Gambia"); - countries["GN"] = tr("Guinea"); - countries["GP"] = tr("Guadeloupe"); - countries["GQ"] = tr("Equatorial Guinea"); - countries["GR"] = tr("Greece"); - countries["GS"] = tr("South Georgia and the South Sandwich Islands"); - countries["GT"] = tr("Guatemala"); - countries["GU"] = tr("Guam"); - countries["GW"] = tr("Guinea-Bissau"); - countries["GY"] = tr("Guyana"); - countries["HK"] = tr("Hong Kong"); - countries["HM"] = tr("Heard Island and McDonald Islands"); - countries["HN"] = tr("Honduras"); - countries["HR"] = tr("Croatia"); - countries["HT"] = tr("Haiti"); - countries["HU"] = tr("Hungary"); - countries["ID"] = tr("Indonesia"); - countries["IE"] = tr("Ireland"); - countries["IL"] = tr("Israel"); - countries["IM"] = tr("Isle of Man"); - countries["IN"] = tr("India"); - countries["IO"] = tr("British Indian Ocean Territory"); - countries["IQ"] = tr("Iraq"); - countries["IR"] = tr("Iran, Islamic Republic of"); - countries["IS"] = tr("Iceland"); - countries["IT"] = tr("Italy"); - countries["JE"] = tr("Jersey"); - countries["JM"] = tr("Jamaica"); - countries["JO"] = tr("Jordan"); - countries["JP"] = tr("Japan"); - countries["KE"] = tr("Kenya"); - countries["KG"] = tr("Kyrgyzstan"); - countries["KH"] = tr("Cambodia"); - countries["KI"] = tr("Kiribati"); - countries["KM"] = tr("Comoros"); - countries["KN"] = tr("Saint Kitts and Nevis"); - countries["KP"] = tr("Korea, Democratic People's Republic of"); - countries["KR"] = tr("Korea, Republic of"); - countries["KW"] = tr("Kuwait"); - countries["KY"] = tr("Cayman Islands"); - countries["KZ"] = tr("Kazakhstan"); - countries["LA"] = tr("Lao People's Democratic Republic"); - countries["LB"] = tr("Lebanon"); - countries["LC"] = tr("Saint Lucia"); - countries["LI"] = tr("Liechtenstein"); - countries["LK"] = tr("Sri Lanka"); - countries["LR"] = tr("Liberia"); - countries["LS"] = tr("Lesotho"); - countries["LT"] = tr("Lithuania"); - countries["LU"] = tr("Luxembourg"); - countries["LV"] = tr("Latvia"); - countries["LY"] = tr("Libya"); - countries["MA"] = tr("Morocco"); - countries["MC"] = tr("Monaco"); - countries["MD"] = tr("Moldova, Republic of"); - countries["ME"] = tr("Montenegro"); - countries["MF"] = tr("Saint Martin (French part)"); - countries["MG"] = tr("Madagascar"); - countries["MH"] = tr("Marshall Islands"); - countries["MK"] = tr("Macedonia, The Former Yugoslav Republic of"); - countries["ML"] = tr("Mali"); - countries["MM"] = tr("Myanmar"); - countries["MN"] = tr("Mongolia"); - countries["MO"] = tr("Macao"); - countries["MP"] = tr("Northern Mariana Islands"); - countries["MQ"] = tr("Martinique"); - countries["MR"] = tr("Mauritania"); - countries["MS"] = tr("Montserrat"); - countries["MT"] = tr("Malta"); - countries["MU"] = tr("Mauritius"); - countries["MV"] = tr("Maldives"); - countries["MW"] = tr("Malawi"); - countries["MX"] = tr("Mexico"); - countries["MY"] = tr("Malaysia"); - countries["MZ"] = tr("Mozambique"); - countries["NA"] = tr("Namibia"); - countries["NC"] = tr("New Caledonia"); - countries["NE"] = tr("Niger"); - countries["NF"] = tr("Norfolk Island"); - countries["NG"] = tr("Nigeria"); - countries["NI"] = tr("Nicaragua"); - countries["NL"] = tr("Netherlands"); - countries["NO"] = tr("Norway"); - countries["NP"] = tr("Nepal"); - countries["NR"] = tr("Nauru"); - countries["NU"] = tr("Niue"); - countries["NZ"] = tr("New Zealand"); - countries["OM"] = tr("Oman"); - countries["PA"] = tr("Panama"); - countries["PE"] = tr("Peru"); - countries["PF"] = tr("French Polynesia"); - countries["PG"] = tr("Papua New Guinea"); - countries["PH"] = tr("Philippines"); - countries["PK"] = tr("Pakistan"); - countries["PL"] = tr("Poland"); - countries["PM"] = tr("Saint Pierre and Miquelon"); - countries["PN"] = tr("Pitcairn"); - countries["PR"] = tr("Puerto Rico"); - countries["PS"] = tr("Palestine, State of"); - countries["PT"] = tr("Portugal"); - countries["PW"] = tr("Palau"); - countries["PY"] = tr("Paraguay"); - countries["QA"] = tr("Qatar"); - countries["RE"] = tr("Reunion"); - countries["RO"] = tr("Romania"); - countries["RS"] = tr("Serbia"); - countries["RU"] = tr("Russian Federation"); - countries["RW"] = tr("Rwanda"); - countries["SA"] = tr("Saudi Arabia"); - countries["SB"] = tr("Solomon Islands"); - countries["SC"] = tr("Seychelles"); - countries["SD"] = tr("Sudan"); - countries["SE"] = tr("Sweden"); - countries["SG"] = tr("Singapore"); - countries["SH"] = tr("Saint Helena, Ascension and Tristan da Cunha"); - countries["SI"] = tr("Slovenia"); - countries["SJ"] = tr("Svalbard and Jan Mayen"); - countries["SK"] = tr("Slovakia"); - countries["SL"] = tr("Sierra Leone"); - countries["SM"] = tr("San Marino"); - countries["SN"] = tr("Senegal"); - countries["SO"] = tr("Somalia"); - countries["SR"] = tr("Suriname"); - countries["SS"] = tr("South Sudan"); - countries["ST"] = tr("Sao Tome and Principe"); - countries["SV"] = tr("El Salvador"); - countries["SX"] = tr("Sint Maarten (Dutch part)"); - countries["SY"] = tr("Syrian Arab Republic"); - countries["SZ"] = tr("Swaziland"); - countries["TC"] = tr("Turks and Caicos Islands"); - countries["TD"] = tr("Chad"); - countries["TF"] = tr("French Southern Territories"); - countries["TG"] = tr("Togo"); - countries["TH"] = tr("Thailand"); - countries["TJ"] = tr("Tajikistan"); - countries["TK"] = tr("Tokelau"); - countries["TL"] = tr("Timor-Leste"); - countries["TM"] = tr("Turkmenistan"); - countries["TN"] = tr("Tunisia"); - countries["TO"] = tr("Tonga"); - countries["TR"] = tr("Turkey"); - countries["TT"] = tr("Trinidad and Tobago"); - countries["TV"] = tr("Tuvalu"); - countries["TW"] = tr("Taiwan"); - countries["TZ"] = tr("Tanzania, United Republic of"); - countries["UA"] = tr("Ukraine"); - countries["UG"] = tr("Uganda"); - countries["UM"] = tr("United States Minor Outlying Islands"); - countries["US"] = tr("United States"); - countries["UY"] = tr("Uruguay"); - countries["UZ"] = tr("Uzbekistan"); - countries["VA"] = tr("Holy See (Vatican City State)"); - countries["VC"] = tr("Saint Vincent and the Grenadines"); - countries["VE"] = tr("Venezuela, Bolivarian Republic of"); - countries["VG"] = tr("Virgin Islands, British"); - countries["VI"] = tr("Virgin Islands, U.S."); - countries["VN"] = tr("Viet Nam"); - countries["VU"] = tr("Vanuatu"); - countries["WF"] = tr("Wallis and Futuna"); - countries["WS"] = tr("Samoa"); - countries["YE"] = tr("Yemen"); - countries["YT"] = tr("Mayotte"); - countries["ZA"] = tr("South Africa"); - countries["ZM"] = tr("Zambia"); - countries["ZW"] = tr("Zimbabwe"); + {"AD", tr("Andorra")}, + {"AE", tr("United Arab Emirates")}, + {"AF", tr("Afghanistan")}, + {"AG", tr("Antigua and Barbuda")}, + {"AI", tr("Anguilla")}, + {"AL", tr("Albania")}, + {"AM", tr("Armenia")}, + {"AO", tr("Angola")}, + {"AQ", tr("Antarctica")}, + {"AR", tr("Argentina")}, + {"AS", tr("American Samoa")}, + {"AT", tr("Austria")}, + {"AU", tr("Australia")}, + {"AW", tr("Aruba")}, + {"AX", tr("Aland Islands")}, + {"AZ", tr("Azerbaijan")}, + {"BA", tr("Bosnia and Herzegovina")}, + {"BB", tr("Barbados")}, + {"BD", tr("Bangladesh")}, + {"BE", tr("Belgium")}, + {"BF", tr("Burkina Faso")}, + {"BG", tr("Bulgaria")}, + {"BH", tr("Bahrain")}, + {"BI", tr("Burundi")}, + {"BJ", tr("Benin")}, + {"BL", tr("Saint Barthelemy")}, + {"BM", tr("Bermuda")}, + {"BN", tr("Brunei Darussalam")}, + {"BO", tr("Bolivia, Plurinational State of")}, + {"BQ", tr("Bonaire, Sint Eustatius and Saba")}, + {"BR", tr("Brazil")}, + {"BS", tr("Bahamas")}, + {"BT", tr("Bhutan")}, + {"BV", tr("Bouvet Island")}, + {"BW", tr("Botswana")}, + {"BY", tr("Belarus")}, + {"BZ", tr("Belize")}, + {"CA", tr("Canada")}, + {"CC", tr("Cocos (Keeling) Islands")}, + {"CD", tr("Congo, The Democratic Republic of the")}, + {"CF", tr("Central African Republic")}, + {"CG", tr("Congo")}, + {"CH", tr("Switzerland")}, + {"CI", tr("Cote d'Ivoire")}, + {"CK", tr("Cook Islands")}, + {"CL", tr("Chile")}, + {"CM", tr("Cameroon")}, + {"CN", tr("China")}, + {"CO", tr("Colombia")}, + {"CR", tr("Costa Rica")}, + {"CU", tr("Cuba")}, + {"CV", tr("Cape Verde")}, + {"CW", tr("Curacao")}, + {"CX", tr("Christmas Island")}, + {"CY", tr("Cyprus")}, + {"CZ", tr("Czech Republic")}, + {"DE", tr("Germany")}, + {"DJ", tr("Djibouti")}, + {"DK", tr("Denmark")}, + {"DM", tr("Dominica")}, + {"DO", tr("Dominican Republic")}, + {"DZ", tr("Algeria")}, + {"EC", tr("Ecuador")}, + {"EE", tr("Estonia")}, + {"EG", tr("Egypt")}, + {"EH", tr("Western Sahara")}, + {"ER", tr("Eritrea")}, + {"ES", tr("Spain")}, + {"ET", tr("Ethiopia")}, + {"FI", tr("Finland")}, + {"FJ", tr("Fiji")}, + {"FK", tr("Falkland Islands (Malvinas)")}, + {"FM", tr("Micronesia, Federated States of")}, + {"FO", tr("Faroe Islands")}, + {"FR", tr("France")}, + {"GA", tr("Gabon")}, + {"GB", tr("United Kingdom")}, + {"GD", tr("Grenada")}, + {"GE", tr("Georgia")}, + {"GF", tr("French Guiana")}, + {"GG", tr("Guernsey")}, + {"GH", tr("Ghana")}, + {"GI", tr("Gibraltar")}, + {"GL", tr("Greenland")}, + {"GM", tr("Gambia")}, + {"GN", tr("Guinea")}, + {"GP", tr("Guadeloupe")}, + {"GQ", tr("Equatorial Guinea")}, + {"GR", tr("Greece")}, + {"GS", tr("South Georgia and the South Sandwich Islands")}, + {"GT", tr("Guatemala")}, + {"GU", tr("Guam")}, + {"GW", tr("Guinea-Bissau")}, + {"GY", tr("Guyana")}, + {"HK", tr("Hong Kong")}, + {"HM", tr("Heard Island and McDonald Islands")}, + {"HN", tr("Honduras")}, + {"HR", tr("Croatia")}, + {"HT", tr("Haiti")}, + {"HU", tr("Hungary")}, + {"ID", tr("Indonesia")}, + {"IE", tr("Ireland")}, + {"IL", tr("Israel")}, + {"IM", tr("Isle of Man")}, + {"IN", tr("India")}, + {"IO", tr("British Indian Ocean Territory")}, + {"IQ", tr("Iraq")}, + {"IR", tr("Iran, Islamic Republic of")}, + {"IS", tr("Iceland")}, + {"IT", tr("Italy")}, + {"JE", tr("Jersey")}, + {"JM", tr("Jamaica")}, + {"JO", tr("Jordan")}, + {"JP", tr("Japan")}, + {"KE", tr("Kenya")}, + {"KG", tr("Kyrgyzstan")}, + {"KH", tr("Cambodia")}, + {"KI", tr("Kiribati")}, + {"KM", tr("Comoros")}, + {"KN", tr("Saint Kitts and Nevis")}, + {"KP", tr("Korea, Democratic People's Republic of")}, + {"KR", tr("Korea, Republic of")}, + {"KW", tr("Kuwait")}, + {"KY", tr("Cayman Islands")}, + {"KZ", tr("Kazakhstan")}, + {"LA", tr("Lao People's Democratic Republic")}, + {"LB", tr("Lebanon")}, + {"LC", tr("Saint Lucia")}, + {"LI", tr("Liechtenstein")}, + {"LK", tr("Sri Lanka")}, + {"LR", tr("Liberia")}, + {"LS", tr("Lesotho")}, + {"LT", tr("Lithuania")}, + {"LU", tr("Luxembourg")}, + {"LV", tr("Latvia")}, + {"LY", tr("Libya")}, + {"MA", tr("Morocco")}, + {"MC", tr("Monaco")}, + {"MD", tr("Moldova, Republic of")}, + {"ME", tr("Montenegro")}, + {"MF", tr("Saint Martin (French part)")}, + {"MG", tr("Madagascar")}, + {"MH", tr("Marshall Islands")}, + {"MK", tr("Macedonia, The Former Yugoslav Republic of")}, + {"ML", tr("Mali")}, + {"MM", tr("Myanmar")}, + {"MN", tr("Mongolia")}, + {"MO", tr("Macao")}, + {"MP", tr("Northern Mariana Islands")}, + {"MQ", tr("Martinique")}, + {"MR", tr("Mauritania")}, + {"MS", tr("Montserrat")}, + {"MT", tr("Malta")}, + {"MU", tr("Mauritius")}, + {"MV", tr("Maldives")}, + {"MW", tr("Malawi")}, + {"MX", tr("Mexico")}, + {"MY", tr("Malaysia")}, + {"MZ", tr("Mozambique")}, + {"NA", tr("Namibia")}, + {"NC", tr("New Caledonia")}, + {"NE", tr("Niger")}, + {"NF", tr("Norfolk Island")}, + {"NG", tr("Nigeria")}, + {"NI", tr("Nicaragua")}, + {"NL", tr("Netherlands")}, + {"NO", tr("Norway")}, + {"NP", tr("Nepal")}, + {"NR", tr("Nauru")}, + {"NU", tr("Niue")}, + {"NZ", tr("New Zealand")}, + {"OM", tr("Oman")}, + {"PA", tr("Panama")}, + {"PE", tr("Peru")}, + {"PF", tr("French Polynesia")}, + {"PG", tr("Papua New Guinea")}, + {"PH", tr("Philippines")}, + {"PK", tr("Pakistan")}, + {"PL", tr("Poland")}, + {"PM", tr("Saint Pierre and Miquelon")}, + {"PN", tr("Pitcairn")}, + {"PR", tr("Puerto Rico")}, + {"PS", tr("Palestine, State of")}, + {"PT", tr("Portugal")}, + {"PW", tr("Palau")}, + {"PY", tr("Paraguay")}, + {"QA", tr("Qatar")}, + {"RE", tr("Reunion")}, + {"RO", tr("Romania")}, + {"RS", tr("Serbia")}, + {"RU", tr("Russian Federation")}, + {"RW", tr("Rwanda")}, + {"SA", tr("Saudi Arabia")}, + {"SB", tr("Solomon Islands")}, + {"SC", tr("Seychelles")}, + {"SD", tr("Sudan")}, + {"SE", tr("Sweden")}, + {"SG", tr("Singapore")}, + {"SH", tr("Saint Helena, Ascension and Tristan da Cunha")}, + {"SI", tr("Slovenia")}, + {"SJ", tr("Svalbard and Jan Mayen")}, + {"SK", tr("Slovakia")}, + {"SL", tr("Sierra Leone")}, + {"SM", tr("San Marino")}, + {"SN", tr("Senegal")}, + {"SO", tr("Somalia")}, + {"SR", tr("Suriname")}, + {"SS", tr("South Sudan")}, + {"ST", tr("Sao Tome and Principe")}, + {"SV", tr("El Salvador")}, + {"SX", tr("Sint Maarten (Dutch part)")}, + {"SY", tr("Syrian Arab Republic")}, + {"SZ", tr("Swaziland")}, + {"TC", tr("Turks and Caicos Islands")}, + {"TD", tr("Chad")}, + {"TF", tr("French Southern Territories")}, + {"TG", tr("Togo")}, + {"TH", tr("Thailand")}, + {"TJ", tr("Tajikistan")}, + {"TK", tr("Tokelau")}, + {"TL", tr("Timor-Leste")}, + {"TM", tr("Turkmenistan")}, + {"TN", tr("Tunisia")}, + {"TO", tr("Tonga")}, + {"TR", tr("Turkey")}, + {"TT", tr("Trinidad and Tobago")}, + {"TV", tr("Tuvalu")}, + {"TW", tr("Taiwan")}, + {"TZ", tr("Tanzania, United Republic of")}, + {"UA", tr("Ukraine")}, + {"UG", tr("Uganda")}, + {"UM", tr("United States Minor Outlying Islands")}, + {"US", tr("United States")}, + {"UY", tr("Uruguay")}, + {"UZ", tr("Uzbekistan")}, + {"VA", tr("Holy See (Vatican City State)")}, + {"VC", tr("Saint Vincent and the Grenadines")}, + {"VE", tr("Venezuela, Bolivarian Republic of")}, + {"VG", tr("Virgin Islands, British")}, + {"VI", tr("Virgin Islands, U.S.")}, + {"VN", tr("Viet Nam")}, + {"VU", tr("Vanuatu")}, + {"WF", tr("Wallis and Futuna")}, + {"WS", tr("Samoa")}, + {"YE", tr("Yemen")}, + {"YT", tr("Mayotte")}, + {"ZA", tr("South Africa")}, + {"ZM", tr("Zambia")}, + {"ZW", tr("Zimbabwe")}, - countries[QString()] = tr("N/A"); - initialized = true; - } + {{}, tr("N/A")} + }; return countries.value(countryISOCode, tr("N/A")); } From f6f8aaf3db071d9ba7796494dd15a1ea3326ee37 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 14 Jul 2019 17:22:17 +0800 Subject: [PATCH 3/4] Put internal function into anonymous namespace --- src/base/net/reverseresolution.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/base/net/reverseresolution.cpp b/src/base/net/reverseresolution.cpp index 116de9ef0..89ebf1c6f 100644 --- a/src/base/net/reverseresolution.cpp +++ b/src/base/net/reverseresolution.cpp @@ -36,9 +36,12 @@ const int CACHE_SIZE = 500; using namespace Net; -static inline bool isUsefulHostName(const QString &hostname, const QString &ip) +namespace { - return (!hostname.isEmpty() && (hostname != ip)); + bool isUsefulHostName(const QString &hostname, const QString &ip) + { + return (!hostname.isEmpty() && (hostname != ip)); + } } ReverseResolution::ReverseResolution(QObject *parent) From 7a5e883cd292060cb6a73a98a77c88acba33b904 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 14 Jul 2019 17:26:56 +0800 Subject: [PATCH 4/4] Revise inline keyword usage And let compiler decide whether to inline functions. --- src/base/profile.cpp | 5 +++++ src/base/profile.h | 5 +---- src/webui/webapplication.cpp | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/base/profile.cpp b/src/base/profile.cpp index 6facc409e..f8261a578 100644 --- a/src/base/profile.cpp +++ b/src/base/profile.cpp @@ -112,3 +112,8 @@ QString Profile::fromPortablePath(const QString &portablePath) const { return m_pathConverterImpl->fromPortablePath(portablePath); } + +QString specialFolderLocation(const SpecialFolder folder) +{ + return Profile::instance().location(folder); +} diff --git a/src/base/profile.h b/src/base/profile.h index ce52193de..40f672fc1 100644 --- a/src/base/profile.h +++ b/src/base/profile.h @@ -83,9 +83,6 @@ private: static Profile *m_instance; }; -inline QString specialFolderLocation(SpecialFolder folder) -{ - return Profile::instance().location(folder); -} +QString specialFolderLocation(SpecialFolder folder); #endif // QBT_PROFILE_H diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index 8a38318e9..709abd481 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -88,7 +88,7 @@ namespace return ret; } - inline QUrl urlFromHostHeader(const QString &hostHeader) + QUrl urlFromHostHeader(const QString &hostHeader) { if (!hostHeader.contains(QLatin1String("://"))) return {QLatin1String("http://") + hostHeader};