Skip to content
This repository was archived by the owner on Mar 4, 2023. It is now read-only.

Commit 9464e18

Browse files
committed
added file edit ui
1 parent d2bb4e8 commit 9464e18

3 files changed

Lines changed: 42 additions & 26 deletions

File tree

Demo/main.qml

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ ApplicationWindow {
99
height: 480
1010
title: qsTr("Hello World")
1111

12-
FileChooser {
13-
id: chooser
14-
15-
type: modeBox.model.get(modeBox.currentIndex).value
16-
17-
onAccepted: AndroidUtils.showToast("File choosen: " + chooser.contentUrl, true)
18-
onRejected: AndroidUtils.showToast("file choosing aborted!")
19-
}
20-
2112
footer: TabBar {
2213
id: tabBar
2314
currentIndex: swipeView.currentIndex
@@ -76,14 +67,31 @@ ApplicationWindow {
7667
}
7768

7869
Pane {
79-
ColumnLayout {
80-
anchors.centerIn: parent
70+
FileChooser {
71+
id: chooser
72+
73+
type: modeBox.model.get(modeBox.currentIndex).value
74+
75+
onAccepted: AndroidUtils.showToast("File choosen: " + chooser.contentUrl, true)
76+
onRejected: AndroidUtils.showToast("file choosing aborted!")
77+
}
78+
79+
Opener {
80+
id: opener
81+
82+
onDataLoaded: editField.text = data
83+
}
84+
85+
GridLayout {
86+
anchors.fill: parent
87+
columns: 3
8188

8289
TextField {
8390
id: contentField
8491
text: chooser.contentUrl
8592

8693
Layout.fillWidth: true
94+
Layout.columnSpan: 3
8795

8896
onEditingFinished: chooser.contentUrl = contentField.text
8997
}
@@ -92,8 +100,8 @@ ApplicationWindow {
92100
id: modeBox
93101
textRole: "key"
94102

95-
Layout.minimumWidth: 200
96103
Layout.fillWidth: true
104+
Layout.columnSpan: 3
97105

98106
model: ListModel {
99107
ListElement { key: "GetContent"; value: FileChooser.GetContent }
@@ -113,15 +121,25 @@ ApplicationWindow {
113121

114122
Button {
115123
id: editButton
124+
Layout.fillWidth: true
116125
text: "Display/Edit File"
117126

118-
Opener {
119-
id: opener
127+
onClicked: opener.openFile(chooser.contentUrl)
128+
}
120129

121-
onDataLoaded: console.log(data)
122-
}
130+
Button {
131+
id: saveButton
132+
Layout.fillWidth: true
133+
text: "Save File"
123134

124-
onClicked: opener.openFile(chooser.contentUrl)
135+
onClicked: opener.saveFile(chooser.contentUrl, editField.text)
136+
}
137+
138+
TextArea {
139+
id: editField
140+
Layout.fillHeight: true
141+
Layout.fillWidth: true
142+
Layout.columnSpan: 3
125143
}
126144
}
127145
}

Demo/opener.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define OPENER_H
33

44
#include <QObject>
5+
#include <QUrl>
56

67
class Opener : public QObject
78
{

contentdevice.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,14 @@ bool ContentDevice::open(QIODevice::OpenMode mode)
4949
"parse",
5050
"(Ljava/lang/String;)Landroid/net/Uri;",
5151
QAndroidJniObject::fromString(_url.toString(QUrl::FullyEncoded)).object());
52-
if(!uri.isValid()) {
53-
AndroidUtils::javaThrow();
52+
AndroidUtils::javaThrow();
53+
if(!uri.isValid())
5454
return false;
55-
}
5655

5756
auto contentResolver = _context.callObjectMethod("getContentResolver", "()Landroid/content/ContentResolver;");
58-
if(!contentResolver.isValid()) {
59-
AndroidUtils::javaThrow();
57+
AndroidUtils::javaThrow();
58+
if(!contentResolver.isValid())
6059
return false;
61-
}
6260

6361
switch(mode) {
6462
case QIODevice::ReadOnly:
@@ -77,10 +75,9 @@ bool ContentDevice::open(QIODevice::OpenMode mode)
7775
return false;
7876
}
7977

80-
if(!_stream.isValid()) {
81-
AndroidUtils::javaThrow();
78+
AndroidUtils::javaThrow();
79+
if(!_stream.isValid())
8280
return false;
83-
}
8481

8582
return true;
8683
} catch(QException &e) {

0 commit comments

Comments
 (0)