PDA

View Full Version : Split pane view with different headers.



yannickt
6th August 2008, 20:59
Hello,

I am facing the same problem discussed in a previous thread (http://www.qtcentre.org/forum/f-qt-programming-2/t-tableview-model-view-problem-10574.html) but the thread is quote old so I figured I would start a new discussion. Basically I want to use two table views in a split pane view, with the bottom table showing children of the item selected in the upper one. I would prefer to use the same model in both tables, however the tables need different headers. I am trying to implement a hierarchical model as suggested by wysota in the other thread:


So you could say that the bottom table show "children" of the item selected in the upper table?

If so, then why not make a proper hierarchical model with parents and children. Then populating the bottom table would be as simple as setting the root index to the index of the item selected in the upper table.

Regardless of your decision, the headers could be changed by using a proxy model over the sqlquery (or your custom) model.

This makes sense, however I don't know how to go about mapping to and from the source index in the proxy model, and how the source index relates to the root index that would be set in the bottom table on a new item selection in the upper table.

Any help would be appreciated.

yannickt
7th August 2008, 19:46
To clarify, I have the following structures.


struct Order
{
int quantity;
double price;
QString currency;
};

struct Account
{
QString accountId;
QString holderName;
QString holderAddress;
OrderList orders;
};


I want to display the account details in a split pane view where the upper table would show account details such as id, name, address, etc. and the bottom table would show the list of orders. The tables would have different headers, and I would like to set them up from the same item model.

chocolate
3rd February 2009, 22:56
Does anyone have an answer to this? Specifically how to provide the different headers for the different views of a single model.

Thanks.

wysota
3rd February 2009, 23:18
Use a proxy model where you will reimplement headerData() to return new column descriptions.

chocolate
5th February 2009, 22:27
Thanks for the response.

I tried to implement a QSortFilterProxyModel on the tree view/model and it seg faults. I just implemented the lessThan and the filterAcceptsRow returning true in each to allow everything to display at first.

I also implemented a proxy model based on QAbstractProxyModel and it does not display anything in my view, so I'm not sure that I implemented it correctly, but it doesn't seg fault.

Just using the model itself with the view works fine.

Any ideas about what I could look at or does anyone have any good examples of a tree model/proxy/view...more than the simple ones that are available?

Any help is appreciated. :confused:


I was able to see this error:

signal SEGV (no mapping at the fault address) in QSortFilterProxyModel Private::proxy_to_source at 0xfe8a7180

wysota
5th February 2009, 23:42
Can we see the code?

caduel
6th February 2009, 07:16
Wild guesses:
i) are you sure there is a (valid!) model inside your proxy model?
ii) maybe you have some signals attached to the QTreeView that now no longer contain QModelIndexes of "your" model but of the proxy?

chocolate
9th February 2009, 15:56
I figured out my problem. In my QSortFilterProxyModel, I had to reimplement all the public methods from my model.

One other question, do I need to reimplement the mapToSource and mapFromSource in my QSortFilterProxyModel or will the base methods work?

I ask because I have not reimplemented them and when I set a certain location to expand in the tree view, it is expanding the wrong location in the view, so it's like it's getting the wrong indices for the items.

chocolate
16th February 2009, 18:54
Okay, any help from anyone will be much appreciated. I've worked through any of the above problems that I had.

I have a model, a tree proxy model and a table proxy model and two views a tree view and a table view. The Proxy's are based on QSortFilterProxy. The treeview gets the data and displays it (filtered to be only folders). The table view is supposed to only display the data matching it's set parent, for example a users home directory. The treeview/proxy model works fine.

The problem is that the table view/proxy does not recieve data from the model. If I connect a signal/SLOT on rowsInserted, then I can see that the filter sees the top level data, but does not display anything. In addition, the table proxy model's data method is never called.

Here are some snippets.
class MyDataModel : QAbstractItemModel
class MyTreeProxyModel : QSortFilterProxyModel
class MyTableProxyModel : QSortFilterProxyModel

QTreeView *myTreeView;
QTableView *myTableView;

In Mainwindow::Mainwindow()

MyDataModel *dataModel = new MyDataModel();
// Sets the root directory to display
dataModel->setRoot("/");
MyTreeProxyModel *treeProxy = new MyTreeProxyModel();
MyTableProxyModel *tableProxy = new MyTableProxyModel();

treeProxy->setSourceModel(dataModel);
tableProxy->setSourceModel(dataModel);

// Sets the directory on which to filter..
tableProxy->setParent("/home/user1");

myTreeView = new QTreeView();
myTreeView->setModel(treeProxy);

myTableView = new QTableView();
myTableView->setModel(tableProxy);

QSplitter* splitter = new QSplitter(this);
splitter->addWidget(myTreeView);
splitter->addWidget(myTableView);
setCentralWidget(splitter);

//This starts the process, i.e. the tree view recieves and displays data
setRootPath("/home/user1");
---------------------------------------

What I need to do is display a list of folders on one side in a tree and in the other side in tabular form, information about the children of a selected folder. You can think of windows explorer in how it's supposed to behave.

Example data:
FOLDERS----------------------------------------- NAME INFO1 INFO2 INFO3

/folder1------------------------------------------- file1 info1 info2 info3
/folder2------------------------------------------- file2 info1 info2 info3
+/home/user1
/file1
/file2
/folder3
.
.
.

I appreciate any help in advance.

chocolate
17th February 2009, 14:22
Has anyone seen this or have any ideas? I really need to get this working.

wysota
17th February 2009, 14:36
Did you remember to emit appropriate signals from the proxy when "things happen" in the base model?

chocolate
17th February 2009, 15:56
Yes, I do emit the signal and see that it is emited and received.

I can also see the data going through the filter, but the tableProxy's data method is never called. The treeproxy's data method is called (although it's just a pass through to the underlying model).