Qt - Can Several QtableWidgets share linked Items - c++

Qt Several tableWidgets share linked Items
Hi, in Qt I have a QMainWindow -> centralWidget (QWidget) -> QtabWidget -> then 10 Tabs (QWidgets) -> each with up to 26 QtableWidgets:
Sample 1
Sample 2
The idea is that instead of this:
void MainWindow::on_pushButton_Add_Player_clicked()
{
ui->tableWidget_Players->insertRow(ui->tableWidget_Players->rowCount());
ui->tableWidget_Defensive->insertRow(ui->tableWidget_Defensive->rowCount());
.
. [10 tableWidgets in Total]
.
ui->tableWidgetAll->insertRow(ui->tableWidget_Players->rowCount());
}
Is there a way so that I can add a column each time to every tableWidget with less code.
Of course that's not there is to it, in fact I want to know is there is a way to link some of the Items of each that are actually the same Item but it's repeated in each like for example the Player Name is the same per row in each tableWidget, so if the user edits the name in one, it should change it in the same row in every tableWidget.
Is there a way to link them somehow, or the only way it's checking for item changes as signals.
I would also like that if I sort by column in one tableWidget, the new arrangement of the rows should be the same in every tableWidget.
Can anyone point me in the correct direction, the only idea I have it's using signals for ItemChanged. Isn't there a better way?
Thanks a lot for your time.

