Populating ListBox from C++ using Grid - c++

In specific, how do you take elements/models that are added to an XRObservableCollection and use them to generate rows/columns in XAML listbox?
I have tried to do this on my own, but my listbox remains empty, despite having elements added to my collection.
Note: This menu is being designed for a Windows Embedded Compact 7 device using VS2008 and Silverlight for Windows Embedded, so many features available in WPF do not apply to this environment.
What i have done is initialize the model of the element i want to display in the listbox as follows:
DispCh->Initialize(ChannelNum,ChannelName,InputType,DispRange_Low,DispRange_High,MovingAvgFilter,EngUnit);
By substituting values in for those variables, you are defining what to display in each column of the listbox (implying that 1 row of the listbox will contain 6 columns; display range high and low are in 1 column).
Now i add this model of my element to the collection as follows:
pMainPage->m_pDispChModelCollection->Add(DispCh);
This works fine as when i check the collection count after adding, it increases.
Now, i believe that i have done the binding correctly to take the collection and convert it into the listbox. To do this, i do the following:
XRValue value;
value.vType = VTYPE_PROPERTYBAG;
value.pPropertyBagVal = m_pDispCh_Model;
m_pReviewModeDispCh->m_pReviewMode_ChList->SetDataContext(&value);
m_pDispCh_Model->Set_ChannelCollection(m_pDispChModelCollection);
where m_pDispCh_Model is the model class that contains all the xaml initialization and binding, m_pReviewModeDispCh is the class definition for the XAML menu, m_pReviewMode_ChList is the IXRPtr to the XAML listbox, and Set_ChannelCollection takes m_pDispChModelCollection and passes it to m_pRevChList which is the following:
TBoundPointerProperty<IXREnumerable> m_pRevChList;
hResult = RegisterBoundProperty(L"ReviewModeDispChList", m_pRevChList);
Now, i could post the code that shows what i did for the xaml menu, the c++ code for defining the xaml class, the c++ class for the element model, and the c++ code where i use these class methods, but it wouldnt follow the MVCE, so instead, i'd like to see if the idea behind steps i am doing are correct as far as the code i have provided or at the very least if someone could point me in the right direction regarding generating listbox grids from C++ code.

Related

WXWidgets TextCtrl or RichTextCtrl

I'm using wxWidgets for a log window of a piece of software which runs for many hours. The log can accumulate 10,000's of entries. Does the community have a suggestion for how not to have the GUI thread choke for many seconds when updating a textctrl or richtextctrl with this many lines? I'm open to using either control type but richtext is preferable to I can highlight warnings or errors.
It's currently set to readonly, so undo, redo, paste, etc are not active. I'm currently freezing and thawing it before and after adding content.
In a test case, I add 10000 lines to the text control with a freeze and thaw before and after. This operation still takes over a minute. Are these text controls simply incapable of handling long content?
Assuming your display is like a log, where each "line" is it's own entry, try using the wxListCtrl in "virtual mode". Basically, you maintain the data in your own control (a vector, array, whatever works) and the control asks you for only the data that is currently visible.
Inherit wxListCtrl with your own class and implement OnGetItem. When a row is visible, your derived control will have this method called for each row (and each column if you implement multiple columns) and you provide it with the data for that row, accessed directly from your array (list, vector, whatever).
More information is available in the wxWidgets docs here: http://docs.wxwidgets.org/3.0/classwx_list_ctrl.html#a92370967f97215e6068326645ee76624
The suggestion to use wxListCtrl in #avariant answer is a good one, however a wxTextCtrl with wxTE_RICH style should still be capable of appending 10000 lines in well less than a minute if you freeze/thaw it before/after. I'd be curious to know if you can reproduce the problem in the text sample included with wxWidgets (which already has a menu item doing something like this) and, if so, which wxWidgets port do you use.

Hierarchical Listview QML

I want to display hierarchical Data with a QML-Listview. This means that I have different Cpp datamodels, that have the following structure:
Section 1
Subsection 1
Item
Item
Subsection 2
Item
Section 2
The number of subsections is different in every model, so that I'm looking for a general solution to display that data in a flat list like that:
Section 1
Subsection 1
Item
Item
...
I'm using Qt 4.8.2 with Qt Quick 1.1.
What I figured out till now:
The QML ListView cannot display hierarchical listmodels
There are different solutions to display tree-structured extendable lists with multiple Listviews, but that's too complex for my models
I can make my model flat by using a Abstract-Class insert different Object types in a flat list, but that would be a lot of work, cause I had to insert lots of loops
Till now I found one solution provided by blackberry cascades, but I can't use it because I have to run my application on Embedded Linux:
Cascades Vegetables Data Model
At this moment I'm thinking about to write my own ListView with Cpp, but I would really like to avoid that because It will be a lot of work to implement that.
I'm new here at stackoverflow, so please let me know if I have to give you more informations.
Thank's in advance.
Quperman
EDIT 05.08.2014:
Temporary Solution:
Since It seems to be hard work for me to implement my own Cpp TreeView, I found another easier solution:
I created an abstract class AbstractItem with an attribute ItemType (enum), that has the following values:
Item
Section
Subsection
...
What I now do is the following:
I inherit my Section and Item classes from my new class AbstractItem. Now I put QList into my QAbstractListModel and appended the items, sections, subsections...
I can now provide different data in header and item by implementing the data() function with a switch over ItemType. depending on the ItemType I can do a reinterpret_cast to access the data.
Now I have a flat hierarchy that works for me. Sadly I can't use the class hierarchy, but at this moment it seems to be the fastest solution.
15th May 2015 We got beta version of Qt 5.5. See its features. Take a deep breath... Now you can use TreeView component in QML!
Take a look at snapshot for Qt 5.5 documentation.

