Unlimited number of checkboxes - c++

I wonder how to create mechanism which create new checkbox below previous when you click on button. Number of checkboxes are unlimited.
I don't think that table of objects work well, so I think about implementation in list of objects.
Any suggestions?

Here is what I would do:
Create an event for clicking that button (let's call it OnBtnClick)
Use a vector/list to hold all the checkboxes
When OnBtnClick is called you do:
create a checkbox with the desired position and size and make sure it receives an unique id (this will help you differentiate between checkboxes when they are clicked/checked/etc).
add the checkbox to the list (to get its status: checked or not checked)
add the checkbox to the desired window, the parent window (though this may happen automatically when you create it)
if you want to add an event for the added checkbox you should check the manual of your GUI framework (you will probably use the same event handler for all checkboxes and treat them separately based on their id)
Depending on the GUI framework used the bottom details may vary but the idea remains the same. I did this with wxWidgets, QT and MFC but I don't know which framework you use. You should be able to find code samples for each framework.

What would you do with unlimited number of check boxes - confuse the user? So, that he/she wouldn't attempt to use it again? Bad idea, as you can guess now.
You may (should) limit the number of check boxes (or better, limit the number of controls on form/dialog). IMO, more than 10-12 CBs would be cumbersome for the end user. Therefore, better idea is to have all of them on dialog/dialog-resource, and make all of them invisible/disabled. When user does some action, make them visible/enabled - so that end user may do something with it.
Still demand N number of CBs, where N is not determined beforehand? Then you may have checkboxes under Combo box, or use check-boxes under List Control. List Control already hosts this feature, but for CBs under Combo, you may need to write your own class.See this article as an example.

Related

wxWidgets widget IDs

I'm a little bit confused about how the IDs work in wxWidgets, do I have to ensure that all ids across all windows that I create are unique to each of their own functions? Like if I have two wxID_OK's for two different dialog boxes are they going to start firing off events in other windows just because they share the same id?
Currently I've been maintaining a huge enum to grab my IDs from, this seems a bit silly though, and was wondering if I just had a misunderstanding of what is actually going on.
I nerver use id's nowadays. I use wxID_ANY for all widgets and use the widget pointer for identification. This works just as well and so there is no reason for two id's for the same widget. There might be some corner cases where real id's are required but i have not found any.
It's a good idea to use unique IDs inside each top level window (i.e. a wxFrame or a wxDialog) because the controls include their ID in the wxCommandEvents they generate and as command events are propagated upwards the window hierarchy until they reach the first top level window, it could be confusing to have 2 controls with the same ID as any handler defined in their common parent window would need to be careful to distinguish between them.
There are no restrictions on the reuse of IDs in different dialog boxes however.
And an even better idea is to not use any non standard IDs at all but just let wxWidgets generate them for you by specifying wxID_ANY when creating controls and using Bind() to connect your event handlers instead of the IDs in the event tables.

Lookup Combo that supports remote data - load data only after user wants to

I'm building a VCL c++ builder application. I would like to see if anyone knows of a component that can load data in the lookup upon drop down only after a user has typed a few letters to limit the rows queried? Preferably after pressing Tab, or Enter.
What I would like best is to get a behaviour similar to what Linux command line has, but that might be wishful thinking. The way it would work is to drop down the combo list after user presses tab only if there is multiple options available, and to fill in additional text till the point where characters are not the same anymore, then if user presses tab again, drop down list.
The next best would be if the drop down would only allow drop down if user has typed a few letters, then pressing a specific button opens the dataset with the parameter of the typed text so far, then drops down the combo.
Does a component like this exist?
You can check out TMS Software. I'm not sure if it has something exactly for you, but their components are quite flexible. And you can send a feature request to them - to consider for next update. If you are lucky they might add it to next release.

How to obtain user's choice in a radio buttons group box for further processing?

I just finished with my web application's GUI part, which relies heavily on groups of radio buttons to provide an option mechanism.
I am looking to collect user choices from radio button groups in order to provide input parameters in certain algorithms.
Wt has not a connection function of this kind declared in its WRadioButton class and the way of creating radio buttons makes uneasy to store user's radio button choice.
How can I proceed on this?
UPDATE: I tried to obtain choices by using checkedButton() (declared in WRadioButton class) but my method didn't work properly.
I think it's easier to look at the methods and signals of WButtonGroup: selectedId(), which returns the id of the selected WRadioButton, or checkedChanged(), which is called when the selection changes, with the checked button. checkedButton() on the WButtonGroup should work too.
You also could connect all signals to one slot with Wt::WSignalMapper

PopUp Menus in a custom GUI API?

I have made my own GUI API for games. One assumption that must be made is the user may want to use a derived version of a Widget I have made.
An example of how I dealt with this with ToolTips is, the user allocates a new ToolTip and sets a global one for the GUI. Ex: getGui().setToolTip(customToolTip);
The GUI then calls toolTip->show() when necessary. The problem with menus in general is that you can have many of them appearing at a given time.
I also would hate to have the user implement an interface:
PopUpFactory::createPopUp()
PopUpFactory::destroyPopup()
How is this usually dealt with? Who or how is the memory also managed for these?
There is always the option of limiting to something like 9 nested menus and have the user set an array of 9 PopUps but that seems messy.
Thanks

Implementing Undo feature (like Ctrl+Z) in Qt/C++

I am using Qt 4.5 and C++ on Windows XP.
Basically I will be having an UI where the user will enter some data. He can go and modify the values available in the UI. The UI will have basic Qt UI elements like QLineEdit,QTableWidget etc.,
So now, if the user presses Undo button (or Ctrl+Z) the previous value should be retained in the corresponding UI element.
Say, if there is QLineEdit with the text 25. Now the user modifies to 30. Now by clicking Undo, the older value 25 should be retained.
Like the Undo feature that usually available in many applications. Is there any way to do it?
You could use Qt's undo framework.
The typical way of implementing Undo is to represent each action done by the user, and store them. You also want the ability to compute the inverse of a given action.
So, for an insert into a text buffer, the action would store the text inserted, and the location at which the insert happened. The inverse then becomes a delete, at the same location and with the size of the inserted text.
When the user asks the application to undo, simply look at the most recent stored action, and execute its inverse. If you now instead of deleting the "spent" action remember it, too, you can implement Redo by moving the other way in the history of actions.
Note that this is an abstract and generic explanation; as other answers point out, Qt has a framwork in place for implementing Undo already, so you should of course investigate that, first.
You could use the Command Pattern to realize undo/redo
QLineEdit has a built-in undo/redo support, exported as public slots, check : http://doc.trolltech.com/4.7/qlineedit.html#undo