If your tables are the same data, you should consider getting some nice model view controller action going (also say that phrase a lot when applying for jobs, they like that ;))
To do this you need to create a tablemodel. And a TableView widget. This way, the data is shared, so it exists in only one place. All your TableViews just show the data. You can have a look at QSortedFilterProxy to filter your data for a specific view(i have never used this, so don't know). That way you have your playerModel somewhere, and each view has a proxyModel that only shows for instance the active players.

Related

Can i change an item in a list from another list?

I´ve created a list in SharePoint. What i´ll like to do is create another list, and retrieve some information from one list to my new one, and be able to change the input data from list A in a single line of text.
So lets say, list A is PopStar, with columns like Genre "Rock", HairColor "Red" and GrammyCount "2".
In list B i only want textboxes to show whats in list A and be able to change (update) them, for example Genre to "Pop", HairColor to "Black" and GrammyCont to "8" ?
Is this possible?
i´m using office 365
In order to achieve exactly what you want you will require either a Workflow or an Event Receiver, however I assume you won't feel confident by struggling with such approaches, furthermore, there are some workarounds that could be very close to your requirement and maybe are even better solutions than the approach you suggest, in terms of maintenance, growth and upgrade.
I suggest to review topics like "SharePoint parent/child list webparts connections" or "sharepoint edit form add child items", here are two videos of which you can get some ideas.
https://www.youtube.com/watch?v=9PWIxk6rF-A
https://www.youtube.com/watch?v=-5CdjfLONgE
Take in count that you can do more than what is displayed in the videos, by example in the Edit Form you could add a webpart to display the Quick Edit View (Grid View) of the related list so the values can be edited in the same Form and thus removing the need to navigate to a second window.

QListWidget performance with many custom items

I have a list with about 2500 custom items. I set them with:
const std::vector<const Items::AbstractItem *> results = _engine.request(text);
if (!results.empty())
{
for (auto i : results){
QListWidgetItem *lwi = new QListWidgetItem;
_results->addItem(lwi);
ListItemWidget *w = new ListItemWidget;
w->setName(i->name());
w->setTooltip(i->path());
_results->setItemWidget(lwi, w);
}
_results->setFixedHeight(std::min(5,_results->count()) * 48); // TODO
_results->show();
}
This takes about 5 seconds on an i5-4590. Hiding the widget is twice as fast. Is this normal or do I have look for errors?
A few ideas:
Try assigning proper parents to your QWidgets, thats way the layout doesn't have to do this
mapping for you. This should help performance.
Call setUpdatesEnable(false) before starting the insert, and to true after it's done
As for hiding the widget while adding large amounts of items, this will help to alleviate extraneous update calls. The second suggestion above should mitigate that.
I think this is fully expected behavior for controls like Lists or Trees that are not based on any data model. And I believe that the data model was invented mainly to fix this issue.
In your situation you have a ListWidget control that stores its data on its own. You need to pass all 2500 items before your app can go on, and you need to do this even if your list shows only 10 items at a time. Even if you just run and close your app, the user won't see all the items but you still need to pass them to your ListWidget. Some GUI frameworks use internal allocation of items and in such case they can optimize things a bit, you could do the same if you allocated your Items in chunks but it's still not a good solution.
Now let's say you introduce some object that could be asked about item properties. The Control will ask about some item and your object will respond with the contents. Your object don't even need to know about all your items, it will just learn when needed.
You Control can ask about few first items and stop when it realize it can fill up its entire height. This way you can avoid work that is not needed for now. The Control can also ask about the item count, so it can set-up its vertical slider.
It needs to be said that the model will not solve your problem automatically, it's just a programming paradigm that allows you to do it better.
So the solution for you would be to replace your QListWidget with a QListView and implement you own data model inheriting QAbstractListModel. You could pass the results to the model and it will pass the items data when needed.
If your QListWidgetItem's always has fixed size, call setUniformItemSizes on your QListWidget, pass true.

Kendo datasource and templates, specifically for Scheduler widget

I've noticed that the scheduler widget does things a bit differently from other widgets. In fact, I read in the documentation that the DS is a different one:
"http://docs.kendoui.com/api/framework/schedulerdatasource"
Anyways, on to my two questions.
when i was doing a template for the day cells, i noticed that if i used value called 'date' it would automatically use the correct date value for that day cell. But i never created this date variable, not did i include it in my datasource. So where did it come from? if its provided through framework, what other values similar to this one are available to me? where can i find some documentation on this?
For kendo widgets, when you apply a datasource and a template, it automatically maps each datasource item to one item in the widget (e.g. one row in the grid, one item in the list view etc.). its a one to one correlation. But this is not the case for the scheduler datasource since, like i stated above, it is a different type of datasource (its a schedulerdatasource). The scheduler datasource mandates that each item in the datasource have a start date and an end date so it can map it to the corresponding cell. hence, this destroys the one-to-one relationship of datasource item to day [template]. How can i revert to the behavior of the datasource with other widgets? do i have to somehow configure it to overwrite the schedulerdatasource to the original datasource? i want to preserve the correlation behavior of 1-to-1 between my datasource and my day template.
just to give a generic example of what i am trying to accomplish with this, imagine that instead of doing entrys with time slots, i want to instead have my scheduler display daily summaries of how many hours i worked out, how many calories i ate, amount of hours i slept etc. But i do not want to associate those amounts with hours in the day.
--
Sorry that was technically more than two questions.
But thanks in advance!
-B
Straight to your questions:
The options available in the eventTemplate are listed in the documentation.
The SchedulerDataSource does one thing more than the regular DataSource - it expands recurring events. This means that for one event which says repeats two days the SchedulerDataSource creates two data items - one for each day. If you don't have any recurring events then you would have the one-to-one mapping. The scheduler can only be bound to a SchedulerDataSource instance (it will throw an exception otherwise).
It looks that the scheduler may not be the widget you are looking for. If you just want to display a list of items the ListView or Grid widgets may be a better fit.

QTableWidget - combobox delegate how do I allow different options per cell

Aloha
I have a QTableWidget with two columns that are currently using a ComboboxDelegate (my subclass of QItemDelegate) to present options to the user. I'd like the choice in the first column to effect the options available in the second, for the current row only.
E.g have a list of cars in the first column, and in the second a list of colours which are available for that car. Other rows to have different cars selected and thus different colour choices available.
From what I can see, I can only set an item delegate per row or column, so I can't see how to change the options in the second column's delegate without affecting all the other rows.
Is this possible? I'd really like to avoid going to a full view/model separation as I have quite a bit of code looking at this QTableWidget already (and I'm under time pressure)
Well for those interested; I went back to my pre-delegate approach, which was to use QTableWidget::setItemWidget() to provide a combobox widget for each cell.
I subclassed qcombobox to take a reference to the table, and connected the combobox CurrentIndexChanged with a slot to update the table data.
(setting a widget in a cell does not affect the tablewidget data unless you do this).
Using a full combobox like this is more expensive than an itemdelegate, but my tables are very small so I can get away with it. The rendering of the combobox is not as nice as the delegate (the combobox is visible all the time instead of only during editing in the delegate's case), but with time I'm sure I can improve on this.

User interface for reordering a list items

I have a list of items as a part of a web application. The question is how user can manipulate the order of items in the list (not the list sort order). The typical way is to use arrow buttons to move items up or down. The other way is the drag-and-drop.
But are there any other ways for a user interface for list reordering?
There are two other sorting methods (besides those you mentioned) I've seen which work pretty well.
Click To Move
The method used for ordering items in the Gallery web photo album works pretty well for ordering photos, and it should work just as well for any set that can be represented as a sorted group of clickable elements:
Present your list of items as clickable elements.
Clicking an element "selects" it, it is highlighted to indicate it's selected.
Clicking another item moves the selected item to a position just before the clicked item.
Repeat until all items are in the desired order.
A dummy item is shown at the end of the list for moving items to the end.
This is slightly easier to use than drag-n-drop as it requires less dexterity, and you don't have to hold down the mouse button while you figure out where you want to "drop" the item.
The method could easily be extended to allow selection of multiple items (via shift-click or similar) which could then be placed in a new position in the same way.
Provide Order Numbers
Used by Netflix and some internal apps I've worked with. This works best if your users have a concrete idea of exactly what the numeric order should be (used when working with lists of instruction steps in our internal app).
Present your list of items one per line.
Provide a text entry box next to each item where the order number is displayed, starting with 1.
The user changes the order numbers in the text fields as desired.
If multiple items are given the same order number, they are placed next to each other.
Provide a button to "apply" the sort in JavaScript so that the user doesn't have to submit the entire page to see the re-arranged list. This makes it easy to work in increments.
Edit: A couple of additional thoughts on Drag-and-Drop. You might have used these before or not, but there are a few things that can make drag-and-drop more forgiving and easier to use:
Highlight the area where the item will appear when dropped. For example, show a prominent horizontal line between the two existing items where the item will be inserted if it is dropped.
Ghost the draggable item as it is dragged so that it's obvious what's being moved, rather than using a generic "dragging" cursor. This works best if the items being dragged are still legible if shown on top of one another with transparency.
Make sure the target areas where the draggable can be dropped are sufficiently large. Larger areas can be helpful for people who have trouble with the required coordination.
We've found that drag and drop can be counter intuitive for non-technical people. We have explored the Up Down Arrow which works but can also be cumbersome as you need to keep clicking up and down and it results in a lot of traffic.
Another paradigm we've explored is the Move button so each item in a list has a Move Item button when you click it new buttons are added before and after each item in the list to let you move the item to any location.
This works well when each item in the list takes a lot of space, if each list item is only a single row it can result in a cluttered interface. In our case each item was half a dozen lines of text or more. We also have add item here button before / after each item to allow insertion.
Survey Monkey uses this paradigm as well and inspired some of what we do.
Some thoughts - Very much on the ideas rather than implementation end though...
1 - Provide both up and down arrows and drag and drop, and monitor which is more popular, which type of users use which etc, then tailor from there once you have some data
2 - Add a "random" button which generates the order randomly - could be useless, could be fun depending on your app
3 - Add a "display order" field by the side of each item and allow the user to manipulate it (but make sure that you have some code to auto update the rest of the numbers when one changes) personally I think this could be very confusing, but for some users it might work
4 - Instead of drag and drop in place, have users drag to a new list
5 - For a very simple version, have a "favourite" check box, and then have the list just show the favourites first, (in alphabetical order or something)
6 - Have groups - you assign a group number to an item, all the group ones appear first, followed by group 2 etc
Hope this random rambling has been useful, if i think of anything more I'll come back...
1) A variation of Click to Move would involve having a separate target list, where the user selects the slot into which their item will move, then clicks on the original item to move it.
For example, in the following diagram, the user has already put 'E' at the head of the reordered list and has selected slot three for their next choice. Their next step would be to choose which item from the old list goes into slot three on the new list. (The row of asterisks is a feeble attempt to show that slot three is highlighted or selected.)
old new
----- -----
| A | | E |
| D | | |
| C | |*****|
| | | |
| B | | |
----- -----
Clicking on an item in the new list selects it and highlights its original slot in the old list, which is now a target. Clicking on the item a second time returns it to that original slot.
The new list should also display indicators of some sort to show that it has selectable regions, perhaps unobtrusive (low-opacity) numbered buttons in its slots or some other informative affordance.
2) Another approach would be to allow users to draw lines between the original and desired positions.
Whatever method is chosen, the process need not be chatty: there's no reason this couldn't all be done client side (with the option to save and commit changes to the server).
You can experiment with drag-and-drop using the examples of jQuery UI Sortables.
To make it obvious for the non-technical or new users you could use visual cues such as handles or arrows and maybe a tooltip on hover to suggest dragging the element.
You could even provide an animated gif demonstrating the gesture.
As soon as a user learns how to do this I think it's the easiest method of ordering a list.
Another way is to provide a small text input next to every item, so the user can enter a numerical ordering themselves; then they click a button to reorder it all at once. (I've only seen this used on sites that store the order of items, such as Netflix queue or Livejournal links.)
Sorting, by clicking on headers is very popular. Perhaps only considered as a reordering of the view of the actual list, though.
Implement a copy/paste style function? This would mean you can take an item out of the list, and then select another item, and click "paste" or CTRL+V. This is quite intuitive and would allow large lists to be manipulated easily.
You could implement multi-selection easily to move a large block of adjacent items.
Network traffic would be low (only one or two requests).
You need to make sure the "paste" is consistent. I.e. pasting always inserts above the selected item.
Take a look at Checkvist for more inspiration.
You could also use arrow keys to move up and down.
I actually think the iphone / itouch does this really well when moving application icons.
If you haven't seen it look here: http://www.youtube.com/watch?v=qnXoGnUU6uI
The 'shaking' icons are a very good visual cue that something is moveable/draggable.
So I would suggest this approach with drag an drop. Clicking and holding on an item could put it in 'moveable-mode' and this would be indicated by it shaking (or some easier to code visual cue). Then drag and drop would work in the normal way.
Implementing this in javascript is of course the challenge...
Also another thing to think about - most people make the mistake of conflating usability with learnability. Think who the users of this app are (will they use it regularly and be taught how to use it, or are they public web users who may use it infrequently and not be taught how to use it) - it might give you a different answer to what the solution should be.
To me, performing a drag and drop of list elements in place (i.e. within the list itself) is the best approach.
Not only you can give to your users the immediate idea of what their list will look like (the list is reorganizing before their eyes), but it's also very easy for them to understand the moving mechanism.
And this is the briefest way to have your users ordering the list in the shortest number of moves.
By the way, foreseeing that a list could be longer than few elements, alongside the DnD method you could provide an asynchronous way to order the list: give the user the ability to attribute an ordering number to each entry, and then click on the "Order" button.
Handling in a smart and correct way user's input, this could result in a speed up for longer lists editing.
I was thinking of "Move selected to here":
Let all items be selectable by checkboxes
Let all items have a button or icon meaning "Move selected to here"
When "Move selected to here" is clicked, all selected items are moved to this item in existing order
The edge-cases here are when the items should be moved to either end of the list. One way to solve that, is to move all selected items before the target, and reserve a special button/icon at the end to move the selection there.
I've found the following to be the quickest way to allow specifying item order regardless of list size:
1) If user wants to set the order of list/grid items, they click a "Reorder" button.
2) This opens the reordering dialog which can be used with any list or grid.
3) In the dialog, all of the items are shown in their current order in a list on the left. There is an empty list on the right.
4) The user clicks the items in the left list in the desired order. When an item is clicked, it is removed from the left list and placed in the right list in the next position. In a worst case reordering where every item needs a new order, this allows ordering a list of N items with N clicks.
5) The user can then apply the new order or cancel. Applying the order results in the "display order" field in the data being set to the final order of the items in the right list. You can decide if the "Apply" button is only enabled when the left list is empty.
6) Also available in the ordering dialog are the following controls:
a) A button to move all of the items from the left list to the right list maintaining whatever order they are in
b) A button to start over by reloading the left list in its original order and clearing the right list.
c) A button to sort the right list alphabetically (or by date or numerically depending on what the key field is)
d) Drag and drop capability in the right list to manually drag items into order.
e) An index number column in the right list which, if edited, moves the item to that position.
This provides the best of all worlds. If you have a huge list where only a few items need to be moved, move all items over, then drag the few items where desired or enter the desired index. If you have a small-ish list that needs to be completely reordered, just click the items in the desired order. And so on.
I've used this approach for many years and it has been very effective.
You can show 'Up' and 'Delete' buttons just the way Google does for SearchWiki. Most of the people have at least some experience with it now. Most people bother only with 'Upping' their choice. If they do not like a thing, and want to downvote it, removing from the list with help of the abovementioned 'Delete' button will be easier for them
You could show an overlay when hovering over an element. This overlay shows you 4 arrows (n/e/s/w) and u can click and move the element accordingly.
If you are trying to oder items across a grid like facebook's and picasaweb's photo grouping features, then that is about the only way to handle that
if you had 3 columns each with a list of items, clicking on any of the items would move the item either to the left or right, middle column could show option for left or right. you could still allow for dragging and dropping or sorting using the typical functionality for that.