cpp graphical menu

I am making a new graphical menu interface for a project I am making. I don't want to use the menu system provided by windows APIs and want to make one from scratch.
My question is, what is the best method for setting up the structure?
I'm thinking I will need a menu item object, each of which will have to have their own item array list, etc...
Is it considered sloppy to have recursive coding like that? (Ie an object which contains objects of itself, which contains objects of itself, etc...)
I'm thinking I can give the item object a draw interface which checks itself to see if it has an item array that is not null. If it does, it executes the draw command all the way down, thereby giving me a menu with (for my purposes) unlimited submenu level
In my opinion your approach is fine. In nearly all UI frameworks, views contain views as subviews after all.
But the thing is that writing drawing code is too much work for small projects I think. I would consider using a UI framework such as QT and use its view mechanism as a starting point. You can write your own Menu class which will be a subclass of generic View class in the framework.

How can I visually design a component in C++ Builder?

I have been away from C++ for a couple of years now doing AS3/Flex work. I have gotten used to being able to create a component and place it in design mode with very little fuss and I am struggling to get my head around the C++ Builder way of doing the same thing.
I have written many components for C++ Builder in the past, but none of them have been visual. What I would like to do now is create a component for customer search and another for order processing because I want to be able to create a new instance of these on the fly. What I don't want to do is have to place each of the components like the dbgrid and search fields manually in code. I would like to do this (as well as set their properties) in design mode.
How do I go about this? I have browsed the source for other Delphi components and I notice they have dfm files which seems to be what I need. How do I do this in C++ Builder? The only option I see is to add a new form if I want a dfm, but this isn't what I want as my components will be based on TPanel.
Is there a way to do this or do I have to resort to doing it all in code with no visual reference?
Pursuing the DFM idea I did a test this morning where I created a component based on TPanel and added a new form to it which I create and parent in the constructor of the component. In design mode I set the form border to none and placed a grid on it. This all looks OK until I place the component in my application, at that point it looks like a panel with a standard looking form in it and the grid is missing. If I run the app the panel shows as expected, borderless and with a grid. The DFM appears to be ignored in design mode for some reason.
If you know a better way to do this than using components then please give me some pointers.
Any help and advice will be appreciated beyond words
You might want to have a look at frames (look for "Frame objects"). They are "subforms" you can design visually and then place on forms.
Just as an FYI item, you can also drop the panel on a form, put any other controls on it, position them, set captions, etc..
Now, click the panel to select it, and use Component->Create Component Template from the IDE's main menu. This creates a unit you can install as a component which will add the panel and it's sub-controls (as a single component) to the IDE's component palette.
Of course, you can then modify the source for that new component like any other component source.

Does MFC have a built in grid control?

First what I want: The ability to display a grid with multiple columns, each cell having a custom render callback. So you might use such a control to display your inventory in a game, or something like the behaviour in Google Chrome where it shows a grid of popular pages you visit.
I've been playing with CListCtrl and while I can get custom rendering ability on each item, I can't get it work with columns - having say 3 items per row. The control has column-related methods but I think these are specifically for the built-in functionality where different attributes of an item are shown automatically in each column... not for providing a generic grid control.
So, does such functionality exist in MFC? If not then I wonder if the easiest approach is for me to actually insert each of the rows as an Item... and then the custom rendering draws the multiple cells in the row, I could also do custom UI to support clicking on the cells.
But what I really want is to be able to create a custom control, and add this as an item to a list - like in Flex for instance - so I/O etc is automatically handled.
Any advice/information welcome...
Dundas has thrown some of its (excellent) components in the public domain. Their Ultimate Grid is available on CodeProject.
I'm not aware of a built-in control, but I think you should take a look at this.
The article is describing in detail the functionality of a fully featured MFC grid control, derived from CWnd, for displaying tabular data.
YOUR_LIST_CONTROL.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_INFOTIP|LVS_EX_GRIDLINES);
I think it will help you (SetExtendedStyle).
I suggest this one:
https://code.google.com/p/cgridlistctrlex/
very complete