Commit 30b84d1d authored by rahulde's avatar rahulde

Added Data/Code isolation via local JSON files

parent 3646d1d6
......@@ -3,7 +3,8 @@ TEMPLATE = app
QT += qml quick widgets
SOURCES += main.cpp \
imagemousearea.cpp
imagemousearea.cpp \
jsonreader.cpp
RESOURCES += qml.qrc
......@@ -14,6 +15,7 @@ QML_IMPORT_PATH = /components
include(deployment.pri)
HEADERS += \
imagemousearea.h
imagemousearea.h \
jsonreader.h
CONFIG += c++11
......@@ -6,14 +6,12 @@
class ImageMouseArea : public QQuickItem
{
Q_OBJECT
Q_PROPERTY(QString imageName READ imageName
WRITE setImageName)
Q_PROPERTY(QString imageName READ imageName WRITE setImageName)
public:
explicit ImageMouseArea(QQuickItem *parent = 0);
QString imageName() const
{
QString imageName() const {
return m_imageName;
}
......@@ -25,8 +23,7 @@ private:
QString m_imageName;
public slots:
void setImageName(QString arg)
{
void setImageName(QString arg) {
m_imageName = arg;
}
......
#include "jsonreader.h"
JSONReader::JSONReader(QObject *parent) : QObject(parent) {}
QString JSONReader::read() {
if (jsonFile.isEmpty()) {
emit error("source is empty");
return QString();
}
jsonFile = jsonFile.replace("file://", "");
QFile file(jsonFile);
QString fileContent;
if (file.open(QIODevice::ReadOnly)) {
QString line;
QTextStream t( &file );
do {
line = t.readLine();
fileContent += line;
} while (!line.isNull());
file.close();
} else {
emit error("Unable to open the file");
return QString();
}
return fileContent;
}
#ifndef JSONREADER_H
#define JSONREADER_H
#include <QObject>
#include <QFile>
#include <QTextStream>
class JSONReader : public QObject
{
Q_OBJECT
public:
explicit JSONReader(QObject *parent = 0);
Q_PROPERTY(QString source
READ source
WRITE setSource
NOTIFY sourceChanged)
Q_INVOKABLE QString read();
QString source() {
return jsonFile;
}
public slots:
void setSource(const QString& source) {
jsonFile = source;
}
signals:
void sourceChanged(const QString& source);
void error(const QString& msg);
private:
QString jsonFile;
};
#endif // JSONREADER_H
......@@ -3,12 +3,14 @@
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QtQml>
#include <jsonreader.h>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
qmlRegisterType<ImageMouseArea>("org.swecha.humanatlas", 1, 0, "ImageMouseArea");
qmlRegisterType<JSONReader>("JSONReader", 1, 0, "JSONReader");
QQmlApplicationEngine engine;
......
......@@ -10,14 +10,21 @@ RowLayout {
id: root
property string organism
property string organSystem
property string currentOrgan
property string currentOrgan: "mouth"
property string currentOrganDesc: ""
anchors.fill: parent
Organs {
Layout.fillWidth: true
Layout.maximumWidth: 400
Layout.fillHeight: true
anchors {
left: parent.left
leftMargin: 200
}
organism: root.organism
organSystem: root.organSystem
currentOrgan: root.currentOrgan
......@@ -32,24 +39,54 @@ RowLayout {
style: Components.ButtonStyle {}
width: 50
height: 50
x: 900
x: 750
y: 700
onClicked: {
stack.push(modeSelection)
}
}
}
Text {
Layout.fillWidth: true
Layout.maximumWidth: 170
anchors {
left: parent.left
top: parent.top
leftMargin: 800
topMargin: 50
}
text: root.currentOrgan
}
Image {
Layout.fillWidth: true
Layout.maximumWidth: 170
anchors {
left: parent.left
top: parent.top
leftMargin: 700
topMargin: 100
}
source: _organismsDataDirectory + "/" + root.organism + "/" + root.organSystem + "/" + root.currentOrgan + ".png"
}
Text {
id: organDesc
Layout.fillWidth: true
Layout.maximumWidth: 170
anchors {
left: parent.left
top: parent.top
leftMargin: 700
topMargin: 100
}
text: root.currentOrganDesc
}
Audio {
id: pronunciation
source: root.currentOrgan + ".wav"
}
Text {
text: "Hello World";
}
}
import QtQuick 2.0
import components 1.0 as Components
import JSONReader 1.0
Item {
id: root
......@@ -8,17 +9,13 @@ Item {
property string currentOrgan
property variant labelColorSheet
property bool displayOrganLabel: false
property bool dragOrgans: true
property variant coordinatesSheet: {
"mouth" : {"x": 120, "y": 1, "z": 1},
"oesophagus": {"x": 157, "y": 140, "z": 1},
"liver": {"x": 120, "y": 290, "z": -1},
"stomach": {"x": 183, "y": 311},
"small_intestine": {"x": 145, "y": 435, "z": 2},
"large_intestine": {"x": 120, "y": 400, "z": 1},
"anus": {"x": 173, "y": 615, "z": 1},
"pancreas": {"x": 170, "y": 310, "z": -10},
"gall_bladder": {"x": 130, "y": 350, "z": 10}
property bool dragOrgans: false
property variant coordinatesSheet
JSONReader {
id: myFile
source: _organismsDataDirectory + "/" + root.organism + "/" + root.organSystem + "/" + "data.json"
onError: console.log(msg);
}
signal clicked(var organ)
......@@ -27,9 +24,9 @@ Item {
id: mouthImage
organ: "mouth"
dragOrgans: root.dragOrgans
x: root.coordinatesSheet[mouthImage.organ].x
y: root.coordinatesSheet[mouthImage.organ].y
z: root.coordinatesSheet[mouthImage.organ].z
x: 0
y: 0
z: 0
onClicked: root.clicked(organ)
......@@ -44,12 +41,12 @@ Item {
id: oesophagusImage
organ: "oesophagus"
dragOrgans: root.dragOrgans
x: root.coordinatesSheet[oesophagusImage.organ].x
y: root.coordinatesSheet[oesophagusImage.organ].y
z: root.coordinatesSheet[oesophagusImage.organ].z
x: 0
y: 0
z: 0
onClicked: root.clicked(organ)
Text {
text: oesophagusImage.organ
color: root.organLabelColor(oesophagusImage.organ)
......@@ -61,12 +58,12 @@ Item {
id: liverImage
organ: "liver"
dragOrgans: root.dragOrgans
x: root.coordinatesSheet[liverImage.organ].x
y: root.coordinatesSheet[liverImage.organ].y
z: root.coordinatesSheet[liverImage.organ].z
x: 0
y: 0
z: 0
onClicked: root.clicked(organ)
Text {
text: liverImage.organ
color: root.organLabelColor(liverImage.organ)
......@@ -78,11 +75,11 @@ Item {
id: stomachImage
organ: "stomach"
dragOrgans: root.dragOrgans
x: root.coordinatesSheet[stomachImage.organ].x
y: root.coordinatesSheet[stomachImage.organ].y
x: 0
y: 0
onClicked: root.clicked(organ)
Text {
text: stomachImage.organ
color: root.organLabelColor(stomachImage.organ)
......@@ -94,11 +91,11 @@ Item {
id: small_intestineImage
organ: "small_intestine"
dragOrgans: root.dragOrgans
x: root.coordinatesSheet[small_intestineImage.organ].x
y: root.coordinatesSheet[small_intestineImage.organ].y
x: 0
y: 0
onClicked: root.clicked(organ)
Text {
text: small_intestineImage.organ
color: root.organLabelColor(small_intestineImage.organ)
......@@ -106,17 +103,17 @@ Item {
x: 250
}
}
Components.OrganImage {
id: large_intestineImage
organ: "large_intestine"
dragOrgans: root.dragOrgans
x: root.coordinatesSheet[large_intestineImage.organ].x
y: root.coordinatesSheet[large_intestineImage.organ].y
z: root.coordinatesSheet[large_intestineImage.organ].z
x: 0
y: 0
z: 0
onClicked: root.clicked(organ)
Text {
text: large_intestineImage.organ
color: root.organLabelColor(large_intestineImage.organ)
......@@ -129,29 +126,29 @@ Item {
id: anusImage
organ: "anus"
dragOrgans: root.dragOrgans
x: root.coordinatesSheet[anusImage.organ].x
y: root.coordinatesSheet[anusImage.organ].y
x: 0
y: 0
onClicked: root.clicked(organ)
Text {
text: anusImage.organ
color: root.organLabelColor(anusImage.organ)
visible: root.displayOrganLabel
}
}
Components.OrganImage {
id: pancreasImage
organ: "pancreas"
dragOrgans: root.dragOrgans
x: root.coordinatesSheet[pancreasImage.organ].x
y: root.coordinatesSheet[pancreasImage.organ].y
z: root.coordinatesSheet[pancreasImage.organ].z
x: 0
y: 0
z: 0
onClicked: root.clicked(organ)
Text {
text: liverImage.organ
color: root.organLabelColor(liverImage.organ)
......@@ -163,12 +160,12 @@ Item {
id: gall_bladderImage
organ: "gall_bladder"
dragOrgans: root.dragOrgans
x: root.coordinatesSheet[gall_bladderImage.organ].x
y: root.coordinatesSheet[gall_bladderImage.organ].y
z: root.coordinatesSheet[gall_bladderImage.organ].z
x: 0
y: 0
z: 0
onClicked: root.clicked(organ)
Text {
text: gall_bladderImage.organ
color: root.organLabelColor(gall_bladderImage.organ)
......@@ -185,4 +182,41 @@ Item {
}
return labelColor;
}
Component.onCompleted: {
root.coordinatesSheet = JSON.parse(myFile.read());
mouthImage.x = root.coordinatesSheet.mouth.coordinates.x;
mouthImage.y = root.coordinatesSheet.mouth.coordinates.y;
mouthImage.z = root.coordinatesSheet.mouth.coordinates.z;
oesophagusImage.x = root.coordinatesSheet.oesophagus.coordinates.x;
oesophagusImage.y = root.coordinatesSheet.oesophagus.coordinates.y;
oesophagusImage.z = root.coordinatesSheet.oesophagus.coordinates.z;
liverImage.x = root.coordinatesSheet.liver.coordinates.x;
liverImage.y = root.coordinatesSheet.liver.coordinates.y;
liverImage.z = root.coordinatesSheet.liver.coordinates.z;
stomachImage.x = root.coordinatesSheet.stomach.coordinates.x;
stomachImage.y = root.coordinatesSheet.stomach.coordinates.y;
small_intestineImage.x = root.coordinatesSheet.small_intestine.coordinates.x;
small_intestineImage.y = root.coordinatesSheet.small_intestine.coordinates.y;
large_intestineImage.x = root.coordinatesSheet.large_intestine.coordinates.x;
large_intestineImage.y = root.coordinatesSheet.large_intestine.coordinates.y;
large_intestineImage.z = root.coordinatesSheet.large_intestine.coordinates.z;
anusImage.x = root.coordinatesSheet.anus.coordinates.x;
anusImage.y = root.coordinatesSheet.anus.coordinates.y;
pancreasImage.x = root.coordinatesSheet.pancreas.coordinates.x;
pancreasImage.y = root.coordinatesSheet.pancreas.coordinates.y;
pancreasImage.z = root.coordinatesSheet.pancreas.coordinates.z;
gall_bladderImage.x = root.coordinatesSheet.gall_bladder.coordinates.x;
gall_bladderImage.y = root.coordinatesSheet.gall_bladder.coordinates.y;
gall_bladderImage.z = root.coordinatesSheet.gall_bladder.coordinates.z;
}
}
{
"mouth": {
"coordinates": {
"x": 120,
"y": 1,
"z": 10
},
"description": "In human anatomy, the mouth is the first portion of the alimentary canal that receives food and saliva. In addition to its primary role as the beginning of the digestive system, in humans the mouth also plays a significant role in communication. The mouth, normally moist, is lined with a mucous membrane, and contains the teeth."
},
"oesophagus": {
"coordinates": {
"x": 157,
"y": 140,
"z": 1
},
"description": "commonly known as the foodpipe or gullet, is an organ in vertebrates which consists of a fibromuscular tube through which food passes, aided by peristaltic contractions, from the pharynx to the stomach. In humans, the esophagus is usually 18–25 centimeters (cm) long."
},
"liver": {
"coordinates": {
"x": 120,
"y": 290,
"z": -1
},
"description": "The liver is a vital organ of the digestive system present in vertebrates and some other animals. It has a wide range of functions, including detoxification, protein synthesis, and production of biochemicals necessary for digestion. The liver is necessary for survival; there is currently no way to compensate for the absence of liver function in the long term, although new liver dialysis techniques can be used in the short term. This gland plays a major role in metabolism and has a number of functions in the body, including glycogen storage, decomposition of red blood cells, plasma protein synthesis, hormone production, and detoxification. It lies below the diaphragm in the abdominal-pelvic region of the abdomen. It produces bile, an alkaline compound which aids in digestion via the emulsification of lipids. The liver's highly specialized tissues regulate a wide variety of high-volume biochemical reactions, including the synthesis and breakdown of small and complex molecules, many of which are necessary for normal vital functions.[2] Estimates regarding the organ's total number of functions vary, but textbooks generally cite it at around 500 or so. Terminology related to the liver often starts in hepar- or hepat- from the Greek word for liver."
},
"stomach": {
"coordinates": {
"x": 183,
"y": 311
},
"description": "The stomach is a muscular, hollow, dilated part of the digestive system which functions as an important organ of the digestive tract in some animals, including vertebrates, echinoderms, insects (mid-gut), and molluscs. It is involved in the second phase of digestion, following mastication (chewing). The stomach is located between the esophagus and the small intestine. It secretes protein-digesting enzymes called proteases and strong acids to aid in food digestion, (sent to it via esophageal peristalsis) through smooth muscular contortions (called segmentation) before sending partially digested food (chyme) to the small intestines."
},
"small_intestine": {
"coordinates": {
"x": 145,
"y": 435,
"z": 2
},
"description": "The small intestine (or small bowel) is the part of the gastrointestinal tract following the stomach and followed by the large intestine, and is where much of the digestion and absorption of food takes place. The small intestine is composed of a duodenum, jejunum, and ileum. It receives bile juice and pancreatic juice from the liver."
},
"large_intestine": {
"coordinates": {
"x": 120,
"y": 400,
"z": 1
},
"description": "The large intestine is the combination of the cecum, colon, rectum, and anal canal. Its function is to absorb water from fecal matter, and then rid the body of remaining waste material."
},
"anus": {
"coordinates": {
"x": 173,
"y": 615,
"z": 1
},
"description": "The anus is the opening where the gastrointestinal tract ends and exits the body. The anus starts at the bottom of the rectum, the last portion of the colon (large intestine). The anorectal line separates the anus from the rectum."
},
"pancreas": {
"coordinates": {
"x": 170,
"y": 310,
"z": -10
},
"description": "The pancreas is a glandular organ in the digestive system and endocrine system of vertebrates. In humans, it is located in the abdominal cavity behind the stomach. It is an endocrine gland producing several important hormones, including insulin, glucagon, somatostatin, and pancreatic polypeptide which circulate in the blood. The pancreas is also a digestive organ, secreting pancreatic juice containing digestive enzymes that assist digestion and absorption of nutrients in the small intestine. These enzymes help to further break down the carbohydrates, proteins, and lipids in the chyme."
},
"gall_bladder": {
"coordinates": {
"x": 130,
"y": 350,
"z": 10
},
"description": "The gallbladder is a small pouch that sits just under the liver. The gallbladder stores bile produced by the liver. After meals, the gallbladder is empty and flat, like a deflated balloon. Before a meal, the gallbladder may be full of bile and about the size of a small pear."
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment