Compare commits
	
		
			4 commits
		
	
	
		
			main
			...
			orangerot-
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | d55c6fb611 | ||
|  | efeec3b99e | ||
|  | cf013eb832 | ||
|  | 71aee728b7 | 
							
								
								
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | |||
| [submodule "external/QJsonModel"] | ||||
| 	path = external/QJsonModel | ||||
| 	url = https://github.com/dridk/QJsonModel.git | ||||
|  | @ -3,14 +3,37 @@ project(itat_challange_olympics) | |||
| 
 | ||||
| set(CMAKE_CXX_STANDARD 17) | ||||
| 
 | ||||
| add_executable(itat_challange_olympics main.cpp) | ||||
| find_package(Qt6 COMPONENTS | ||||
| 	Core REQUIRED | ||||
| 	Gui REQUIRED | ||||
| 	Widgets REQUIRED | ||||
|   Network REQUIRED | ||||
|   Quick REQUIRED | ||||
| ) | ||||
| 
 | ||||
| find_package(Qt6 REQUIRED COMPONENTS Core) | ||||
| target_link_libraries(itat_challange_olympics PRIVATE Qt6::Core) | ||||
| # SET(MODULES_EXTERNAL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external) | ||||
| 
 | ||||
| find_package(Qt6 REQUIRED COMPONENTS Quick) | ||||
| target_link_libraries(itat_challange_olympics PRIVATE Qt6::Quick) | ||||
| # include_directories(BEFORE ${MODULES_EXTERNAL_DIR}) | ||||
| 
 | ||||
| find_package(Qt6 REQUIRED COMPONENTS Network) | ||||
| target_link_libraries(itat_challange_olympics PRIVATE Qt6::Network) | ||||
| set(CMAKE_AUTORCC ON) | ||||
| set(CMAKE_AUTOMOC ON) | ||||
| set(CMAKE_AUTOUIC ON) | ||||
| qt_add_executable(itat_challange_olympics application.qrc main.cpp | ||||
|   external/QJsonModel/include/QJsonModel.hpp | ||||
|   external/QJsonModel/QJsonModel.cpp) | ||||
| 
 | ||||
| target_include_directories(itat_challange_olympics PRIVATE | ||||
|   external/QJsonModel/include) | ||||
| 
 | ||||
| # add_subdirectory(${MODULES_EXTERNAL_DIR}/QJsonModel) | ||||
| # target_link_libraries(itat_challange_olympics PRIVATE Qt6::QJsonModelStatic) | ||||
| # target_include_directories(itat_challange_olympics PRIVATE ${CMAKE_BINARY_DIR}/include) | ||||
| 
 | ||||
| target_link_libraries(itat_challange_olympics | ||||
| PUBLIC | ||||
| 	Qt6::Core | ||||
| 	Qt6::Gui | ||||
| 	Qt6::Widgets | ||||
|   Qt6::Network | ||||
|   Qt6::Quick | ||||
| ) | ||||
|  |  | |||
							
								
								
									
										27
									
								
								EventInfoPage.qml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								EventInfoPage.qml
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,27 @@ | |||
| import QtQuick | ||||
| import QtQuick.Layouts | ||||
| import QtQuick.Controls | ||||
| 
 | ||||
