Make the fibonacci number list look similar across styles
parent
0a143b6bad
commit
d544db5a1b
|
@ -81,9 +81,13 @@
|
||||||
"FibonacciList": {
|
"FibonacciList": {
|
||||||
"type": "List",
|
"type": "List",
|
||||||
"itemProperties": {
|
"itemProperties": {
|
||||||
"result": {
|
"row": {
|
||||||
"type": "quint64",
|
"type": "quint64",
|
||||||
"roles": [ [ "display" ] ]
|
"roles": [ [ "display" ] ]
|
||||||
|
},
|
||||||
|
"fibonacciNumber": {
|
||||||
|
"type": "quint64",
|
||||||
|
"roles": [ [], [ "display" ] ]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,19 +4,16 @@ import QtQuick.Controls 1.5
|
||||||
import QtQuick.Layouts 1.3
|
import QtQuick.Layouts 1.3
|
||||||
|
|
||||||
TableView {
|
TableView {
|
||||||
id: listView
|
|
||||||
model: demo.fibonacciList
|
model: demo.fibonacciList
|
||||||
TableViewColumn {
|
TableViewColumn {
|
||||||
delegate: Text {
|
role: "row"
|
||||||
text: styleData.row + 1
|
title: qsTr("Row")
|
||||||
}
|
|
||||||
title: "Row"
|
|
||||||
width: 100
|
width: 100
|
||||||
Component.onCompleted: resizeToContents()
|
Component.onCompleted: resizeToContents()
|
||||||
}
|
}
|
||||||
TableViewColumn {
|
TableViewColumn {
|
||||||
role: "display"
|
role: "fibonacciNumber"
|
||||||
title: "Fibonacci Number"
|
title: qsTr("Fibonacci number")
|
||||||
width: 100
|
width: 100
|
||||||
Component.onCompleted: resizeToContents()
|
Component.onCompleted: resizeToContents()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,6 @@ import QtQuick.Controls 1.5
|
||||||
import QtQuick.Layouts 1.3
|
import QtQuick.Layouts 1.3
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
id: content
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Image {
|
Image {
|
||||||
sourceSize.height: 2* box.height
|
sourceSize.height: 2* box.height
|
||||||
fillMode: Image.PreserveAspectFit
|
fillMode: Image.PreserveAspectFit
|
||||||
|
@ -15,9 +13,9 @@ RowLayout {
|
||||||
currentIndex: qtquickIndex
|
currentIndex: qtquickIndex
|
||||||
model: styles
|
model: styles
|
||||||
textRole: "display"
|
textRole: "display"
|
||||||
onCurrentIndexChanged: {
|
onActivated: {
|
||||||
if (currentIndex !== qtquickIndex) {
|
if (index !== qtquickIndex) {
|
||||||
widgets.currentIndex = currentIndex;
|
widgets.currentIndex = index;
|
||||||
application.close();
|
application.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,76 +7,30 @@ ApplicationWindow {
|
||||||
property string initialTab: "style"
|
property string initialTab: "style"
|
||||||
property int qtquickIndex: 0
|
property int qtquickIndex: 0
|
||||||
visible: true
|
visible: true
|
||||||
footer: StyleSwitcher {
|
height: 500
|
||||||
anchors.fill: parent
|
header: TabBar {
|
||||||
}
|
id: bar
|
||||||
contentItem {
|
width: parent.width
|
||||||
TabBar {
|
TabButton {
|
||||||
id: bar
|
text: "object"
|
||||||
width: parent.width
|
|
||||||
TabButton {
|
|
||||||
text: "object"
|
|
||||||
}
|
|
||||||
TabButton {
|
|
||||||
text: "list"
|
|
||||||
}
|
|
||||||
TabButton {
|
|
||||||
text: "tree"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
StackLayout {
|
TabButton {
|
||||||
width: parent.width
|
text: "list"
|
||||||
anchors.top: bar.bottom
|
}
|
||||||
anchors.bottom: parent.bottom
|
TabButton {
|
||||||
currentIndex: bar.currentIndex
|
text: "tree"
|
||||||
ColumnLayout {
|
}
|
||||||
ComboBox {
|
}
|
||||||
currentIndex: qtquickIndex
|
footer: StyleSwitcher2 {
|
||||||
model: styles
|
}
|
||||||
textRole: "display"
|
StackLayout {
|
||||||
onCurrentIndexChanged: {
|
anchors.fill: parent
|
||||||
if (currentIndex != qtquickIndex) {
|
currentIndex: bar.currentIndex
|
||||||
widgets.currentIndex = currentIndex
|
Fibonacci2 {}
|
||||||
application.close()
|
FibonacciList2 {}
|
||||||
}
|
Text {
|
||||||
}
|
id: treeView
|
||||||
}
|
text: "No TreeView in QtQuick Controls 2"
|
||||||
Image {
|
|
||||||
source: "../logo.svg"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
RowLayout {
|
|
||||||
TextField {
|
|
||||||
id: fibonacciInput
|
|
||||||
placeholderText: "Your number"
|
|
||||||
validator: IntValidator {
|
|
||||||
bottom: 0
|
|
||||||
top: 100
|
|
||||||
}
|
|
||||||
Component.onCompleted: {
|
|
||||||
text = demo.fibonacci.input
|
|
||||||
}
|
|
||||||
onTextChanged: {
|
|
||||||
demo.fibonacci.input = parseInt(text, 10)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Text {
|
|
||||||
text: "The Fibonacci number: " + demo.fibonacci.result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ListView {
|
|
||||||
id: listView
|
|
||||||
model: demo.fibonacciList
|
|
||||||
delegate: Row {
|
|
||||||
Text {
|
|
||||||
text: result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Text {
|
|
||||||
id: treeView
|
|
||||||
text: "No TreeView in QtQuick Controls 2"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,5 +7,8 @@
|
||||||
<file>qml/Fibonacci.qml</file>
|
<file>qml/Fibonacci.qml</file>
|
||||||
<file>qml/FibonacciList.qml</file>
|
<file>qml/FibonacciList.qml</file>
|
||||||
<file>qml/StyleSwitcher.qml</file>
|
<file>qml/StyleSwitcher.qml</file>
|
||||||
|
<file>qml/StyleSwitcher2.qml</file>
|
||||||
|
<file>qml/Fibonacci2.qml</file>
|
||||||
|
<file>qml/FibonacciList2.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
@ -75,7 +75,10 @@ impl FibonacciListTrait for FibonacciList {
|
||||||
fn row_count(&self) -> usize {
|
fn row_count(&self) -> usize {
|
||||||
93
|
93
|
||||||
}
|
}
|
||||||
fn result(&self, row: usize) -> u64 {
|
fn row(&self, row: usize) -> u64 {
|
||||||
|
row as u64 + 1
|
||||||
|
}
|
||||||
|
fn fibonacci_number(&self, row: usize) -> u64 {
|
||||||
fibonacci(row as u32 + 1) as u64
|
fibonacci(row as u32 + 1) as u64
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -437,7 +437,8 @@ pub trait FibonacciListTrait {
|
||||||
}
|
}
|
||||||
fn fetch_more(&mut self) {}
|
fn fetch_more(&mut self) {}
|
||||||
fn sort(&mut self, u8, SortOrder) {}
|
fn sort(&mut self, u8, SortOrder) {}
|
||||||
fn result(&self, item: usize) -> u64;
|
fn fibonacci_number(&self, item: usize) -> u64;
|
||||||
|
fn row(&self, item: usize) -> u64;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -497,8 +498,13 @@ pub unsafe extern "C" fn fibonacci_list_sort(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn fibonacci_list_data_result(ptr: *const FibonacciList, row: c_int) -> u64 {
|
pub unsafe extern "C" fn fibonacci_list_data_fibonacci_number(ptr: *const FibonacciList, row: c_int) -> u64 {
|
||||||
(&*ptr).result(row as usize).into()
|
(&*ptr).fibonacci_number(row as usize).into()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn fibonacci_list_data_row(ptr: *const FibonacciList, row: c_int) -> u64 {
|
||||||
|
(&*ptr).row(row as usize).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FileSystemTreeQObject {}
|
pub struct FileSystemTreeQObject {}
|
||||||
|
|
|
@ -147,7 +147,8 @@ extern "C" {
|
||||||
};
|
};
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
quint64 fibonacci_list_data_result(const FibonacciList::Private*, int);
|
quint64 fibonacci_list_data_fibonacci_number(const FibonacciList::Private*, int);
|
||||||
|
quint64 fibonacci_list_data_row(const FibonacciList::Private*, int);
|
||||||
void fibonacci_list_sort(FibonacciList::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
|
void fibonacci_list_sort(FibonacciList::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
|
||||||
|
|
||||||
int fibonacci_list_row_count(const FibonacciList::Private*);
|
int fibonacci_list_row_count(const FibonacciList::Private*);
|
||||||
|
@ -156,7 +157,7 @@ extern "C" {
|
||||||
}
|
}
|
||||||
int FibonacciList::columnCount(const QModelIndex &parent) const
|
int FibonacciList::columnCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
return (parent.isValid()) ? 0 : 1;
|
return (parent.isValid()) ? 0 : 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FibonacciList::hasChildren(const QModelIndex &parent) const
|
bool FibonacciList::hasChildren(const QModelIndex &parent) const
|
||||||
|
@ -171,7 +172,7 @@ int FibonacciList::rowCount(const QModelIndex &parent) const
|
||||||
|
|
||||||
QModelIndex FibonacciList::index(int row, int column, const QModelIndex &parent) const
|
QModelIndex FibonacciList::index(int row, int column, const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if (!parent.isValid() && row >= 0 && row < rowCount(parent) && column >= 0 && column < 1) {
|
if (!parent.isValid() && row >= 0 && row < rowCount(parent) && column >= 0 && column < 2) {
|
||||||
return createIndex(row, column, (quintptr)row);
|
return createIndex(row, column, (quintptr)row);
|
||||||
}
|
}
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
@ -204,10 +205,17 @@ Qt::ItemFlags FibonacciList::flags(const QModelIndex &i) const
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant FibonacciList::result(int row) const
|
QVariant FibonacciList::fibonacciNumber(int row) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
v = fibonacci_list_data_result(m_d, row);
|
v = fibonacci_list_data_fibonacci_number(m_d, row);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant FibonacciList::row(int row) const
|
||||||
|
{
|
||||||
|
QVariant v;
|
||||||
|
v = fibonacci_list_data_row(m_d, row);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,10 +224,18 @@ QVariant FibonacciList::data(const QModelIndex &index, int role) const
|
||||||
Q_ASSERT(rowCount(index.parent()) > index.row());
|
Q_ASSERT(rowCount(index.parent()) > index.row());
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0:
|
case 0:
|
||||||
|
switch (role) {
|
||||||
|
case Qt::UserRole + 0:
|
||||||
|
return fibonacciNumber(index.row());
|
||||||
|
case Qt::DisplayRole:
|
||||||
|
case Qt::UserRole + 1:
|
||||||
|
return row(index.row());
|
||||||
|
}
|
||||||
|
case 1:
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
case Qt::UserRole + 0:
|
case Qt::UserRole + 0:
|
||||||
return result(index.row());
|
return fibonacciNumber(index.row());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -227,7 +243,8 @@ QVariant FibonacciList::data(const QModelIndex &index, int role) const
|
||||||
|
|
||||||
QHash<int, QByteArray> FibonacciList::roleNames() const {
|
QHash<int, QByteArray> FibonacciList::roleNames() const {
|
||||||
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
||||||
names.insert(Qt::UserRole + 0, "result");
|
names.insert(Qt::UserRole + 0, "fibonacciNumber");
|
||||||
|
names.insert(Qt::UserRole + 1, "row");
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
QVariant FibonacciList::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant FibonacciList::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
|
@ -906,7 +923,7 @@ Demo::Demo(QObject *parent):
|
||||||
},
|
},
|
||||||
[](FibonacciList* o, quintptr first, quintptr last) {
|
[](FibonacciList* o, quintptr first, quintptr last) {
|
||||||
o->dataChanged(o->createIndex(first, 0, first),
|
o->dataChanged(o->createIndex(first, 0, first),
|
||||||
o->createIndex(last, 0, last));
|
o->createIndex(last, 1, last));
|
||||||
},
|
},
|
||||||
[](FibonacciList* o) {
|
[](FibonacciList* o) {
|
||||||
o->beginResetModel();
|
o->beginResetModel();
|
||||||
|
@ -1155,7 +1172,7 @@ FibonacciList::FibonacciList(QObject *parent):
|
||||||
},
|
},
|
||||||
[](FibonacciList* o, quintptr first, quintptr last) {
|
[](FibonacciList* o, quintptr first, quintptr last) {
|
||||||
o->dataChanged(o->createIndex(first, 0, first),
|
o->dataChanged(o->createIndex(first, 0, first),
|
||||||
o->createIndex(last, 0, last));
|
o->createIndex(last, 1, last));
|
||||||
},
|
},
|
||||||
[](FibonacciList* o) {
|
[](FibonacciList* o) {
|
||||||
o->beginResetModel();
|
o->beginResetModel();
|
||||||
|
@ -1190,7 +1207,8 @@ FibonacciList::~FibonacciList() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void FibonacciList::initHeaderData() {
|
void FibonacciList::initHeaderData() {
|
||||||
m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("result"));
|
m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("row"));
|
||||||
|
m_headerData.insert(qMakePair(1, Qt::DisplayRole), QVariant("fibonacciNumber"));
|
||||||
}
|
}
|
||||||
FileSystemTree::FileSystemTree(bool /*owned*/, QObject *parent):
|
FileSystemTree::FileSystemTree(bool /*owned*/, QObject *parent):
|
||||||
QAbstractItemModel(parent),
|
QAbstractItemModel(parent),
|
||||||
|
|
|
@ -102,7 +102,8 @@ public:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||||
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
|
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
|
||||||
Q_INVOKABLE QVariant result(int row) const;
|
Q_INVOKABLE QVariant fibonacciNumber(int row) const;
|
||||||
|
Q_INVOKABLE QVariant row(int row) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
// new data is ready to be made available to the model with fetchMore()
|
// new data is ready to be made available to the model with fetchMore()
|
||||||
|
|
|
@ -84,6 +84,8 @@ void createQtQuick(const QString& name, const QString& qml, Model* model,
|
||||||
QWindow* window = getWindow(widgets);
|
QWindow* window = getWindow(widgets);
|
||||||
if (window) {
|
if (window) {
|
||||||
geometry = window->geometry();
|
geometry = window->geometry();
|
||||||
|
} else {
|
||||||
|
geometry = QRect(0, 0, 500, 500);
|
||||||
}
|
}
|
||||||
engine->load(QUrl(qml));
|
engine->load(QUrl(qml));
|
||||||
QObject* root = engine->rootObjects().first();
|
QObject* root = engine->rootObjects().first();
|
||||||
|
@ -193,8 +195,13 @@ QWidget* createObjectTab(Model* model) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* createListTab(Model* model) {
|
QWidget* createListTab(Model* model) {
|
||||||
QListView* view = new QListView();
|
QTableView* view = new QTableView();
|
||||||
|
model->demo.fibonacciList()->setHeaderData(0, Qt::Horizontal,
|
||||||
|
view->tr("Row"), Qt::DisplayRole);
|
||||||
|
model->demo.fibonacciList()->setHeaderData(1, Qt::Horizontal,
|
||||||
|
view->tr("Fibonacci number"), Qt::DisplayRole);
|
||||||
view->setModel(model->demo.fibonacciList());
|
view->setModel(model->demo.fibonacciList());
|
||||||
|
view->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,7 +275,7 @@ QWidget* createChartTab(Model* model) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QTabWidget* createTabs(Model* model, QComboBox* box) {
|
QTabWidget* createTabs(Model* model) {
|
||||||
QTabWidget* tabs = new QTabWidget();
|
QTabWidget* tabs = new QTabWidget();
|
||||||
tabs->addTab(createObjectTab(model), "object");
|
tabs->addTab(createObjectTab(model), "object");
|
||||||
tabs->addTab(createListTab(model), "list");
|
tabs->addTab(createListTab(model), "list");
|
||||||
|
@ -292,7 +299,7 @@ void createMainWindow(Model* model, const QString& initialStyle,
|
||||||
QComboBox* box = createStyleComboBox(model);
|
QComboBox* box = createStyleComboBox(model);
|
||||||
QStatusBar* statusBar = createStatusBar(model, main, box, initialTab);
|
QStatusBar* statusBar = createStatusBar(model, main, box, initialTab);
|
||||||
main->setStatusBar(statusBar);
|
main->setStatusBar(statusBar);
|
||||||
QTabWidget* tabs = createTabs(model, box);
|
QTabWidget* tabs = createTabs(model);
|
||||||
main->setCentralWidget(tabs);
|
main->setCentralWidget(tabs);
|
||||||
main->show();
|
main->show();
|
||||||
box->setCurrentText(initialStyle);
|
box->setCurrentText(initialStyle);
|
||||||
|
|
Loading…
Reference in New Issue