This commit is contained in:
朱子楚\zhuzi 2024-04-28 20:22:05 +08:00
parent c733f3c60e
commit 96a6d0e7fa
17 changed files with 158 additions and 160 deletions

View File

@ -1968,7 +1968,7 @@ Some contents...</source>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="177"/> <location filename="qml/page/T_TableView.qml" line="177"/>
<location filename="qml/page/T_TableView.qml" line="509"/> <location filename="qml/page/T_TableView.qml" line="510"/>
<source>Name</source> <source>Name</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -1988,67 +1988,67 @@ Some contents...</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="358"/> <location filename="qml/page/T_TableView.qml" line="359"/>
<source>Age</source> <source>Age</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="433"/> <location filename="qml/page/T_TableView.qml" line="434"/>
<source>Clear All</source> <source>Clear All</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="440"/> <location filename="qml/page/T_TableView.qml" line="441"/>
<source>Delete Selection</source> <source>Delete Selection</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="463"/> <location filename="qml/page/T_TableView.qml" line="464"/>
<source>Add a row of Data</source> <source>Add a row of Data</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="469"/> <location filename="qml/page/T_TableView.qml" line="470"/>
<source>Insert a Row</source> <source>Insert a Row</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="476"/> <location filename="qml/page/T_TableView.qml" line="477"/>
<source>Focus not acquired: Please click any item in the form as the target for insertion!</source> <source>Focus not acquired: Please click any item in the form as the target for insertion!</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="504"/> <location filename="qml/page/T_TableView.qml" line="505"/>
<source>Avatar</source> <source>Avatar</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="522"/> <location filename="qml/page/T_TableView.qml" line="523"/>
<source>Address</source> <source>Address</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="530"/> <location filename="qml/page/T_TableView.qml" line="531"/>
<source>Nickname</source> <source>Nickname</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="537"/> <location filename="qml/page/T_TableView.qml" line="538"/>
<source>Long String</source> <source>Long String</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="545"/> <location filename="qml/page/T_TableView.qml" line="546"/>
<source>Options</source> <source>Options</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="564"/> <location filename="qml/page/T_TableView.qml" line="565"/>
<source>&lt;Previous</source> <source>&lt;Previous</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="565"/> <location filename="qml/page/T_TableView.qml" line="566"/>
<source>Next&gt;</source> <source>Next&gt;</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>

View File

@ -2110,7 +2110,7 @@ Some contents...</source>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="177"/> <location filename="qml/page/T_TableView.qml" line="177"/>
<location filename="qml/page/T_TableView.qml" line="509"/> <location filename="qml/page/T_TableView.qml" line="510"/>
<source>Name</source> <source>Name</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -2130,67 +2130,67 @@ Some contents...</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="358"/> <location filename="qml/page/T_TableView.qml" line="359"/>
<source>Age</source> <source>Age</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="433"/> <location filename="qml/page/T_TableView.qml" line="434"/>
<source>Clear All</source> <source>Clear All</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="469"/> <location filename="qml/page/T_TableView.qml" line="470"/>
<source>Insert a Row</source> <source>Insert a Row</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="476"/> <location filename="qml/page/T_TableView.qml" line="477"/>
<source>Focus not acquired: Please click any item in the form as the target for insertion!</source> <source>Focus not acquired: Please click any item in the form as the target for insertion!</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="504"/> <location filename="qml/page/T_TableView.qml" line="505"/>
<source>Avatar</source> <source>Avatar</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="522"/> <location filename="qml/page/T_TableView.qml" line="523"/>
<source>Address</source> <source>Address</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="530"/> <location filename="qml/page/T_TableView.qml" line="531"/>
<source>Nickname</source> <source>Nickname</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="537"/> <location filename="qml/page/T_TableView.qml" line="538"/>
<source>Long String</source> <source>Long String</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="545"/> <location filename="qml/page/T_TableView.qml" line="546"/>
<source>Options</source> <source>Options</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="564"/> <location filename="qml/page/T_TableView.qml" line="565"/>
<source>&lt;Previous</source> <source>&lt;Previous</source>
<translation type="unfinished">&lt;</translation> <translation type="unfinished">&lt;</translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="565"/> <location filename="qml/page/T_TableView.qml" line="566"/>
<source>Next&gt;</source> <source>Next&gt;</source>
<translation type="unfinished">&gt;</translation> <translation type="unfinished">&gt;</translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="440"/> <location filename="qml/page/T_TableView.qml" line="441"/>
<source>Delete Selection</source> <source>Delete Selection</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="qml/page/T_TableView.qml" line="463"/> <location filename="qml/page/T_TableView.qml" line="464"/>
<source>Add a row of Data</source> <source>Add a row of Data</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>