| Page { | ||||
|   id: root | ||||
|   property string event_id | ||||
| 
 | ||||
|   header: ToolBar { | ||||
|     ToolButton { | ||||
|       text: qsTr("Back") | ||||
|       anchors.left: parent.left | ||||
|       anchors.leftMargin: 10 | ||||
|       anchors.verticalCenter: parent.verticalCenter | ||||
|       onClicked: root.StackView.view.pop() | ||||
|     } | ||||
|     Label { | ||||
|       id: pageTitle | ||||
|       font.pixelSize: 20 | ||||
|       anchors.centerIn: parent | ||||
|       text: qsTr("Event Info") | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
							
								
								
									
										38
									
								
								EventsPage.qml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								EventsPage.qml
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,38 @@ | |||
| import QtQuick | ||||
| import QtQuick.Controls | ||||
| 
 | ||||
| Page { | ||||
|   id: root | ||||
|   header: ToolBar { | ||||
|     Label { | ||||
|       text: qsTr("Olympia 2024 Events") | ||||
|       font.pixelSize: 20 | ||||
|       anchors.centerIn: parent | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   ListView { | ||||
|     id: listView | ||||
|     objectName: eventsList | ||||
|     anchors.fill: parent | ||||
|     topMargin: 48 | ||||
|     leftMargin: 48 | ||||
|     bottomMargin: 48 | ||||
|     rightMargin: 48 | ||||
|     spacing: 20 | ||||
|     model: ["Albert Einstein", "Ernest Hemingway", "Hans Gude"] | ||||
|     delegate: ItemDelegate { | ||||
|       text: modelData | ||||
|       width: listView.width - listView.leftMargin - listView.rightMargin | ||||
|       height: avatar.implicitHeight + 32 | ||||
|       leftPadding: avatar.implicitWidth + 32 | ||||
|       onClicked: root.StackView.view.push("EventInfoPage.qml", { event_id: 1 }) | ||||
| 
 | ||||
|       Image { | ||||
|         id: avatar | ||||
|         // source: "images/" + modelData.replace(" ", "_") + ".png" | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
| 
 | ||||
|  | @ -2,12 +2,24 @@ import QtQuick | |||
| import QtQuick.Controls | ||||
| 
 | ||||
| ApplicationWindow { | ||||
|     width: 400 | ||||
|     height: 400 | ||||
|     visible: true | ||||
|   width: 400 | ||||
|   height: 400 | ||||
|   visible: true | ||||
| 
 | ||||
|     Button { | ||||
|         id: button | ||||
|         text: "A Special Button" | ||||
|   TreeView { | ||||
|     id: listView | ||||
|     anchors.fill: parent | ||||
|     model: sports // This will reference the model added to the context | ||||
|     delegate: ItemDelegate {  | ||||
|       text: eventName | ||||
|     } | ||||
|     Component.onCompleted : console.log(Object.keys(sports.data)) | ||||
|   } | ||||
| 
 | ||||
|   // StackView { | ||||
|   //   id: stackView | ||||
|   //   anchors.fill: parent | ||||
|   //   initialItem: EventsPage {} | ||||
|   // } | ||||
| } | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										6
									
								
								application.qrc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								application.qrc
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,6 @@ | |||
| <!DOCTYPE RCC><RCC version="1.0"> | ||||
| <qresource prefix="/"> | ||||
|     <file>qtquickcontrols2.conf</file> | ||||
| </qresource> | ||||
| </RCC> | ||||
| 
 | ||||
							
								
								
									
										1
									
								
								external/QJsonModel
									
									
									
									
										vendored
									
									
										Submodule
									
								
							
							
								
								
								
								
								
								
							
						
						
									
										1
									
								
								external/QJsonModel
									
									
									
									
										vendored
									
									
										Submodule
									
								
							|  | @ -0,0 +1 @@ | |||
| Subproject commit ed3652666d4954c2262eb5ceee8fda3e613f8c0c | ||||
							
								
								
									
										43
									
								
								main.cpp
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								main.cpp
									
									
									
									
									
								
							|  | @ -19,21 +19,38 @@ | |||
| 
 | ||||
| // console output
 | ||||
| #include <QDebug> | ||||
| #include <qlogging.h> | ||||
| // #include <iostream>
 | ||||
| 
 | ||||
| #include "QJsonModel.hpp" | ||||
| #include <QTreeView> | ||||
| #include <QApplication> | ||||
| 
 | ||||
| int main(int argc, char *argv[]) | ||||
| { | ||||
|     QGuiApplication app(argc, argv); | ||||
|     QApplication app(argc, argv); | ||||
| 
 | ||||
|     QQmlEngine engine; | ||||
|     QQmlContext *objectContext = new QQmlContext(engine.rootContext()); | ||||
| 
 | ||||
|     QQmlComponent component(&engine, "application.qml"); | ||||
|     QObject *object = component.create(objectContext); | ||||
| 
 | ||||
|     QStringList dataList = { | ||||
|       "Item 1", | ||||
|       "Item 2", | ||||
|       "Item 3", | ||||
|       "Item 4" | ||||
|     }; | ||||
| 
 | ||||
|     //objectContext->setContextProperty("sports", QVariant::fromValue(dataList));
 | ||||
| 
 | ||||
|     //QQmlComponent component(&engine, "application.qml");
 | ||||
|     //QObject *object = component.create(objectContext);
 | ||||
|     // QObject *eventsList = object->findChild<QObject*>("eventsList");
 | ||||
|     // QQmlContext *componentContext = component.creationContext();
 | ||||
|     // ... delete object and objectContext when necessary
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|    // create custom temporary event loop on stack
 | ||||
|     QEventLoop eventLoop; | ||||
| 
 | ||||
|  | @ -53,12 +70,30 @@ int main(int argc, char *argv[]) | |||
| 
 | ||||
|         QString strReply = (QString)reply->readAll(); | ||||
| 
 | ||||
| 
 | ||||
|         //parse json
 | ||||
|         // qDebug() << "Response:" << strReply;
 | ||||
|         QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8()); | ||||
| 
 | ||||
|         QJsonObject jsonObj = jsonResponse.object(); | ||||
| 
 | ||||
|         QJsonModel * model = new QJsonModel(); | ||||
|         // qDebug() << QJsonDocument(jsonObj["units"].toArray()).toJson();
 | ||||
|         // model->loadJson(QJsonDocument(jsonObj["units"].toArray()).toJson());
 | ||||
|         model->loadJson(strReply.toUtf8()); | ||||
| 
 | ||||
|         objectContext->setContextProperty("sports", QVariant::fromValue(model)); | ||||
|         // componentContext->setContextProperty("sports", model);
 | ||||
| 
 | ||||
|         // objectContext->setContextProperty("sports", QVariant::fromValue(dataList));
 | ||||
| 
 | ||||
|         QQmlComponent component(&engine, "application.qml"); | ||||
|         QObject *object = component.create(objectContext); | ||||
| 
 | ||||
| 
 | ||||
|         QTreeView * view = new QTreeView; | ||||
|         view->setModel(model); | ||||
|         view->show(); | ||||
|          | ||||
|         qDebug() << "Competitor:" << jsonObj["units"][0]["competitors"][0]["name"].toString(); | ||||
| 
 | ||||
|         delete reply; | ||||
|  |  | |||
							
								
								
									
										12
									
								
								qtquickcontrols2.conf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								qtquickcontrols2.conf
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,12 @@ | |||
| [Controls] | ||||
| Style=Material | ||||
| 
 | ||||
| [Universal] | ||||
| Theme=Material | ||||
| Accent=Red | ||||
| 
 | ||||
| [Material] | ||||
| Theme=Light | ||||
| Accent=Teal | ||||
| Primary=BlueGrey | ||||
| 
 | ||||
		Loading…
	
		Reference in a new issue