Skip to content

Commit ca85096

Browse files
committed
Simplify tooltip code
Use boost::algorithm::join to compress joining of vector elements in strings for tooltip.
1 parent 1ce7762 commit ca85096

File tree

3 files changed

+25
-43
lines changed

3 files changed

+25
-43
lines changed

src/qt/bitcoingui.cpp

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585

8686
#include <iostream>
8787
#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
88+
#include <boost/algorithm/string/join.hpp>
8889
#include "boinc.h"
8990
#include "util.h"
9091

@@ -1452,70 +1453,51 @@ void BitcoinGUI::updateScraperIcon(int scraperEventtype, int status)
14521453

14531454
int64_t nConvergenceTime = ConvergedScraperStatsCache.nTime;
14541455

1455-
std::string sExcludedProjects;
1456-
std::string sIncludedScrapers;
1457-
std::string sExcludedScrapers;
1458-
std::string sScrapersNotPublishing;
1456+
QString qsExcludedProjects;
1457+
QString qsIncludedScrapers;
1458+
QString qsExcludedScrapers;
1459+
QString qsScrapersNotPublishing;
14591460

14601461
bool bDisplayScrapers = false;
14611462

1463+
// Note that the translation macro tr is applied in the setToolTip call below.
14621464
// If the convergence cache has excluded projects...
14631465
if (!ConvergedScraperStatsCache.Convergence.vExcludedProjects.empty())
14641466
{
1465-
for (const auto& iter : ConvergedScraperStatsCache.Convergence.vExcludedProjects)
1466-
{
1467-
if (sExcludedProjects.empty())
1468-
sExcludedProjects += iter.first;
1469-
else
1470-
sExcludedProjects += ", " + iter.first;
1471-
}
1467+
qsExcludedProjects = QString(((std::string)boost::algorithm::join(ConvergedScraperStatsCache.Convergence.vExcludedProjects, ", ")).c_str());
14721468
}
14731469
else
14741470
{
1475-
sExcludedProjects = "none";
1471+
qsExcludedProjects = "none";
14761472
}
14771473

14781474
// If fDebug3 then show scrapers in tooltip...
14791475
if (fDebug3)
14801476
{
14811477
bDisplayScrapers = true;
14821478

1483-
for (const auto& iter : ConvergedScraperStatsCache.Convergence.vIncludedScrapers)
1484-
{
1485-
if (sIncludedScrapers.empty())
1486-
sIncludedScrapers += iter;
1487-
else
1488-
sIncludedScrapers += ", " + iter;
1489-
} // Don't need the else for empty here.
1479+
// No need to include "none" for included scrapers, because if no scrapers there will not be a convergence.
1480+
//sIncludedScrapers = boost::algorithm::join(ConvergedScraperStatsCache.Convergence.vIncludedScrapers, ", ");
1481+
// qsIncludedScrapers = sIncludedScrapers.c_str();
1482+
//sIncludedScrapers = boost::algorithm::join(ConvergedScraperStatsCache.Convergence.vIncludedScrapers, ", ");
1483+
qsIncludedScrapers = QString(((std::string)boost::algorithm::join(ConvergedScraperStatsCache.Convergence.vIncludedScrapers, ", ")).c_str());
14901484

14911485
if (!ConvergedScraperStatsCache.Convergence.vExcludedScrapers.empty())
14921486
{
1493-
for (const auto& iter : ConvergedScraperStatsCache.Convergence.vExcludedScrapers)
1494-
{
1495-
if (sExcludedScrapers.empty())
1496-
sExcludedScrapers += iter;
1497-
else
1498-
sExcludedScrapers += ", " + iter;
1499-
}
1487+
qsExcludedScrapers = QString(((std::string)boost::algorithm::join(ConvergedScraperStatsCache.Convergence.vExcludedScrapers, ", ")).c_str());
15001488
}
15011489
else
15021490
{
1503-
sExcludedScrapers = "none";
1491+
qsExcludedScrapers = "none";
15041492
}
15051493

15061494
if (ConvergedScraperStatsCache.Convergence.vScrapersNotPublishing.empty())
15071495
{
1508-
for (const auto& iter : ConvergedScraperStatsCache.Convergence.vScrapersNotPublishing)
1509-
{
1510-
if (sScrapersNotPublishing.empty())
1511-
sScrapersNotPublishing += iter;
1512-
else
1513-
sScrapersNotPublishing += ", " + iter;
1514-
}
1496+
qsScrapersNotPublishing = QString(((std::string)boost::algorithm::join(ConvergedScraperStatsCache.Convergence.vScrapersNotPublishing, ", ")).c_str());
15151497
}
15161498
else
15171499
{
1518-
sScrapersNotPublishing = "none";
1500+
qsScrapersNotPublishing = "none";
15191501
}
15201502
}
15211503

@@ -1547,17 +1529,17 @@ void BitcoinGUI::updateScraperIcon(int scraperEventtype, int status)
15471529
"Scraper(s) excluded: %4. \n"
15481530
"Scraper(s) not publishing: %5.")
15491531
.arg(QString(DateTimeStrFormat("%x %H:%M:%S", nConvergenceTime).c_str()))
1550-
.arg(QString(sExcludedProjects.c_str()))
1551-
.arg(QString(sIncludedScrapers.c_str()))
1552-
.arg(QString(sExcludedScrapers.c_str()))
1553-
.arg(QString(sScrapersNotPublishing.c_str())));
1532+
.arg(qsExcludedProjects)
1533+
.arg(qsIncludedScrapers)
1534+
.arg(qsExcludedScrapers)
1535+
.arg(qsScrapersNotPublishing));
15541536
}
15551537
else
15561538
{
15571539
labelScraperIcon->setToolTip(tr("Scraper: Convergence achieved, date/time %1 UTC. \n"
15581540
" Project(s) excluded: %2.")
15591541
.arg(QString(DateTimeStrFormat("%x %H:%M:%S", nConvergenceTime).c_str()))
1560-
.arg(QString(sExcludedProjects.c_str())));
1542+
.arg(qsExcludedProjects));
15611543
}
15621544
}
15631545
else if ((scraperEventtype == (int)scrapereventtypes::Convergence || scraperEventtype == (int)scrapereventtypes::SBContract)

src/scraper/fwd.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ struct ConvergedManifest
8080
// convergences by project.
8181
std::map<std::string, unsigned int> mScraperConvergenceCountbyProject;
8282

83-
// ------------------ project ----- reason for exclusion
84-
std::vector<std::pair<std::string, std::string>> vExcludedProjects;
83+
// --------- project
84+
std::vector<std::string> vExcludedProjects;
8585
};
8686

8787

src/scraper/scraper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4052,7 +4052,7 @@ bool ScraperConstructConvergedManifestByProject(const NN::WhitelistSnapshot& pro
40524052
if (StructConvergedManifest.ConvergedManifestPartsMap.find(iProjects.m_name) == StructConvergedManifest.ConvergedManifestPartsMap.end())
40534053
{
40544054
// Project in whitelist was not in the map, so it goes in the exclusion vector.
4055-
StructConvergedManifest.vExcludedProjects.push_back(std::make_pair(iProjects.m_name, "No convergence was found at the fallback (project) level."));
4055+
StructConvergedManifest.vExcludedProjects.push_back(iProjects.m_name);
40564056
_log(logattribute::WARNING, "ScraperConstructConvergedManifestByProject", "Project "
40574057
+ iProjects.m_name
40584058
+ " was excluded because there was no convergence from the scrapers for this project at the project level.");

0 commit comments

Comments
 (0)