I have a doubt with canFetch() and fetchMore() functions.
i am implementing tree structure, when i scroll till the end canfetch() will be call and if returns true fetchMore() will be called where we have to fetch the data and insert items into tree.
void model::fetchMore(const QModelIndex& f_parent)
{
//fetch the data needed and create items
beginInsertRows(f_parent, row, lastRow);
endInsertRows();
}
Please let me know In beginInsertRows, what numbers exactly we need to specify, It is confusing me..
I have fetched some data now, in that from top I have 5 child's and followed by 10 parents and each parent has 10 child's. (f_parent parent has 5 childs already)
Now I need to insert 5 more children followed by 10 parents.
now what numbers I need to specify in beginInsertRows() exactly.
beginInsertRows(f_parent,5,f_parent.row()+10); ?
beginInsertRows(f_parent,f_parent.row(),f_parent.row()+10); ?
beginInsertRows(f_parent,5,10); ?
Related
I have two select list : A and B.
A is the parent LOV of B. So when A changes B gets refreshed and changes based on the value of A.
--> B now has lower values to chose from.
Now my problem is that when I select values via PL SQL into the select list (from the database) that select list B never returns the wanted value but the values I would get when I choose the value from A.
--> B should be set to John and A should be set to IT.
--> B returns null value but I can choose all people that work in IT.
When I remove A as Parent LOV then the right value is inserted into B but the list dosent adapt to A.
I use Oracle APEX v.19.1.0.00.15
So I tried it out myself.
I had a button that triggers a Dynamic action. The action was PLSQL code and it just assigned the parent and child. If I set it to assign both of them in the same action, it didnt work, if I separated them out it did.
So change out the actions in your DA(dynamic action) first you have a PLSQL action that assigns the parent item, and you also need to set the Items to return to return this item. Then you have a second action that is the same thing, just for the child.
This works for me, so I am hoping it works for you, let me know if it is still causing you issues
I'm using Redux (with React) to handle state in my application. I have the following scenario:
Load a list of items
Apply transform(s) to a list (arbitrary number of transforms)
Reduce displayed items in list
Increase displayed items in list
At step 4: How do I best achieve to again increase displayed items, with transforms from step 1 still applied/reapplied?
An example:
Load list with 50 items
Uppercase items
Filter items to display items with less than 4 chars (=> results in
30 items)
Apply filter again to display items with less than 10 chars (=> should result in 50 items with all still uppercased)
Based on your description, the only actual state that should be kept in the store is the initial data and the information about current filters. For example, your state shape might look like:
{
items: ['April', 'Jake', 'Mary', 'Zooey', 'Dan'],
filters: {
isUppercase: false,
maxLength: 10
}
}
As you change the data, the items reducer would handle adding and deleting items. As you change the filters, the filter reducer would record the new filter setting.
Now comes the important part. The actual filtering happens when the data is selected for the components.
We suggest to store the minimal possible state in Redux. In this case the list itself and the information about the filters is the minimal possible state. The current list with the filters applied can always be calculated from the state, so it shouldn’t be in the state.
Instead, you can write a pure function that selects the data according to the current state:
function filterItems(items, filters) {
return items.filter(item => {
// return true or false depending on your logic
})
}
Now, if you use React, you can call it in your render() method:
var filteredItems = filterItems(this.props.items, this.props.filters)
You might find that re-computing this on every render can be inefficient. Thankfully, the solution is simple: memoization. Make sure the derived data is only recalculated when the inputs change. Reselect is a tiny library that lets you do that, and it is often used together with Redux.
You can find more information about this topic with some examples in the official Computing Derived Data recipe on Redux website, and in the Reselect README.
In my app I'd like to insert an item at the top of a QTreeView.
What I have so far will insert an item just above the currently selected item. The code (nicked, I think, from the EditableTreeviewDemo):
QModelIndex index = this->selectionModel()->currentIndex();
QAbstractItemModel *model = this->model();
if (!model->insertRow(index.row(), index.parent()))
return;
I guess what I need is the index to the current first row? How do I get this?
As a side question, what happens to the current index when a row is inserted? Does it continue to point to the same item, or the same row?
Well first you have to know that insertRow is a function from QAbstractItemModel and it will call insertRows (with an s). This function must be redefined in your model subclass if you want to allow insertion of data in your model.
http://doc.qt.io/qt-5/qabstractitemmodel.html#insertRows
Also consider that any parent of a topmost index is a invalid QModelIndex. Then the call to do would be :
model->insertRow(0, QModelIndex());
And because this is the default value for the second parameter, simply call :
model->insertRow(0);
Then in your redefinition of insertRows simply check the validity of you parent index to ensure you news underlying data is created where you want it to be.
For you question, inserting data in the model won't affect the current and selected items.
There is a method
void QStandardItemModel::appendRow(QStandardItem * item)
in class QStandardItemModel. I cannot figure out where the item is appended, or who the item's parent is after appending?
And another method
bool QStandardItemModel::insertRow(int row, const QModelIndex & parent = QModelIndex())
shows the parent but which item will be appended to the parent?
The first question is easy. As the name says: Append. It is appended to a list or a tree, which has only one column.
The second one is difficult. This function is not directly about inserting items, but about the algorithm how to insert items. In a complicated tree this is not a necessarily trivial task. Adding nodes, changing the dimension of a tree. You have to implement this virtual method, when you have to create an editable tree. In that case making room for a new item and actually inserting the item are two different tasks.
I'm implementing my model based on QAbstractItemModel and I'm using it with QTreeView to display hierachical data. Data are stored in sqlite table.
My question is how should I call beginInsertRows when adding subnodes.
Lets say I have some parent node, it contains 10 subnodes. And I want to add new subnode (at the end).
I'm doing it like this:
beginInsertRows(parentIndex, currentNodesCount, currentNodesCount);
// actual inserting
endInsertRows()
currentNodesCount contains value 10 which is the number of rows in this subnode.
The new node will be placed at the 11th position (10th counting from 0).
Is this logic correct ?
Thanks for help.
I'm wondering also about using beginRemoveRows.
Is this correct:
beginRemoveRows(parentIndex, currentRow, currentRow);
// delete record
endRemoveRows();
currentRow contains position in the list of the removed node counting from 0.
Yes that's it.
Was this your only question?