-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
138 lines (94 loc) · 3.93 KB
/
main.cpp
File metadata and controls
138 lines (94 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// -----------------------------------------------------------
// ===========================================================
// INCLUDES
// ===========================================================
// HEADER
#include "main.hpp"
#if defined( Q_DEBUG ) || defined( DEBUG ) // DEBUG
#include <QDebug>
#endif // DEBUG
// ===========================================================
// METHODS
// ===========================================================
QString getPrivateDataDir( ) noexcept
{
// Get Paths to Home-Dir.
const auto pathList = QStandardPaths::standardLocations( QStandardPaths::HomeLocation );
// Extract first available path.
const QString homeDirPath = pathList.first( ).split( QDir::separator( ) ).last( );
#if defined( QT_DEBUG ) || defined( DEBUG ) // DEBUG
// Print path to a Debug-Output.
qDebug( ) << "HomeDir=" << homeDirPath ;
#endif // DEBUG
// Return Path to a Home-Dir.
return( homeDirPath );
}
int main(int argc, char *argv[])
{
// Enable DPI Scaling
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
// Set Organization Name
QCoreApplication::setOrganizationName( "C0DE4UN INC." );
// Set Application Name
QCoreApplication::setApplicationName( "QRSSReader" );
// Set Home-Dir.
MainWindowLogic::mHomeDir = getPrivateDataDir( );
// Set Version
QCoreApplication::setApplicationVersion( "1.0" );
// Create GUI Application
QGuiApplication app(argc, argv);
// Register MainWindowLogic.
qmlRegisterType<MainWindowLogic>( "MainWindowLogic", 1, 0, "MainWindowLogic" );
// Register ChannelModel Type within QML.
qmlRegisterType<rss::ChannelModel>( "ChannelModel", 1, 0, "ChannelModel" );
// Register ProxyChannelModel Type in QML.
qmlRegisterType<rss::ProxyChannelModel>( "ProxyChannelModel", 1, 0, "ProxyChannelModel" );
// Create QML Application Enigne
QQmlApplicationEngine engine;
// Create ChannelsModel.
rss::ChannelModel *const channelModel( new rss::ChannelModel( ) );
// Create Proxy-ChannelModel.
rss::ProxyChannelModel *const proxyChannelModel( new rss::ProxyChannelModel( ) );
// Configure ProxyChannelModel instance.
//proxyChannelModel->setSortOrder( Qt::SortOrder::DescendingOrder );
//proxyChannelModel->setSortCaseSensitivity( Qt::CaseSensitivity::CaseSensitive );
//proxyChannelModel->setSortRole( "pubDate" );
// Set Proxy-Model Source.
proxyChannelModel->setSourceModel( channelModel );
// Get root-Context.
QQmlContext *const rootContext( engine.rootContext( ) );
// Make ChannelModel available for all Views.
rootContext->setContextProperty( "rssModel", channelModel );
// Make ProxyChannelModel available for all Views.
rootContext->setContextProperty( "proxyRssModel", proxyChannelModel );
// QML
const QUrl url(QStringLiteral("qrc:/main.qml"));
// Connect Engine & Application
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
// Load QML
engine.load(url);
//QWindow
QWindow *const rootWindow( qobject_cast<QWindow*>( engine.rootObjects( ).first( ) ) );
#if defined( Q_DEBUG ) || defined( DEBUG ) // DEBUG
//qDebug( rootWindow-> );
const QVariant windowName = rootWindow->property( "name" );
// Check root-Window
assert( windowName.toString( ) == "mainWindow" && "main.hpp - root Window missmatch !" );
#endif // DEBUG
// Set root-Window
MainWindowLogic::mMainWindowLogicInstance->mMainWindow = rootWindow;
// Set Engine
MainWindowLogic::mMainWindowLogicInstance->mQQmlApplicationEngine = &engine;
const auto returnCode( app.exec( ) );
// Delete ChannelModel.
delete channelModel;
// Delete ProxyChannelModel.
delete proxyChannelModel;
// Execute QT Application
return( returnCode );
}
// -----------------------------------------------------------