Skip to content

Commit 7b8d134

Browse files
committed
qml: set and expose the current network name from the ChainModel
1 parent 0dd350e commit 7b8d134

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/qml/bitcoin.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ int QmlGuiMain(int argc, char* argv[])
175175
// QObject::connect(&init_executor, &InitExecutor::runawayException, &node_model, &NodeModel::handleRunawayException);
176176

177177
ChainModel chain_model{*chain};
178+
chain_model.setCurrentNetworkName(QString::fromStdString(gArgs.GetChainName()));
178179

179180
QObject::connect(&node_model, &NodeModel::setTimeRatioList, &chain_model, &ChainModel::setTimeRatioList);
180181
QObject::connect(&node_model, &NodeModel::setTimeRatioListInitial, &chain_model, &ChainModel::setTimeRatioListInitial);

src/qml/chainmodel.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <qml/chainmodel.h>
66

77
#include <QDateTime>
8+
#include <QString>
89
#include <QThread>
910
#include <QTime>
1011
#include <interfaces/chain.h>
@@ -21,6 +22,12 @@ ChainModel::ChainModel(interfaces::Chain& chain)
2122
timer_thread->start();
2223
}
2324

25+
void ChainModel::setCurrentNetworkName(QString network_name)
26+
{
27+
m_current_network_name = network_name.toUpper();
28+
Q_EMIT currentNetworkNameChanged();
29+
}
30+
2431
void ChainModel::setTimeRatioList(int new_time)
2532
{
2633
if (m_time_ratio_list.isEmpty()) {

src/qml/chainmodel.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <interfaces/chain.h>
99

1010
#include <QObject>
11+
#include <QString>
1112
#include <QTimer>
1213
#include <QVariant>
1314

@@ -21,11 +22,14 @@ static const int SECS_IN_12_HOURS = 43200;
2122
class ChainModel : public QObject
2223
{
2324
Q_OBJECT
25+
Q_PROPERTY(QString currentNetworkName READ currentNetworkName WRITE setCurrentNetworkName NOTIFY currentNetworkNameChanged)
2426
Q_PROPERTY(QVariantList timeRatioList READ timeRatioList NOTIFY timeRatioListChanged)
2527

2628
public:
2729
explicit ChainModel(interfaces::Chain& chain);
2830

31+
QString currentNetworkName() const { return m_current_network_name; };
32+
void setCurrentNetworkName(QString network_name);
2933
QVariantList timeRatioList() const { return m_time_ratio_list; };
3034

3135
int timestampAtMeridian();
@@ -38,8 +42,10 @@ public Q_SLOTS:
3842

3943
Q_SIGNALS:
4044
void timeRatioListChanged();
45+
void currentNetworkNameChanged();
4146

4247
private:
48+
QString m_current_network_name;
4349
/* time_ratio: Ratio between the time at which an event
4450
* happened and 12 hours. So, for example, if a block is
4551
* found at 4 am or pm, the time_ratio would be 0.3.

0 commit comments

Comments
 (0)