diff options
author | Tobias Hunger <tobias.hunger@theqtcompany.com> | 2015-10-19 14:19:41 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@theqtcompany.com> | 2015-10-21 13:57:24 +0000 |
commit | 9035e7780081c0f57e2044268b95d6a1d47cbb6e (patch) | |
tree | bdc27a8cbffbf1f4b4b444466a1ab1d4161366e0 | |
parent | 114261dc84d01106f73910bd33149b9dc17e56ec (diff) | |
download | qt-creator-9035e7780081c0f57e2044268b95d6a1d47cbb6e.tar.gz |
Wizard: Add a wizard for item models
Task-number: QTCREATORBUG-7
Change-Id: Ibc06eda1b6596b08dd2e3be4e426c8b89be31064
Reviewed-by: Alessandro Portale <alessandro.portale@theqtcompany.com>
7 files changed, 692 insertions, 0 deletions
diff --git a/share/qtcreator/templates/wizards/classes/itemmodel/itemmodel.cpp b/share/qtcreator/templates/wizards/classes/itemmodel/itemmodel.cpp new file mode 100644 index 0000000000..a8cdf3164a --- /dev/null +++ b/share/qtcreator/templates/wizards/classes/itemmodel/itemmodel.cpp @@ -0,0 +1,133 @@ +%{Cpp:LicenseTemplate}\ +#include "%{HdrFileName}" +%{JS: Cpp.openNamespaces('%{Class}')}\ + +%{CN}::%{CN}(QObject *parent) + : %{Base}(parent) +{ +} +@if %{CustomHeader} + +QVariant %{CN}::headerData(int section, Qt::Orientation orientation, int role) const +{ + // FIXME: Implement me! +} +@if %{Editable} + +bool %{CN}::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) +{ + if (value != headerData(section, orientation, role)) { + // FIXME: Implement me! + emit headerDataChanged(orientation, section, section); + return true; + } + return false; +} +@endif +@endif + +QModelIndex %{CN}::index(int row, int column, const QModelIndex &parent) const +{ + // FIXME: Implement me! +} + +QModelIndex %{CN}::parent(const QModelIndex &index) const +{ + // FIXME: Implement me! +} + +int %{CN}::rowCount(const QModelIndex &parent) const +{ + if (!parent.isValid()) + return 0; + + // FIXME: Implement me! +} + +int %{CN}::columnCount(const QModelIndex &parent) const +{ + if (!parent.isValid()) + return 0; + + // FIXME: Implement me! +} +@if %{DynamicFetch} + +bool %{CN}::hasChildren(const QModelIndex &parent) const +{ + // FIXME: Implement me! +} + +bool %{CN}::canFetchMore(const QModelIndex &parent) const +{ + // FIXME: Implement me! + return false; +} + +void %{CN}::fetchMore(const QModelIndex &parent) +{ + // FIXME: Implement me! +} +@endif + +QVariant %{CN}::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + // FIXME: Implement me! + return QVariant(); +} +@if %{Editable} + +bool %{CN}::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if (data(index, role) != value) { + // FIXME: Implement me! + emit dataChanged(index, index, QVector<int>() << role); + return true; + } + return false; +} + +Qt::ItemFlags %{CN}::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return Qt::NoItemFlags; + + return Qt::ItemIsEditable; // FIXME: Implement me! +} +@endif +@if %{AddData} + +bool %{CN}::insertRows(int row, int count, const QModelIndex &parent) +{ + beginInsertRows(parent, row, row + count - 1); + // FIXME: Implement me! + endInsertRows(); +} + +bool %{CN}::insertColumns(int column, int count, const QModelIndex &parent) +{ + beginInsertColumns(parent, column, column + count - 1); + // FIXME: Implement me! + endInsertColumns(); +} +@endif +@if %{RemoveData} + +bool %{CN}::removeRows(int row, int count, const QModelIndex &parent) +{ + beginRemoveRows(parent, row, row + count - 1); + // FIXME: Implement me! + endRemoveRows(); +} + +bool %{CN}::removeColumns(int column, int count, const QModelIndex &parent) +{ + beginRemoveColumns(parent, column, column + count - 1); + // FIXME: Implement me! + endRemoveColumns(); +} +@endif +%{JS: Cpp.closeNamespaces('%{Class}')}\ diff --git a/share/qtcreator/templates/wizards/classes/itemmodel/itemmodel.h b/share/qtcreator/templates/wizards/classes/itemmodel/itemmodel.h new file mode 100644 index 0000000000..63ee4bddc6 --- /dev/null +++ b/share/qtcreator/templates/wizards/classes/itemmodel/itemmodel.h @@ -0,0 +1,65 @@ +%{Cpp:LicenseTemplate}\ +#ifndef %{GUARD} +#define %{GUARD} + +%{JS: QtSupport.qtIncludes([ 'QtCore/%{Base}' ], [ 'QtCore/%{Base}' ])}\ +%{JS: Cpp.openNamespaces('%{Class}')}\ + +class %{CN} : public %{Base} +{ + Q_OBJECT + +public: + explicit %{CN}(QObject *parent = 0); + +@if %{CustomHeader} + // Header: + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + +@if %{Editable} + bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override; + +@endif +@endif + // Basic functionality: + QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const override; + QModelIndex parent(const QModelIndex &index) const override; + + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent = QModelIndex()) const override; + +@if %{DynamicFetch} + // Fetch data dynamically: + bool hasChildren(const QModelIndex &parent = QModelIndex()) const override; + + bool canFetchMore(const QModelIndex &parent) const override; + void fetchMore(const QModelIndex &parent) override; + +@endif + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + +@if %{Editable} + // Editable: + bool setData(const QModelIndex &index, const QVariant &value, + int role = Qt::EditRole) override; + + Qt::ItemFlags flags(const QModelIndex& index) const override; + +@endif +@if %{AddData} + // Add data: + bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; + bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override; + +@endif +@if %{RemoveData} + // Remove data: + bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; + bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override; + +@endif +private: +}; +%{JS: Cpp.closeNamespaces('%{Class}')} +#endif // %{GUARD}\ diff --git a/share/qtcreator/templates/wizards/classes/itemmodel/listmodel.cpp b/share/qtcreator/templates/wizards/classes/itemmodel/listmodel.cpp new file mode 100644 index 0000000000..5d7fa72875 --- /dev/null +++ b/share/qtcreator/templates/wizards/classes/itemmodel/listmodel.cpp @@ -0,0 +1,83 @@ +%{Cpp:LicenseTemplate}\ +#include "%{HdrFileName}" +%{JS: Cpp.openNamespaces('%{Class}')}\ + +%{CN}::%{CN}(QObject *parent) + : %{Base}(parent) +{ +} +@if %{CustomHeader} + +QVariant %{CN}::headerData(int section, Qt::Orientation orientation, int role) const +{ + // FIXME: Implement me! +} +@if %{Editable} + +bool %{CN}::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) +{ + if (value != headerData(section, orientation, role)) { + // FIXME: Implement me! + emit headerDataChanged(orientation, section, section); + return true; + } + return false; +} +@endif +@endif + +int %{CN}::rowCount(const QModelIndex &parent) const +{ + if (!parent.isValid()) + return 0; + + // FIXME: Implement me! +} + +QVariant %{CN}::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + // FIXME: Implement me! + return QVariant(); +} +@if %{Editable} + +bool %{CN}::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if (data(index, role) != value) { + // FIXME: Implement me! + emit dataChanged(index, index, QVector<int>() << role); + return true; + } + return false; +} + +Qt::ItemFlags %{CN}::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return Qt::NoItemFlags; + + return Qt::ItemIsEditable; // FIXME: Implement me! +} +@endif +@if %{AddData} + +bool %{CN}::insertRows(int row, int count, const QModelIndex &parent) +{ + beginInsertRows(parent, row, row + count - 1); + // FIXME: Implement me! + endInsertRows(); +} +@endif +@if %{RemoveData} + +bool %{CN}::removeRows(int row, int count, const QModelIndex &parent) +{ + beginRemoveRows(parent, row, row + count - 1); + // FIXME: Implement me! + endRemoveRows(); +} +@endif +%{JS: Cpp.closeNamespaces('%{Class}')}\ diff --git a/share/qtcreator/templates/wizards/classes/itemmodel/listmodel.h b/share/qtcreator/templates/wizards/classes/itemmodel/listmodel.h new file mode 100644 index 0000000000..24d9815f6f --- /dev/null +++ b/share/qtcreator/templates/wizards/classes/itemmodel/listmodel.h @@ -0,0 +1,50 @@ +%{Cpp:LicenseTemplate}\ +#ifndef %{GUARD} +#define %{GUARD} + +%{JS: QtSupport.qtIncludes([ 'QtCore/%{Base}' ], [ 'QtCore/%{Base}' ])}\ +%{JS: Cpp.openNamespaces('%{Class}')}\ + +class %{CN} : public %{Base} +{ + Q_OBJECT + +public: + explicit %{CN}(QObject *parent = 0); + +@if %{CustomHeader} + // Header: + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + +@if %{Editable} + bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override; + +@endif +@endif + // Basic functionality: + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + +@if %{Editable} + // Editable: + bool setData(const QModelIndex &index, const QVariant &value, + int role = Qt::EditRole) override; + + Qt::ItemFlags flags(const QModelIndex& index) const override; + +@endif +@if %{AddData} + // Add data: + bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; + +@endif +@if %{RemoveData} + // Remove data: + bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; + +@endif +private: +}; +%{JS: Cpp.closeNamespaces('%{Class}')} +#endif // %{GUARD}\ diff --git a/share/qtcreator/templates/wizards/classes/itemmodel/tablemodel.cpp b/share/qtcreator/templates/wizards/classes/itemmodel/tablemodel.cpp new file mode 100644 index 0000000000..fb452feace --- /dev/null +++ b/share/qtcreator/templates/wizards/classes/itemmodel/tablemodel.cpp @@ -0,0 +1,106 @@ +%{Cpp:LicenseTemplate}\ +#include "%{HdrFileName}" +%{JS: Cpp.openNamespaces('%{Class}')}\ + +%{CN}::%{CN}(QObject *parent) + : %{Base}(parent) +{ +} +@if %{CustomHeader} + +QVariant %{CN}::headerData(int section, Qt::Orientation orientation, int role) const +{ + // FIXME: Implement me! +} +@if %{Editable} + +bool %{CN}::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) +{ + if (value != headerData(section, orientation, role)) { + // FIXME: Implement me! + emit headerDataChanged(orientation, section, section); + return true; + } + return false; +} + +@endif +@endif + +int %{CN}::rowCount(const QModelIndex &parent) const +{ + if (!parent.isValid()) + return 0; + + // FIXME: Implement me! +} + +int %{CN}::columnCount(const QModelIndex &parent) const +{ + if (!parent.isValid()) + return 0; + + // FIXME: Implement me! +} + +QVariant %{CN}::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + // FIXME: Implement me! + return QVariant(); +} +@if %{Editable} + +bool %{CN}::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if (data(index, role) != value) { + // FIXME: Implement me! + emit dataChanged(index, index, QVector<int>() << role); + return true; + } + return false; +} + +Qt::ItemFlags %{CN}::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return Qt::NoItemFlags; + + return Qt::ItemIsEditable; // FIXME: Implement me! +} +@endif +@if %{AddData} + +bool %{CN}::insertRows(int row, int count, const QModelIndex &parent) +{ + beginInsertRows(parent, row, row + count - 1); + // FIXME: Implement me! + endInsertRows(); +} + +bool %{CN}::insertColumns(int column, int count, const QModelIndex &parent) +{ + beginInsertColumns(parent, column, column + count - 1); + // FIXME: Implement me! + endInsertColumns(); +} +@endif +@if %{RemoveData} + +bool %{CN}::removeRows(int row, int count, const QModelIndex &parent) +{ + beginRemoveRows(parent, row, row + count - 1); + // FIXME: Implement me! + endRemoveRows(); +} + +bool %{CN}::removeColumns(int column, int count, const QModelIndex &parent) +{ + beginRemoveColumns(parent, column, column + count - 1); + // FIXME: Implement me! + endRemoveColumns(); +} +@endif +%{JS: Cpp.closeNamespaces('%{Class}')}\ diff --git a/share/qtcreator/templates/wizards/classes/itemmodel/tablemodel.h b/share/qtcreator/templates/wizards/classes/itemmodel/tablemodel.h new file mode 100644 index 0000000000..dfc42d848b --- /dev/null +++ b/share/qtcreator/templates/wizards/classes/itemmodel/tablemodel.h @@ -0,0 +1,53 @@ +%{Cpp:LicenseTemplate}\ +#ifndef %{GUARD} +#define %{GUARD} + +%{JS: QtSupport.qtIncludes([ 'QtCore/%{Base}' ], [ 'QtCore/%{Base}' ])}\ +%{JS: Cpp.openNamespaces('%{Class}')}\ + +class %{CN} : public %{Base} +{ + Q_OBJECT + +public: + explicit %{CN}(QObject *parent = 0); + +@if %{CustomHeader} + // Header: + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + +@if %{Editable} + bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override; + +@endif +@endif + // Basic functionality: + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent = QModelIndex()) const override; + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + +@if %{Editable} + // Editable: + bool setData(const QModelIndex &index, const QVariant &value, + int role = Qt::EditRole) override; + + Qt::ItemFlags flags(const QModelIndex& index) const override; + +@endif +@if %{AddData} + // Add data: + bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; + bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override; + +@endif +@if %{RemoveData} + // Remove data: + bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; + bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override; + +@endif +private: +}; +%{JS: Cpp.closeNamespaces('%{Class}')} +#endif // %{GUARD}\ diff --git a/share/qtcreator/templates/wizards/classes/itemmodel/wizard.json b/share/qtcreator/templates/wizards/classes/itemmodel/wizard.json new file mode 100644 index 0000000000..40e458b689 --- /dev/null +++ b/share/qtcreator/templates/wizards/classes/itemmodel/wizard.json @@ -0,0 +1,202 @@ +{ + "version": 1, + "kind": "file", + "id": "A.ItemView", + "category": "R.Qt", + "trDescription": "Creates a Qt item model.", + "trDisplayName": "Qt Item Model", + "trDisplayCategory": "Qt", + "icon": "../../global/genericfilewizard.png", + "enabled": "%{JS: [ %{Plugins} ].indexOf('CppEditor') >= 0}", + + "options": + [ + { "key": "TargetPath", "value": "%{Path}" }, + { "key": "HdrPath", "value": "%{Path}/%{HdrFileName}" }, + { "key": "SrcPath", "value": "%{Path}/%{SrcFileName}" }, + { "key": "CN", "value": "%{JS: Cpp.className('%{Class}')}" }, + { "key": "GUARD", "value": "%{JS: Cpp.classToHeaderGuard('%{Class}', '%{JS: Util.preferredSuffix('text/x-c++hdr')}')}" } + ], + + "pages": + [ + { + "trDisplayName": "Define Item Model Class", + "trShortTitle": "Details", + "typeId": "Fields", + "data" : + [ + { + "name": "Class", + "trDisplayName": "Class name:", + "mandatory": true, + "type": "LineEdit", + "data": { "validator": "(?:(?:[a-zA-Z_][a-zA-Z_0-9]*::)+[a-zA-Z_][a-zA-Z_0-9]*|)" } + }, + { + "name": "Base", + "trDisplayName": "Base class:", + "type": "ComboBox", + "data": + { + "items": [ "QAbstractItemModel", "QAbstractTableModel", "QAbstractListModel" ] + } + }, + + { + "name": "Sp1", + "type": "Spacer", + "data": { "factor": 2 } + }, + { + "name": "CustomHeader", + "trDisplayName": "Customize header row", + "type": "CheckBox", + "data": { + "checked": true, + "checkedValue": true, + "uncheckedValue": false + } + }, + { + "name": "Editable", + "trDisplayName": "Items are editable", + "type": "CheckBox", + "data": { + "checked": false, + "checkedValue": true, + "uncheckedValue": false + } + }, + { + "name": "AddData", + "trDisplayName": "Rows and columns can be added", + "type": "CheckBox", + "data": { + "checked": false, + "checkedValue": true, + "uncheckedValue": false + } + }, { + "name": "RemoveData", + "trDisplayName": "Rows and columns can be removed", + "type": "CheckBox", + "data": { + "checked": false, + "checkedValue": true, + "uncheckedValue": false + } + }, + { + "name": "DynamicFetch", + "trDisplayName": "Fetch data dynamically", + "type": "CheckBox", + "data": { + "checked": false, + "checkedValue": true, + "uncheckedValue": false + } + }, + + { + "name": "HdrFileName", + "type": "LineEdit", + "trDisplayName": "Header file:", + "mandatory": true, + "data": { "trText": "%{JS: Cpp.classToFileName('%{Class}', '%{JS: Util.preferredSuffix('text/x-c++hdr')}')}" } + }, + { + "name": "SrcFileName", + "type": "LineEdit", + "trDisplayName": "Source file:", + "mandatory": true, + "data": { "trText": "%{JS: Cpp.classToFileName('%{Class}', '%{JS: Util.preferredSuffix('text/x-c++src')}')}" } + }, + { + "name": "Path", + "type": "PathChooser", + "trDisplayName": "Path:", + "mandatory": true, + "data": + { + "kind": "existingDirectory", + "basePath": "%{InitialPath}", + "path": "%{InitialPath}" + } + } + ] + }, + { + "trDisplayName": "Project Management", + "trShortTitle": "Summary", + "typeId": "Summary" + } + ], + + "generators": + [ + { + "typeId": "File", + "data": + [ + { + "source": "itemmodel.h", + "target": "%{HdrPath}", + "condition": "%{JS: '%{Base}' === 'QAbstractItemModel'}", + "options": [ + { "key": "Cpp:License:FileName", "value": "%{HdrFileName}" }, + { "key": "Cpp:License:ClassName", "value": "%{CN}" } + ] + }, + { + "source": "itemmodel.cpp", + "target": "%{SrcPath}", + "openInEditor": true, + "condition": "%{JS: '%{Base}' === 'QAbstractItemModel'}", + "options": [ + { "key": "Cpp:License:FileName", "value": "%{SrcFileName}" }, + { "key": "Cpp:License:ClassName", "value": "%{CN}" } + ] + }, + { + "source": "tablemodel.h", + "target": "%{HdrPath}", + "condition": "%{JS: '%{Base}' === 'QAbstractTableModel'}", + "options": [ + { "key": "Cpp:License:FileName", "value": "%{HdrFileName}" }, + { "key": "Cpp:License:ClassName", "value": "%{CN}" } + ] + }, + { + "source": "tablemodel.cpp", + "target": "%{SrcPath}", + "openInEditor": true, + "condition": "%{JS: '%{Base}' === 'QAbstractTableModel'}", + "options": [ + { "key": "Cpp:License:FileName", "value": "%{SrcFileName}" }, + { "key": "Cpp:License:ClassName", "value": "%{CN}" } + ] + }, + { + "source": "listmodel.h", + "target": "%{HdrPath}", + "condition": "%{JS: '%{Base}' === 'QAbstractListModel'}", + "options": [ + { "key": "Cpp:License:FileName", "value": "%{HdrFileName}" }, + { "key": "Cpp:License:ClassName", "value": "%{CN}" } + ] + }, + { + "source": "listmodel.cpp", + "target": "%{SrcPath}", + "openInEditor": true, + "condition": "%{JS: '%{Base}' === 'QAbstractListModel'}", + "options": [ + { "key": "Cpp:License:FileName", "value": "%{SrcFileName}" }, + { "key": "Cpp:License:ClassName", "value": "%{CN}" } + ] + } + ] + } + ] +} |