aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick/tutorials/gettingStartedQml/filedialog
diff options
context:
space:
mode:
Diffstat (limited to 'examples/quick/tutorials/gettingStartedQml/filedialog')
-rw-r--r--examples/quick/tutorials/gettingStartedQml/filedialog/dialogPlugin.cpp7
-rw-r--r--examples/quick/tutorials/gettingStartedQml/filedialog/dialogPlugin.h8
-rw-r--r--examples/quick/tutorials/gettingStartedQml/filedialog/directory.cpp77
-rw-r--r--examples/quick/tutorials/gettingStartedQml/filedialog/directory.h27
-rw-r--r--examples/quick/tutorials/gettingStartedQml/filedialog/file.cpp2
-rw-r--r--examples/quick/tutorials/gettingStartedQml/filedialog/filedialog.pro27
-rw-r--r--examples/quick/tutorials/gettingStartedQml/filedialog/qmldir3
7 files changed, 85 insertions, 66 deletions
diff --git a/examples/quick/tutorials/gettingStartedQml/filedialog/dialogPlugin.cpp b/examples/quick/tutorials/gettingStartedQml/filedialog/dialogPlugin.cpp
index 7076f2c19c..b1ba601df3 100644
--- a/examples/quick/tutorials/gettingStartedQml/filedialog/dialogPlugin.cpp
+++ b/examples/quick/tutorials/gettingStartedQml/filedialog/dialogPlugin.cpp
@@ -41,11 +41,12 @@
#include "dialogPlugin.h"
#include "directory.h"
#include "file.h"
-#include <QtQml/qqml.h>
+#include <QtQml>
void DialogPlugin::registerTypes(const char *uri)
{
- //register the class Directory into QML as a "Directory" element version 1.0
+ // Register the class Directory into QML as a "Directory" type version 1.0
+ // @uri FileDialog
qmlRegisterType<Directory>(uri, 1, 0, "Directory");
- qmlRegisterType<File>(uri,1,0,"File");
+ qmlRegisterType<File>(uri, 1, 0, "File");
}
diff --git a/examples/quick/tutorials/gettingStartedQml/filedialog/dialogPlugin.h b/examples/quick/tutorials/gettingStartedQml/filedialog/dialogPlugin.h
index 5c4e5c971d..f23391f1df 100644
--- a/examples/quick/tutorials/gettingStartedQml/filedialog/dialogPlugin.h
+++ b/examples/quick/tutorials/gettingStartedQml/filedialog/dialogPlugin.h
@@ -46,11 +46,11 @@
class DialogPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
- Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
+ Q_PLUGIN_METADATA(IID "org.qt-project.QmlExtensionPlugin.FileDialog")
+ public:
+ //registerTypes is inherited from QQmlExtensionPlugin
+ void registerTypes(const char *uri);
-public:
- // registerTypes is inherited from QQmlExtensionPlugin
- void registerTypes(const char *uri);
};
#endif
diff --git a/examples/quick/tutorials/gettingStartedQml/filedialog/directory.cpp b/examples/quick/tutorials/gettingStartedQml/filedialog/directory.cpp
index 0d4b551787..9535b97dd9 100644
--- a/examples/quick/tutorials/gettingStartedQml/filedialog/directory.cpp
+++ b/examples/quick/tutorials/gettingStartedQml/filedialog/directory.cpp
@@ -42,27 +42,28 @@
#include <QDebug>
/*
-Directory constructor
+ Directory constructor
-Initialize the saves directory and creates the file list
+ Initialize the saves directory and creates the file list
*/
Directory::Directory(QObject *parent) : QObject(parent)
{
m_dir.cd(QDir::currentPath());
- // go to the saved directory. if not found, create save directory
+ // Go to the saved directory. if not found, create it
m_saveDir = "saves";
if (m_dir.cd(m_saveDir) == 0) {
m_dir.mkdir(m_saveDir);
m_dir.cd(m_saveDir);
}
- m_filterList << "*.txt";
+ m_filterList << "*.txt";
+
refresh();
}
/*
-Directory::filesNumber
-Return the number of Files
+ Directory::filesCount
+ Returns the number of files
*/
int Directory::filesCount() const
{
@@ -70,25 +71,25 @@ int Directory::filesCount() const
}
/*
-Function called to append data onto list property
+ Function to append data into list property
*/
void appendFiles(QQmlListProperty<File> *property, File *file)
{
- Q_UNUSED(property);
- Q_UNUSED(file);
- //Do nothing. can't add to a directory using this method
+ Q_UNUSED(property)
+ Q_UNUSED(file)
+ // Do nothing. can't add to a directory using this method
}
/*
-Function called to retrieve file in the list using an index
+ Function called to retrieve file in the list using an index
*/
-File *fileAt(QQmlListProperty<File> *property, int index)
+File* fileAt(QQmlListProperty<File> *property, int index)
{
return static_cast< QList<File *> *>(property->data)->at(index);
}
/*
-Returns the number of files in the list
+ Returns the number of files in the list
*/
int filesSize(QQmlListProperty<File> *property)
{
@@ -96,7 +97,7 @@ int filesSize(QQmlListProperty<File> *property)
}
/*
-Function called to empty the list property contents
+ Function called to empty the list property contents
*/
void clearFilesPtr(QQmlListProperty<File> *property)
{
@@ -104,7 +105,7 @@ void clearFilesPtr(QQmlListProperty<File> *property)
}
/*
-Returns the list of files as a QQmlListProperty.
+ Returns the list of files as a QQmlListProperty.
*/
QQmlListProperty<File> Directory::files()
{
@@ -113,7 +114,7 @@ QQmlListProperty<File> Directory::files()
}
/*
-Return the name of the currently selected file
+ Return the name of the currently selected file.
*/
QString Directory::filename() const
{
@@ -121,7 +122,7 @@ QString Directory::filename() const
}
/*
-Return the file's content as a string.
+ Return the file's content as a string.
*/
QString Directory::fileContent() const
{
@@ -129,7 +130,7 @@ QString Directory::fileContent() const
}
/*
-Set the file name of the current file
+ Set the file name of the current file.
*/
void Directory::setFilename(const QString &str)
{
@@ -140,7 +141,7 @@ void Directory::setFilename(const QString &str)
}
/*
-Set the content of the file as a string
+ Set the content of the file as a string.
*/
void Directory::setFileContent(const QString &str)
{
@@ -151,32 +152,35 @@ void Directory::setFileContent(const QString &str)
}
/*
-Called from QML to save the file using the filename and file content.
-Saving makes sure that the file has a .txt extension.
+ Called from QML to save the file using the filename and content.
+ Makes sure that the file has a .txt extension.
*/
void Directory::saveFile()
{
- if (currentFile.name().isEmpty()) {
- qWarning()<< "Empty filename. no save";
+ if (currentFile.name().size() == 0) {
+ qWarning() << "Cannot save file, empty filename.";
return;
}
+
QString extendedName = currentFile.name();
if (!currentFile.name().endsWith(".txt")) {
extendedName.append(".txt");
}
+
QFile file(m_dir.filePath(extendedName));
if (file.open(QFile::WriteOnly | QFile::Truncate)) {
QTextStream outStream(&file);
outStream << m_fileContent;
}
+
file.close();
refresh();
emit directoryChanged();
}
/*
-Load the contents of a file.
-Only loads files with a .txt extension
+ Load the contents of a file.
+ Only loads files with a .txt extension
*/
void Directory::loadFile()
{
@@ -186,30 +190,35 @@ void Directory::loadFile()
extendedName.append(".txt");
}
- QFile file(m_dir.filePath(extendedName));
- if (file.open(QFile::ReadOnly)) {
+ QFile file( m_dir.filePath(extendedName));
+ if (file.open(QFile::ReadOnly )) {
QTextStream inStream(&file);
- m_fileContent = inStream.readAll();
+ QString line;
+
+ do {
+ line = inStream.read(75);
+ m_fileContent.append(line);
+ } while (!line .isNull());
}
file.close();
}
/*
-Reloads the content of the files list. This is to ensure that the newly
-created files are added onto the list.
+ Reloads the content of the files list. This is to ensure
+ that the newly created files are added onto the list.
*/
void Directory::refresh()
{
- m_dirFiles = m_dir.entryList(m_filterList,QDir::Files,QDir::Name);
+ m_dirFiles = m_dir.entryList(m_filterList, QDir::Files, QDir::Name);
m_fileList.clear();
- File *file;
- for (int i = 0; i < m_dirFiles.size(); ++i) {
+ File * file;
+ for (int i = 0; i < m_dirFiles.size(); i ++) {
file = new File();
if (m_dirFiles.at(i).endsWith(".txt")) {
QString name = m_dirFiles.at(i);
- file->setName(name.remove(".txt",Qt::CaseSensitive));
+ file->setName(name.remove(".txt", Qt::CaseSensitive));
} else {
file->setName(m_dirFiles.at(i));
}
diff --git a/examples/quick/tutorials/gettingStartedQml/filedialog/directory.h b/examples/quick/tutorials/gettingStartedQml/filedialog/directory.h
index 2cdfab0e43..de170f28b0 100644
--- a/examples/quick/tutorials/gettingStartedQml/filedialog/directory.h
+++ b/examples/quick/tutorials/gettingStartedQml/filedialog/directory.h
@@ -44,41 +44,40 @@
#include "file.h"
#include <QDir>
-#include <QObject>
-#include <QQmlListProperty>
#include <QStringList>
#include <QTextStream>
+#include <QQmlListProperty>
+#include <QObject>
-class Directory : public QObject
-{
+class Directory : public QObject {
Q_OBJECT
- // number of files in the directory
+ // Number of files in the directory
Q_PROPERTY(int filesCount READ filesCount)
- // list property containing file names as QString
+ // List property containing file names as QString
Q_PROPERTY(QQmlListProperty<File> files READ files CONSTANT)
- // file name of the text file to read/write
+ // File name of the text file to read/write
Q_PROPERTY(QString filename READ filename WRITE setFilename NOTIFY filenameChanged)
- // text content of the file
+ // Text content of the file
Q_PROPERTY(QString fileContent READ fileContent WRITE setFileContent NOTIFY fileContentChanged)
public:
Directory(QObject *parent = 0);
- // properties' read functions
+ // Properties' read functions
int filesCount() const;
QString filename() const;
QString fileContent() const;
QQmlListProperty<File> files();
- // properties' write functions
+ // Properties' write functions
void setFilename(const QString &str);
void setFileContent(const QString &str);
- // accessible from QML
+ // Accessible from QML
Q_INVOKABLE void saveFile();
Q_INVOKABLE void loadFile();
@@ -94,13 +93,13 @@ private:
QString m_saveDir;
QStringList m_filterList;
- //contains the file data in QString format
+ // Contains the file data in QString format
QString m_fileContent;
- //Registered to QML in a plugin. Accessible from QML as a property of Directory
+ // Registered to QML in a plugin. Accessible from QML as a property of Directory
QList<File *> m_fileList;
- //refresh content of the directory
+ // Refresh content of the directory
void refresh();
};
diff --git a/examples/quick/tutorials/gettingStartedQml/filedialog/file.cpp b/examples/quick/tutorials/gettingStartedQml/filedialog/file.cpp
index 983c24975b..e2cdab003a 100644
--- a/examples/quick/tutorials/gettingStartedQml/filedialog/file.cpp
+++ b/examples/quick/tutorials/gettingStartedQml/filedialog/file.cpp
@@ -38,7 +38,6 @@
**
****************************************************************************/
-
#include "file.h"
File::File(QObject *parent) : QObject(parent)
@@ -57,4 +56,3 @@ void File::setName(const QString &str)
emit nameChanged();
}
}
-
diff --git a/examples/quick/tutorials/gettingStartedQml/filedialog/filedialog.pro b/examples/quick/tutorials/gettingStartedQml/filedialog/filedialog.pro
index da06975e3b..0886f37b1f 100644
--- a/examples/quick/tutorials/gettingStartedQml/filedialog/filedialog.pro
+++ b/examples/quick/tutorials/gettingStartedQml/filedialog/filedialog.pro
@@ -2,21 +2,32 @@ TEMPLATE = lib
CONFIG += plugin
QT += qml
-DESTDIR += ../plugins
+DESTDIR += ../imports/FileDialog
OBJECTS_DIR = tmp
MOC_DIR = tmp
-TARGET = FileDialog
+TARGET = filedialogplugin
-HEADERS += directory.h \
+HEADERS += \
+ directory.h \
file.h \
dialogPlugin.h
-SOURCES += directory.cpp \
+SOURCES += \
+ directory.cpp \
file.cpp \
dialogPlugin.cpp
-target.path = $$[QT_INSTALL_EXAMPLES]/quick/tutorials/gettingStartedQml/filedialog
-qml.files = qmldir
-qml.path = $$[QT_INSTALL_EXAMPLES]/quick/tutorials/gettingStartedQml/filedialog
-INSTALLS += target qml
+OTHER_FILES += qmldir
+
+copyfile = $$PWD/qmldir
+copydest = $$DESTDIR
+
+# On Windows, use backslashes as directory separators
+win32: {
+ copyfile ~= s,/,\\,g
+ copydest ~= s,/,\\,g
+}
+
+# Copy the qmldir file to the same folder as the plugin binary
+QMAKE_POST_LINK += $$QMAKE_COPY $$quote($$copyfile) $$quote($$copydest) $$escape_expand(\\n\\t)
diff --git a/examples/quick/tutorials/gettingStartedQml/filedialog/qmldir b/examples/quick/tutorials/gettingStartedQml/filedialog/qmldir
index 4a8d13d026..fbcd5f7fd3 100644
--- a/examples/quick/tutorials/gettingStartedQml/filedialog/qmldir
+++ b/examples/quick/tutorials/gettingStartedQml/filedialog/qmldir
@@ -1 +1,2 @@
-plugin FileDialog ../plugins
+module FileDialog
+plugin filedialogplugin