Stack of views or generate on need? - performance

Let's suppose, I'm creating a image editor, something like Photoshop, but simplier in Qt.
I got next problem - I have list of items and I can select only one of them at a time. Each item got QWidget which should be shown in MainWindow. The question is - should I create them(widgets) when I select item or should I just manage visibility of this widgets. Currently, I got the second solution - when item selected, I set the visibility of QWidget to true, and hide current widget. What is better in case of performance? I'm new to Qt, don't which practice is better to use in such case.
For better understanding - attaching a picture with sidebar and place for QWidget(blurred woman)
Disclaimer: It's not a opinion question - I'm asking about best practice in Qt and performance in each case. Thanks.

Here is an example using QListWidget and QListWidgetItem controlling the QStackedWidget:
// Stacked widget
QStackedWidget *pStackedWidget = new QStackedWidget();
// Creating widget list
QListWidget *pListWidget = new QListWidget();
connect(pListWidget, &QListWidget::itemSelectionChanged,
[pStackedWidget, pListWidget]() {
pStackedWidget->setCurrentIndex(
pListWidget->currentItem()->data(Qt::UserRole)
);
}
);
// Populating widget list with items
QListWidgetItem *pItem = new QListWidgetItem();
pListWidget->addItem(pItem);
pItem->setItemWidget(pItem, pWidget);
pItem->setData(Qt::UserRole, 0 /* widget index on stacked layout */);
Visibility of the widgets on the right is controlled by the QStackedWidget. Corresponding widget index is set upon selection change in the QListWidget.
Widget index can be stored in custom user data assigned to corresponding QListWidgetItem.

Related

Xamarin Forms - Slide out menu to select items

I have a xamarin forms application search screen that allows a user to select an item from a list. Currently I am using a picklist and the user has to scroll and select and click done. This is using the native controls. Howerver I have noticed in iOS in settings menu etc where the have designed it so that when a user want to select from a list a arrow is shown on the right hand side which takes them to another page to select an item (s) from a list. To me this seems like a better UX. Here is an ex:
My question is there something built into this withing xamarin forms? I guess I could create a listview and then on click pass to another page. Any examples are appreciated.
There is no built-in for that, but it's not too hard to achieve this.
To set the disclosure indicator (the arrow), implement a custom renderer derived from ImageCellRenderer and override GetCell
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
{
var viewCell = base.GetCell(item, reusableCell, tv);
viewCell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
return viewCell;
}
When the user taps that cell you should navigate modally to the view showing the list of languages.
Adding that Cancel-Button is not really hard either, but needs another step. You'll need to wrap the new language selection page in a NavigationPage and push that NavigationPage modally. Furthermore you'll have to add a toolbar item to the wrapped page (see here).
Within the page there is a SearchBar view and a ListView below it. To add the checkmarks, you'll have to implement a custom cell with a custom renderer (derived from ImageCellRenderer like the one shown above), setting the UITableViewCell.Accessory to Checkmark if the custom cell is selected
if(item is SelectableCell selectableCell)
{
var selected = selectableCell.IsSelected;
viewCell.Accessory = selected ? UITableViewCellAccessory.Checkmark : UITableViewCellAccessory.Checkmark;
}
Please note: Selectable cell is no Xamarin.Forms stock cell, but one that you have to implement by yourself, including the bindable property IsSelected.
This should be basically the steps you need to achieve what you want. I've assumed basic Xamarin.Forms knowledge that is needed to fill the gaps.

highcharts - onclick event handlers redraw/remove

Currently I have 4 charts. The selection (via column or legend) of a category from the main one triggers multiple events. It changes the selected item's color on two charts and it creates two more charts.
For the two created charts, I'm having problems with redrawing/removing (that is what I'm assuming I will have to do) when the column/legend is deselected.
I may be wrong but from what I've looked at, it seems that when you prevent show/hide it doesn't change the visibility property so I wasn't sure if there was a way to use that.
Any help would be appreciated!
Fiddle here: http://jsfiddle.net/jlm578/gy9og69r/4/
I also thought about whether I needed to add it into the logic of the function (possibly one below) or if the sibling aspect needed to be added to the others.
function drawSignifNonSignifEruptionsChart(series){
if (series.index == '0'){
var eruptVEI = ['VEI 0'];
var signifErupt = [10];
var nonSignifErupt = [600];
}

Selecting NSCollectionView Item

I need to create a photo gallery and each individual photo when selected will have some options to edit. For this am using NSCollectionView to set up the grid layout. I followed this guide and the basic grid layout is setup.
Now I need to enable selection of these images. So that when I click on them it gets a check mark, and later I need to enable batch processing of these images(copy/delete ...).
I am stuck here, and couldnt get any info on how to handle selection and later get the selected items from the grid ?

Backbone.Marionette Layouts, regions and views

In may Marionette app I do have set a layout with 3 regions
headerRegion
mainRegion
footerRegion
I am using the footer region to display detail views of my models (itemViews).
Now I do have the situation, that I want to use this region with collectionView in combination with a button-group: Add-Button (adds a model/itemView) and a OK-Button (closes/hides the collectionView and the button-group. I would like to handle these 2 itemViews as a component, showing and hiding them in 1 step.
I am not sure what the right way to do this is.
Option1:
show collection view in subregion1 of footerRegion and the button-group in subregion2 of footerRegion
Option2:
create a new Layout and nest it
Option3:
do it somehow with a compositeView?
Option4:
some combination with jquery hide/show the button-group?
My vote is for Option #2: nested layout. I do this a lot and it works very well. It's easy to manage and easy to work with, IMO.

Treeview - highlighting multiple items

In Powerbuilder, Does anyone here know how am i going to highlights multiple items on a treeview? Selecteditem function is not doing that. Im looking for a behavior just what Selectedrow id doing.
Thanks!
I've not tried this myself but there is an example on CodeXchange (look for Multi-select TreeView Control).
I think the treeview style datawindow might be easier to do this with.
If not, I found this on the newsgroup, don't know if it helps:
The following script in the
selectionchanged event will implement
a very basic multiselect in the
treeview:
treeviewitem ltvi_item
if KeyDown(KeyControl!) then
This.GetItem(oldhandle, ltvi_Item)
ltvi_Item.Selected = True
This.SetItem(oldhandle, ltvi_Item)
end if
A problem is deselecting the
previously selected items. You would
have to scan through ALL items do look
for the selected ones (once the user
clicks an item without holding down
the control key)
https://groups.google.com/forum/#!msg/powersoft.public.powerbuilder.objects/B2ulHBrSnrs/itwhNBjlyOoJ
One approach to this is to use the CheckBoxes attribute on the treeview, then check the treeviewitem's StatePicture (Unchecked = 1, Checked = 2).
Good luck,
Terry.

Resources