I write a small database project for handling payroll records. These payroll records will be put into a tableview object for viewing. How can I search a particular record in a TableView ? Any idea, please help me.
If you are using model / view paradigm, you may consider using a "match()" method, located in the QAbstractItemModel class. For example, see this code snippet:
model->match(model->index(0,0),
Qt::DisplayRole,
pattern, -1,
Qt::MatchContains | Qt::MatchRecursive );
This is a code, I use to locate a pattern string in the TreeView. The flags are set to locate those records, that have a "pattern" among their display role representation, the search is performed recursively through the tree (you don't need it in your TableView, I believe :) ).
A Proxy-Model can be plugged between your (source) model and the view(s) to filter the models data. Take a look at QSortFilterProxyModel which allows to sort models rows/columns. Providing it with the right regexp for the key it will match only one item if found. You can use the proxy-model like a usual model (e.g. check rowCount) so it will update automatically and can be used in other views.
Related
I'm stuck on how to approach the design of this problem - or even how to search for answers. I'm still a bit new with Django. The goal is to have a user select one or more locations (libraries in my problem) from a list of locations. I'd like the user to be able to type in an address and then have the list of locations filter based on distance between the locations. I envision the list of locations to be selection field. I'm assuming there will be an input field for the distance (canned choices or just a whole number) and a button to apply the filter.
I know how to get the user's location (as a postal address) converted to lat/long using py-geocoder. I have the lat/long of each library. I know how to calculate the distance between two points (py-haverstine or maybe geometry-distance).
Where this seems squirrely is the mechanics of filtering the list. How would I do the "filter" action (submit) versus the "save" action if I'm using a model based view? So far, when I hit the server, I've been processing the form as a submission, not a portion.
Or would this be better done client-side as js (which I don't know, but I assume someone has done this already)?
In Qt I have a sqlite database which I'm pulling in. One of the tables (configTable) has a QSqlTableModel attached.
The table has a simple 2-column key/value structure. The keys are strings with folder-like values such as "general/name", "general/version", "foo/bar/baz", etc. Values are just arbitrary variants.
I'd like to display this data in an easier-to-browse QTreeView instead of a QTableView, as my key structure lends itself very nicely to that.
Before I go reimplementing classes and all sorts of crazy things - is there an elegant solution to this? And if I reimplement or extend classes, which ones should I look at?
Thank you.
You have to do the parsing+mapping between the list of value/value/value and a tree model yourself. But there is a (tricky) Qt way to do this yes.
The Qt Model-View architecture can represent many different structures of data, based on the QAbstractItemModel class. A Qt model must implement some functions to tell the view : how many columns, row, children etc.
A list model (Qt provides QAbstractListModel), is basically a model that says to the view :
I have one root item (all data items are represented by a QModelIndex, root has an invalid parent)
This root item has only one column
This root item has as many rows as your list has elements
A tree model will return the appropriate children for each QModelIndex. The abstract model of Qt actually allows each child item to be a table (QModelIndex always has a parent and a row-column index).
Long story short, you have to create a proxy model (QAbstractProxyModel or a suitable subclass, but for your need I don't think there is one). This proxy will transform the data your QSqlTableModel is sending, and this is where you can tell the view that you actually have a tree and not a list.
Your root items are the items from your database list of keys (first element of the foo/bar/whatever), but you need to regroup all the root items that has the same key.
AFAIK you can make it only manually.
Basically, because how did you think Qt knows how to convert your data into tree model.
I'm trying to enable content editors to select an item that resides in a bucket in a droplink field but I'm unable to find a field type/datasource that enables this.
I need to allow the user to select a single item (so not a multilist), the items are in a bucket as the number of items may be huge and the search api would be most helpful to the editors.
Is there a field or datasource query that will enable a lookup field to select a single bucketed item?
The simplest solution is to use a Sitecore multilist with search field.
First you need to set the source of your field to display items within your bucket of a specific template(s).
Example: StartSearchLocation={11111111-1111-1111-1111-111111111111}&Filter=+_templatename:sample item
Here is an article describing how to set the source of your field: Sitecore 7 field types
If you need to limit the selection to one item then you need to also apply some regex. To achieve this you need to enable standards values in the view tab so you can alter the data section.
In the data section add the following regex: ^({[^}]+}\|?){0,1}$ and add some validation text.
Example:
This article provides additional infromation:Limit selected items on Sitecore multilist field
Just in case anyone else comes across this as I did, you can also use a query in the source field to filter the items in a droplink.
query:/sitecore/content/Home/YourBucket//*[##templateid='{your-template-guid}']
You can also use ##templatename='Your Template Name'
Keep in mind that unless your bucketed items aren't numerous (for some reason), the suggested answer is probably better since it provides search, and will not create a massive dropdown list of items.
I made some custom fields for this very purpose: https://github.com/Barsonax/SitecoreSearchFields
It gives you the same rich search interface you normally get when searching in buckets.
I currently have a search button and I would like to search a specific column of my model.Thus I just want the matching rows to be displayed in my tableview.
I have attached a QSortFilterProxyModel* object as a source to the table view and have set a QStandardItemModel* as its source. Then with my search button I made the following connection
QObject::connect(ui.lineEditSearch,SIGNAL(textChanged(QString)),proxyModelFilter,SLOT(setFilterFixedString(QString)));
Now I was under the impression that upon typing the relevant rows will be returned. Then I realized that I havent specified as to which columns I want the filter proxy model to search.
I understand that I could implement a class that inherits from QSortFilterProxyModel and re implement its filterAcceptsRow. I wanted to know if there was a way for me to avoid creating a class that inherits from QSortFilterProxyModel and simply use the QSortFilterProxyModel class only to tell which columns to search on when the Slot setFilterFixedString is called ?
The column to filter by can be set via QSortFilterProxyModel::filterKeyColumn.
It allows to specify a single column, or all of them (-1, the default).
Alternatively, one can define a custom filter role returning a concatenation of all string to search for, and set it via setFilterRole().
Is it possible to choose only specific items from the list in selectOneMenu?
For example. I have List Products has many fields like name, id etc. One of it is category (1,2 or 3) I want to have only one category in the selectOneMenu without making new Lists and new classes. Can you help me?
I think the easiest way is to set the value attribute of f:selectItems to a method which filters your original collection.
Otherwise you'd have to implement your own version of f:selectItems which allows filtering - as we once did in one of our projects.