aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhjk <qthjk@ovi.com>2012-11-16 12:15:18 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-16 16:22:16 +0100
commite7ebed77d60a05983ec7f9e6d221324b2e7f1a22 (patch)
tree4d5f75ff50de0ef717ecdc14b7478abddb85bdca
parentfb8707631ad97311f3a1e0039206fcfccaecdb31 (diff)
Update gettingStartedQml example code to use standard Qt coding style
Change-Id: I225ea53a4e06e92367feb368dd6deea6f9acf403 Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
-rw-r--r--examples/tutorials/gettingStartedQml/filedialog/dialogPlugin.h7
-rw-r--r--examples/tutorials/gettingStartedQml/filedialog/directory.cpp50
-rw-r--r--examples/tutorials/gettingStartedQml/filedialog/directory.h76
-rw-r--r--examples/tutorials/gettingStartedQml/filedialog/file.cpp8
-rw-r--r--examples/tutorials/gettingStartedQml/filedialog/file.h25
5 files changed, 80 insertions, 86 deletions
diff --git a/examples/tutorials/gettingStartedQml/filedialog/dialogPlugin.h b/examples/tutorials/gettingStartedQml/filedialog/dialogPlugin.h
index f5fcae0958..05e076839a 100644
--- a/examples/tutorials/gettingStartedQml/filedialog/dialogPlugin.h
+++ b/examples/tutorials/gettingStartedQml/filedialog/dialogPlugin.h
@@ -48,10 +48,9 @@ class DialogPlugin : public QQmlExtensionPlugin
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
- 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/tutorials/gettingStartedQml/filedialog/directory.cpp b/examples/tutorials/gettingStartedQml/filedialog/directory.cpp
index a07ec6308f..38a47f0431 100644
--- a/examples/tutorials/gettingStartedQml/filedialog/directory.cpp
+++ b/examples/tutorials/gettingStartedQml/filedialog/directory.cpp
@@ -48,11 +48,11 @@ Initialize the saves directory and creates the file list
*/
Directory::Directory(QObject *parent) : QObject(parent)
{
- m_dir.cd( QDir::currentPath() );
+ 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 save directory
m_saveDir = "saves";
- if ( m_dir.cd(m_saveDir) == 0 ) {
+ if (m_dir.cd(m_saveDir) == 0) {
m_dir.mkdir(m_saveDir);
m_dir.cd(m_saveDir);
}
@@ -72,7 +72,7 @@ int Directory::filesCount() const
/*
Function called to append data onto list property
*/
-void appendFiles(QQmlListProperty<File> * property, File * file)
+void appendFiles(QQmlListProperty<File> *property, File *file)
{
Q_UNUSED(property);
Q_UNUSED(file);
@@ -82,7 +82,7 @@ void appendFiles(QQmlListProperty<File> * property, File * file)
/*
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);
}
@@ -90,7 +90,7 @@ File* fileAt(QQmlListProperty<File> * property, int index)
/*
Returns the number of files in the list
*/
-int filesSize(QQmlListProperty<File> * property)
+int filesSize(QQmlListProperty<File> *property)
{
return static_cast< QList<File *> *>(property->data)->size();
}
@@ -109,7 +109,7 @@ Returns the list of files as a QQmlListProperty.
QQmlListProperty<File> Directory::files()
{
refresh();
- return QQmlListProperty<File>( this, &m_fileList, &appendFiles, &filesSize, &fileAt, &clearFilesPtr );
+ return QQmlListProperty<File>(this, &m_fileList, &appendFiles, &filesSize, &fileAt, &clearFilesPtr);
}
/*
@@ -133,7 +133,7 @@ Set the file name of the current file
*/
void Directory::setFilename(const QString &str)
{
- if( str != currentFile.name() ) {
+ if (str != currentFile.name()) {
currentFile.setName(str);
emit filenameChanged();
}
@@ -144,7 +144,7 @@ Set the content of the file as a string
*/
void Directory::setFileContent(const QString &str)
{
- if(str != m_fileContent){
+ if (str != m_fileContent) {
m_fileContent = str;
emit fileContentChanged();
}
@@ -156,16 +156,16 @@ Saving makes sure that the file has a .txt extension.
*/
void Directory::saveFile()
{
- if(currentFile.name().size() == 0){
+ if (currentFile.name().isEmpty()) {
qWarning()<< "Empty filename. no save";
return;
}
QString extendedName = currentFile.name();
- if(!currentFile.name().endsWith(".txt")){
+ if (!currentFile.name().endsWith(".txt")) {
extendedName.append(".txt");
}
- QFile file( m_dir.filePath(extendedName) );
- if ( file.open(QFile::WriteOnly | QFile::Truncate) ) {
+ QFile file(m_dir.filePath(extendedName));
+ if (file.open(QFile::WriteOnly | QFile::Truncate)) {
QTextStream outStream(&file);
outStream << m_fileContent;
}
@@ -182,19 +182,14 @@ void Directory::loadFile()
{
m_fileContent.clear();
QString extendedName = currentFile.name();
- if( !currentFile.name().endsWith(".txt") ) {
+ if (!currentFile.name().endsWith(".txt")) {
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);
-
- QString line;
- do {
- line = inStream.read(75);
- m_fileContent.append(line);
- } while ( !line.isNull() ) ;
+ m_fileContent = inStream.readAll();
}
file.close();
}
@@ -208,15 +203,14 @@ void Directory::refresh()
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") ) {
+ if (m_dirFiles.at(i).endsWith(".txt")) {
QString name = m_dirFiles.at(i);
- file->setName( name.remove(".txt",Qt::CaseSensitive) );
- }
- else {
+ file->setName(name.remove(".txt",Qt::CaseSensitive));
+ } else {
file->setName(m_dirFiles.at(i));
}
m_fileList.append(file);
diff --git a/examples/tutorials/gettingStartedQml/filedialog/directory.h b/examples/tutorials/gettingStartedQml/filedialog/directory.h
index 7bb41efa98..90c427c1c5 100644
--- a/examples/tutorials/gettingStartedQml/filedialog/directory.h
+++ b/examples/tutorials/gettingStartedQml/filedialog/directory.h
@@ -44,64 +44,64 @@
#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
- Q_PROPERTY(QQmlListProperty<File> files READ files CONSTANT )
+ // 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);
+public:
+ Directory(QObject *parent = 0);
- //properties' read functions
- int filesCount() const;
- QString filename() const;
- QString fileContent() const;
- QQmlListProperty<File> files();
+ // properties' read functions
+ int filesCount() const;
+ QString filename() const;
+ QString fileContent() const;
+ QQmlListProperty<File> files();
- //properties' write functions
- void setFilename(const QString &str);
- void setFileContent(const QString &str);
+ // properties' write functions
+ void setFilename(const QString &str);
+ void setFileContent(const QString &str);
- //accessible from QML
- Q_INVOKABLE void saveFile();
- Q_INVOKABLE void loadFile();
+ // accessible from QML
+ Q_INVOKABLE void saveFile();
+ Q_INVOKABLE void loadFile();
- signals:
- void directoryChanged();
- void filenameChanged();
- void fileContentChanged();
+signals:
+ void directoryChanged();
+ void filenameChanged();
+ void fileContentChanged();
- private:
- QDir m_dir;
- QStringList m_dirFiles;
- File currentFile;
- QString m_saveDir;
- QStringList m_filterList;
+private:
+ QDir m_dir;
+ QStringList m_dirFiles;
+ File currentFile;
+ QString m_saveDir;
+ QStringList m_filterList;
- //contains the file data in QString format
- QString m_fileContent;
+ //contains the file data in QString format
+ QString m_fileContent;
- //Registered to QML in a plugin. Accessible from QML as a property of Directory
- QList<File *> m_fileList;
+ //Registered to QML in a plugin. Accessible from QML as a property of Directory
+ QList<File *> m_fileList;
- //refresh content of the directory
- void refresh();
+ //refresh content of the directory
+ void refresh();
};
#endif
diff --git a/examples/tutorials/gettingStartedQml/filedialog/file.cpp b/examples/tutorials/gettingStartedQml/filedialog/file.cpp
index dc91212e0c..b53c569d56 100644
--- a/examples/tutorials/gettingStartedQml/filedialog/file.cpp
+++ b/examples/tutorials/gettingStartedQml/filedialog/file.cpp
@@ -45,12 +45,14 @@ File::File(QObject *parent) : QObject(parent)
{
}
-QString File::name() const{
+QString File::name() const
+{
return m_name;
}
-void File::setName(const QString &str){
- if(str != m_name){
+void File::setName(const QString &str)
+{
+ if (str != m_name) {
m_name = str;
emit nameChanged();
}
diff --git a/examples/tutorials/gettingStartedQml/filedialog/file.h b/examples/tutorials/gettingStartedQml/filedialog/file.h
index cd12e6d39b..7a0da05b70 100644
--- a/examples/tutorials/gettingStartedQml/filedialog/file.h
+++ b/examples/tutorials/gettingStartedQml/filedialog/file.h
@@ -41,27 +41,26 @@
#ifndef FILE_H
#define FILE_H
-
-#include <QString>
#include <QObject>
+#include <QString>
-class File : public QObject{
-
+class File : public QObject
+{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
- public:
- File(QObject *parent = 0);
+public:
+ File(QObject *parent = 0);
- QString name() const;
- void setName(const QString &str);
+ QString name() const;
+ void setName(const QString &str);
- signals:
- void nameChanged();
+signals:
+ void nameChanged();
- private:
- QString m_name;
+private:
+ QString m_name;
};
-#endif \ No newline at end of file
+#endif