View File

@ -244,7 +244,7 @@ FluContentPage{
clickListener: function(){ clickListener: function(){
root.selectedAll = !root.selectedAll root.selectedAll = !root.selectedAll
var checked = root.selectedAll var checked = root.selectedAll
itemModel.display = table_view.customItem(com_column_checbox,{"checked":checked}) model.display = table_view.customItem(com_column_checbox,{"checked":checked})
for(var i =0;i< table_view.rows ;i++){ for(var i =0;i< table_view.rows ;i++){
var rowData = table_view.getRow(i) var rowData = table_view.getRow(i)
rowData.checkbox = table_view.customItem(com_checbox,{"checked":checked}) rowData.checkbox = table_view.customItem(com_checbox,{"checked":checked})
@ -293,6 +293,7 @@ FluContentPage{
}); });
items = result items = result
textbox.text= String(display) textbox.text= String(display)
selectAll()
} }
onCommit: { onCommit: {
editTextChaged(textbox.text) editTextChaged(textbox.text)

View File

@ -1,6 +1,5 @@
#include "FluApp.h" #include "FluApp.h"
#include <QQmlEngine>
#include <QGuiApplication> #include <QGuiApplication>
#include <QQuickItem> #include <QQuickItem>
#include <QTimer> #include <QTimer>
@ -32,7 +31,7 @@ void FluApp::init(QObject *target, QLocale locale) {
} }
} }
[[maybe_unused]] QJsonArray FluApp::iconDatas(const QString &keyword) { [[maybe_unused]] QJsonArray FluApp::iconData(const QString &keyword) {
QJsonArray arr; QJsonArray arr;
QMetaEnum enumType = Fluent_Icons::staticMetaObject.enumerator(Fluent_Icons::staticMetaObject.indexOfEnumerator("Fluent_IconType")); QMetaEnum enumType = Fluent_Icons::staticMetaObject.enumerator(Fluent_Icons::staticMetaObject.indexOfEnumerator("Fluent_IconType"));
for (int i = 0; i <= enumType.keyCount() - 1; ++i) { for (int i = 0; i <= enumType.keyCount() - 1; ++i) {

View File

@ -36,7 +36,7 @@ SINGLETON(FluApp)
Q_INVOKABLE void init(QObject *target, QLocale locale = QLocale::system()); Q_INVOKABLE void init(QObject *target, QLocale locale = QLocale::system());
[[maybe_unused]] Q_INVOKABLE static QJsonArray iconDatas(const QString &keyword = ""); [[maybe_unused]] Q_INVOKABLE static QJsonArray iconData(const QString &keyword = "");
private: private:
QQmlEngine *_engine{}; QQmlEngine *_engine{};

View File

@ -39,12 +39,10 @@ static inline void setShadow(HWND hwnd){
const MARGINS shadow = {1, 0, 0, 0}; const MARGINS shadow = {1, 0, 0, 0};
typedef HRESULT (WINAPI *DwmExtendFrameIntoClientAreaPtr)(HWND hWnd, const MARGINS *pMarInset); typedef HRESULT (WINAPI *DwmExtendFrameIntoClientAreaPtr)(HWND hWnd, const MARGINS *pMarInset);
HMODULE module = LoadLibraryW(L"dwmapi.dll"); HMODULE module = LoadLibraryW(L"dwmapi.dll");
if (module) if (module) {
{
DwmExtendFrameIntoClientAreaPtr dwm_extendframe_into_client_area_; DwmExtendFrameIntoClientAreaPtr dwm_extendframe_into_client_area_;
dwm_extendframe_into_client_area_ = reinterpret_cast<DwmExtendFrameIntoClientAreaPtr>(GetProcAddress(module, "DwmExtendFrameIntoClientArea")); dwm_extendframe_into_client_area_ = reinterpret_cast<DwmExtendFrameIntoClientAreaPtr>(GetProcAddress(module, "DwmExtendFrameIntoClientArea"));
if (dwm_extendframe_into_client_area_) if (dwm_extendframe_into_client_area_) {
{
dwm_extendframe_into_client_area_(hwnd, &shadow); dwm_extendframe_into_client_area_(hwnd, &shadow);
} }
} }

View File

@ -3,9 +3,8 @@
#include <QJSValueList> #include <QJSValueList>
FluTableSortProxyModel::FluTableSortProxyModel(QSortFilterProxyModel *parent) : QSortFilterProxyModel{parent} { FluTableSortProxyModel::FluTableSortProxyModel(QSortFilterProxyModel *parent) : QSortFilterProxyModel{parent} {
_model = nullptr;
connect(this, &FluTableSortProxyModel::modelChanged, this, [=] { connect(this, &FluTableSortProxyModel::modelChanged, this, [=] {
setSourceModel(this->model()); setSourceModel(this->model().value<QAbstractTableModel *>());
}); });
} }
@ -59,19 +58,18 @@ bool FluTableSortProxyModel::lessThan(const QModelIndex &source_left, const QMod
[[maybe_unused]] QVariant FluTableSortProxyModel::getRow(int rowIndex) { [[maybe_unused]] QVariant FluTableSortProxyModel::getRow(int rowIndex) {
QVariant result; QVariant result;
QMetaObject::invokeMethod(_model, "getRow", Q_RETURN_ARG(QVariant, result), Q_ARG(int, mapToSource(index(rowIndex, 0)).row())); QMetaObject::invokeMethod(_model.value<QAbstractTableModel *>(), "getRow", Q_RETURN_ARG(QVariant, result), Q_ARG(int, mapToSource(index(rowIndex, 0)).row()));
return result; return result;
} }
[[maybe_unused]] void FluTableSortProxyModel::setRow(int rowIndex, const QVariant &val) { [[maybe_unused]] void FluTableSortProxyModel::setRow(int rowIndex, const QVariant &val) {
QMetaObject::invokeMethod(_model, "setRow", Q_ARG(int, mapToSource(index(rowIndex, 0)).row()), Q_ARG(QVariant, val)); QMetaObject::invokeMethod(_model.value<QAbstractTableModel *>(), "setRow", Q_ARG(int, mapToSource(index(rowIndex, 0)).row()), Q_ARG(QVariant, val));
} }
[[maybe_unused]] void FluTableSortProxyModel::insertRow(int rowIndex, const QVariant &val) { [[maybe_unused]] void FluTableSortProxyModel::insertRow(int rowIndex, const QVariant &val) {
QMetaObject::invokeMethod(_model, "insertRow", Q_ARG(int, mapToSource(index(rowIndex, 0)).row()), Q_ARG(QVariant, val)); QMetaObject::invokeMethod(_model.value<QAbstractTableModel *>(), "insertRow", Q_ARG(int, mapToSource(index(rowIndex, 0)).row()), Q_ARG(QVariant, val));
} }
[[maybe_unused]] void FluTableSortProxyModel::removeRow(int rowIndex, int rows) { [[maybe_unused]] void FluTableSortProxyModel::removeRow(int rowIndex, int rows) {
QMetaObject::invokeMethod(_model, "removeRow", Q_ARG(int, mapToSource(index(rowIndex, 0)).row()), Q_ARG(int, rows)); QMetaObject::invokeMethod(_model.value<QAbstractTableModel *>(), "removeRow", Q_ARG(int, mapToSource(index(rowIndex, 0)).row()), Q_ARG(int, rows));
} }

View File

@ -8,7 +8,7 @@
class FluTableSortProxyModel : public QSortFilterProxyModel { class FluTableSortProxyModel : public QSortFilterProxyModel {
Q_OBJECT Q_OBJECT
Q_PROPERTY_AUTO_P(QAbstractTableModel*, model) Q_PROPERTY_AUTO_P(QVariant, model)
QML_NAMED_ELEMENT(FluTableSortProxyModel) QML_NAMED_ELEMENT(FluTableSortProxyModel)
public: public:
explicit FluTableSortProxyModel(QSortFilterProxyModel *parent = nullptr); explicit FluTableSortProxyModel(QSortFilterProxyModel *parent = nullptr);

View File

@ -4,7 +4,7 @@ import FluentUI 1.0
Item { Item {
//DropShadow //DropShadow
property color color: FluTheme.dark ? "#AAAAAA" : "#999999" property color color: FluTheme.dark ? "#000000" : "#999999"
property int elevation: 5 property int elevation: 5
property int radius: 4 property int radius: 4
id:control id:control

View File

@ -9,7 +9,9 @@ Rectangle {
readonly property alias rows: table_view.rows readonly property alias rows: table_view.rows
readonly property alias columns: table_view.columns readonly property alias columns: table_view.columns
readonly property alias current: d.current readonly property alias current: d.current
readonly property alias sourceModel: table_model property var sourceModel:FluTableModel {
columnSource: control.columnSource
}
property var columnSource: [] property var columnSource: []
property var dataSource property var dataSource
property color borderColor: FluTheme.dark ? Qt.rgba(37/255,37/255,37/255,1) : Qt.rgba(228/255,228/255,228/255,1) property color borderColor: FluTheme.dark ? Qt.rgba(37/255,37/255,37/255,1) : Qt.rgba(228/255,228/255,228/255,1)
@ -29,7 +31,7 @@ Rectangle {
var columns= [] var columns= []
var headerRow = {} var headerRow = {}
columnSource.forEach(function(item){ columnSource.forEach(function(item){
var column = Qt.createQmlObject('import Qt.labs.qmlmodels 1.0;TableModelColumn{}',table_model); var column = Qt.createQmlObject('import Qt.labs.qmlmodels 1.0;TableModelColumn{}',sourceModel);
column.display = item.dataIndex column.display = item.dataIndex
columns.push(column) columns.push(column)
headerRow[item.dataIndex] = item.title headerRow[item.dataIndex] = item.title
@ -58,12 +60,8 @@ Rectangle {
} }
} }
onDataSourceChanged: { onDataSourceChanged: {
table_model.clear() sourceModel.clear()
table_model.rows = dataSource sourceModel.rows = dataSource
}
FluTableModel {
id:table_model
columnSource: control.columnSource
} }
TableModel{ TableModel{
id:header_column_model id:header_column_model
@ -75,7 +73,7 @@ Rectangle {
} }
FluTableSortProxyModel{ FluTableSortProxyModel{
id:table_sort_model id:table_sort_model
model: table_model model: control.sourceModel
} }
Component{ Component{
id:com_edit id:com_edit
@ -191,6 +189,7 @@ Rectangle {
id:com_table_delegate id:com_table_delegate
MouseArea{ MouseArea{
id:item_table_mouse id:item_table_mouse
property var _model: model
property bool isRowSelected: { property bool isRowSelected: {
if(rowModel === null) if(rowModel === null)
return false return false
@ -283,6 +282,7 @@ Rectangle {
} }
FluLoader{ FluLoader{
id: item_table_loader id: item_table_loader
property var model: item_table_mouse._model
property var display: rowModel[columnModel.dataIndex] property var display: rowModel[columnModel.dataIndex]
property var rowModel : model.rowModel property var rowModel : model.rowModel
property var columnModel : model.columnModel property var columnModel : model.columnModel
@ -446,7 +446,7 @@ Rectangle {
id:column_item_control id:column_item_control
readonly property real cellPadding: 8 readonly property real cellPadding: 8
property bool canceled: false property bool canceled: false
property int columnIndex: column property var _model: model
readonly property var columnObject : control.columnSource[column] readonly property var columnObject : control.columnSource[column]
implicitWidth: { implicitWidth: {
return (item_column_loader.item && item_column_loader.item.implicitWidth) + (cellPadding * 2) return (item_column_loader.item && item_column_loader.item.implicitWidth) + (cellPadding * 2)
@ -503,22 +503,23 @@ Rectangle {
} }
FluLoader{ FluLoader{
id:item_column_loader id:item_column_loader
property var itemModel: model property var model: column_item_control._model
property var modelData: model.display property var display: model.display
property var tableView: table_view property var tableView: table_view
property var tableModel: table_model property var sourceModel: control.sourceModel
property bool isObject: typeof(display) == "object"
property var options:{ property var options:{
if(typeof(modelData) == "object"){ if(isObject){
return modelData.options return display.options
} }
return {} return {}
} }
property int column: column_item_control.columnIndex property int column: model.column
width: parent.width width: parent.width
height: parent.height height: parent.height
sourceComponent: { sourceComponent: {
if(typeof(modelData) == "object"){ if(isObject){
return modelData.comId return display.comId
} }
return com_column_text return com_column_text
} }
@ -686,7 +687,7 @@ Rectangle {
id:com_column_text id:com_column_text
FluText { FluText {
id: column_text id: column_text
text: modelData text: String(display)
anchors.fill: parent anchors.fill: parent
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
@ -835,7 +836,7 @@ Rectangle {
function sort(callback=undefined){ function sort(callback=undefined){
if(callback){ if(callback){
table_sort_model.setComparator(function(left,right){ table_sort_model.setComparator(function(left,right){
return callback(table_model.getRow(left),table_model.getRow(right)) return callback(sourceModel.getRow(left),sourceModel.getRow(right))
}) })
}else{ }else{
table_sort_model.setComparator(undefined) table_sort_model.setComparator(undefined)
@ -844,7 +845,7 @@ Rectangle {
function filter(callback=undefined){ function filter(callback=undefined){
if(callback){ if(callback){
table_sort_model.setFilter(function(index){ table_sort_model.setFilter(function(index){
return callback(table_model.getRow(index)) return callback(sourceModel.getRow(index))
}) })
}else{ }else{
table_sort_model.setFilter(undefined) table_sort_model.setFilter(undefined)
@ -868,7 +869,7 @@ Rectangle {
} }
function insertRow(rowIndex,obj){ function insertRow(rowIndex,obj){
if(rowIndex>=0 && rowIndex<table_view.rows){ if(rowIndex>=0 && rowIndex<table_view.rows){
table_view.model.insertRow(rowIndex,obj) sourceModel.insertRow(rowIndex,obj)
} }
} }
function currentIndex(){ function currentIndex(){
@ -876,8 +877,8 @@ Rectangle {
if(!d.current){ if(!d.current){
return index return index
} }
for (var i = 0; i <= table_model.rowCount-1; i++) { for (var i = 0; i <= sourceModel.rowCount-1; i++) {
var sourceItem = table_model.getRow(i); var sourceItem = sourceModel.getRow(i);
if(sourceItem._key === d.current._key){ if(sourceItem._key === d.current._key){
index = i index = i
break break
@ -886,6 +887,6 @@ Rectangle {
return index return index
} }
function appendRow(obj){ function appendRow(obj){
table_model.appendRow(obj) sourceModel.appendRow(obj)
} }
} }

View File

@ -4,7 +4,7 @@ import FluentUI
Item { Item {
//DropShadow //DropShadow
property color color: FluTheme.dark ? "#AAAAAA" : "#999999" property color color: FluTheme.dark ? "#000000" : "#999999"
property int elevation: 5 property int elevation: 5
property int radius: 4 property int radius: 4
id:control id:control

View File

@ -9,7 +9,9 @@ Rectangle {
readonly property alias rows: table_view.rows readonly property alias rows: table_view.rows
readonly property alias columns: table_view.columns readonly property alias columns: table_view.columns
readonly property alias current: d.current readonly property alias current: d.current
readonly property alias sourceModel: table_model property var sourceModel:FluTableModel {
columnSource: control.columnSource
}
property var columnSource: [] property var columnSource: []
property var dataSource property var dataSource
property color borderColor: FluTheme.dark ? Qt.rgba(37/255,37/255,37/255,1) : Qt.rgba(228/255,228/255,228/255,1) property color borderColor: FluTheme.dark ? Qt.rgba(37/255,37/255,37/255,1) : Qt.rgba(228/255,228/255,228/255,1)
@ -29,7 +31,7 @@ Rectangle {
var columns= [] var columns= []
var headerRow = {} var headerRow = {}
columnSource.forEach(function(item){ columnSource.forEach(function(item){
var column = Qt.createQmlObject('import Qt.labs.qmlmodels 1.0;TableModelColumn{}',table_model); var column = Qt.createQmlObject('import Qt.labs.qmlmodels 1.0;TableModelColumn{}',sourceModel);
column.display = item.dataIndex column.display = item.dataIndex
columns.push(column) columns.push(column)
headerRow[item.dataIndex] = item.title headerRow[item.dataIndex] = item.title
@ -58,12 +60,8 @@ Rectangle {
} }
} }
onDataSourceChanged: { onDataSourceChanged: {
table_model.clear() sourceModel.clear()
table_model.rows = dataSource sourceModel.rows = dataSource
}
FluTableModel {
id:table_model
columnSource: control.columnSource
} }
TableModel{ TableModel{
id:header_column_model id:header_column_model
@ -75,7 +73,7 @@ Rectangle {
} }
FluTableSortProxyModel{ FluTableSortProxyModel{
id:table_sort_model id:table_sort_model
model: table_model model: control.sourceModel
} }
Component{ Component{
id:com_edit id:com_edit
@ -191,6 +189,7 @@ Rectangle {
id:com_table_delegate id:com_table_delegate
MouseArea{ MouseArea{
id:item_table_mouse id:item_table_mouse
property var _model: model
property bool isRowSelected: { property bool isRowSelected: {
if(rowModel === null) if(rowModel === null)
return false return false
@ -283,6 +282,7 @@ Rectangle {
} }
FluLoader{ FluLoader{
id: item_table_loader id: item_table_loader
property var model: item_table_mouse._model
property var display: rowModel[columnModel.dataIndex] property var display: rowModel[columnModel.dataIndex]
property var rowModel : model.rowModel property var rowModel : model.rowModel
property var columnModel : model.columnModel property var columnModel : model.columnModel
@ -446,7 +446,7 @@ Rectangle {
id:column_item_control id:column_item_control
readonly property real cellPadding: 8 readonly property real cellPadding: 8
property bool canceled: false property bool canceled: false
property int columnIndex: column property var _model: model
readonly property var columnObject : control.columnSource[column] readonly property var columnObject : control.columnSource[column]
implicitWidth: { implicitWidth: {
return (item_column_loader.item && item_column_loader.item.implicitWidth) + (cellPadding * 2) return (item_column_loader.item && item_column_loader.item.implicitWidth) + (cellPadding * 2)
@ -503,22 +503,23 @@ Rectangle {
} }
FluLoader{ FluLoader{
id:item_column_loader id:item_column_loader
property var itemModel: model property var model: column_item_control._model
property var modelData: model.display property var display: model.display
property var tableView: table_view property var tableView: table_view
property var tableModel: table_model property var sourceModel: control.sourceModel
property bool isObject: typeof(display) == "object"
property var options:{ property var options:{
if(typeof(modelData) == "object"){ if(isObject){
return modelData.options return display.options
} }
return {} return {}
} }
property int column: column_item_control.columnIndex property int column: model.column
width: parent.width width: parent.width
height: parent.height height: parent.height
sourceComponent: { sourceComponent: {
if(typeof(modelData) == "object"){ if(isObject){
return modelData.comId return display.comId
} }
return com_column_text return com_column_text
} }
@ -686,7 +687,7 @@ Rectangle {
id:com_column_text id:com_column_text
FluText { FluText {
id: column_text id: column_text
text: modelData text: String(display)
anchors.fill: parent anchors.fill: parent
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
@ -835,7 +836,7 @@ Rectangle {
function sort(callback=undefined){ function sort(callback=undefined){
if(callback){ if(callback){
table_sort_model.setComparator(function(left,right){ table_sort_model.setComparator(function(left,right){
return callback(table_model.getRow(left),table_model.getRow(right)) return callback(sourceModel.getRow(left),sourceModel.getRow(right))
}) })
}else{ }else{
table_sort_model.setComparator(undefined) table_sort_model.setComparator(undefined)
@ -844,7 +845,7 @@ Rectangle {
function filter(callback=undefined){ function filter(callback=undefined){
if(callback){ if(callback){
table_sort_model.setFilter(function(index){ table_sort_model.setFilter(function(index){
return callback(table_model.getRow(index)) return callback(sourceModel.getRow(index))
}) })
}else{ }else{
table_sort_model.setFilter(undefined) table_sort_model.setFilter(undefined)
@ -868,7 +869,7 @@ Rectangle {
} }
function insertRow(rowIndex,obj){ function insertRow(rowIndex,obj){
if(rowIndex>=0 && rowIndex<table_view.rows){ if(rowIndex>=0 && rowIndex<table_view.rows){
table_view.model.insertRow(rowIndex,obj) sourceModel.insertRow(rowIndex,obj)
} }
} }
function currentIndex(){ function currentIndex(){
@ -876,8 +877,8 @@ Rectangle {
if(!d.current){ if(!d.current){
return index return index
} }
for (var i = 0; i <= table_model.rowCount-1; i++) { for (var i = 0; i <= sourceModel.rowCount-1; i++) {
var sourceItem = table_model.getRow(i); var sourceItem = sourceModel.getRow(i);
if(sourceItem._key === d.current._key){ if(sourceItem._key === d.current._key){
index = i index = i
break break
@ -886,6 +887,6 @@ Rectangle {
return index return index
} }
function appendRow(obj){ function appendRow(obj){
table_model.appendRow(obj) sourceModel.appendRow(obj)
} }
} }