Is there any way in MFC to change or to learn ID of instance object like *CTreeCtrl.
In my project I have 3 equal bars with tree on each of them. Using pointer to bar I create bars and after Trees on these bars. I don't want to create own class for every bar. It will be bed solution.
So, after I want to use Tree's ID for making DDE. It will be very comfortable for me because class with trees containers already written. Thanks to DDE I will fast create connection between CTreeCtrl and functional class.
I hope you have some ideas about this IDs.
You do not have to create new class to accommodate each object.
I presume that you use Create member of the CTreeCtrl. Create takes ID as the last parameter. Use GetDlgCtrlID member to retrieve this ID.
GetDlgCtrlID is a member of CWnd and CTreeCtrl is derived from CWnd, hence it also inherits this function.
Related
Alright so what I am doing is creating a encrypted chat room for my friends and I to mess around in.
I wanted to make a private chat where you could right click their name on the List View and message them.
Currently I a structure with all "users" information like name, time logged on, and List View Number. But that List View number becomes incorrect when a user disconnects because it shifts everyone down by one.
How would I be able to essentially "tie" a user to a List View item? That way no matter how many people log on / off when I click on their name it will PM that person. (I tried to use LVN_ITEMCHANGE because I thought the iItem would change but it didn't to my experiance)
**My Idea*
My Idea was to add a random character field in the ListView item called "token" that way when someone clicks on the name it will find the "token" that would be unique and do it that way. But maybe their is an easier way so that is why I am asking.
Your data structure should not be tracking the ListView items at all. It is just extra data.
Your ListView can associate each list item with a data structure. The LVITEM structure has an lParam field for handling user-defined values:
When you want to add a new user to the ListView, dynamically allocate your data structure and assign that pointer to the LVITEM::lParam field before using the LVM_INSERTITEM message.
When you want to access a particular user's data, retrieve that list item's LVITEM using the LVM_GETITEM message, and then type-cast its lParam to access your data structure.
When you want to remove a user, simply remove that list item using the LVM_DELETEITEM message, and then use the LVN_DELETEITEM notification to free the associated data structure.
Alternatively, use the ListView in virtual mode via the LVS_OWNERDATA window style (see Virtual List-View Style and How to Use Virtual List-View Controls), and then you don't need to use the LVITEM::lParam field at all. Store your data structures in a separate array/container somewhere off to the side, and then use the LVN_GETDISPINFO notification to provide display data to the ListView only when it needs data. When you add/remove users from your array/container, simply use the LVM_SETITEMCOUNT message to update the ListView's item count to match the new array/container count. That way there is always a direct relation between ListView items and container items. Let LVN_GETDISPINFO tell you which array/container item to access.
I’m trying to display some tabular data with a QTableView subclass and a QAbstractTableModel subclass. I can’t get the data to show up, but before I start really pounding on it I want to make sure that I’m using models in the way they were intended.
The data layer of my application periodically receives new data and distributes the data to the other parts of the application by calling slots like
void new_data_received(QSharedPointer<Measurement> measurement)
where Measurement is my data class. This allows the data to be passed around without being copied (some of my data classes are very large). Measurements are immutable; the table view that displays them doesn’t allow any editing.
Measurement is a subclass of QAbstractTableModel, so whenever I receive a new measurement I call set_model on my QTableView subclass instance with the new data as a parameter. (In the time before the first measurement is received there is no model set on the table view.)
Are Qt’s view classes intended to be used like this, with a new model being set every so often? Or should there be just one instance of the model class, with the same lifetime as the table view, that receives the new data and emits dataChanged? The latter seems like it adds unnecessary structure—at least in my case—but maybe that’s the way the system was designed to be used.
I don't think your Measurement class should be a subclass of QAbstractTableModel. It should represent raw data instead. So maybe a struct with some parameters or a list of structs will be a right type for your data class.
Then you should implement a custom model where incoming data are added to. So, when new data arrives that model will automatically update all the views connected to it. In this case new data affects directly your model only, not the views.
I suppose resetting view's model every time is not the right way to do what you want.
I have a subclass of QStandardItemModel in which I have drag and drop working quite nicely. I store my data (pointers to classes) in a subclass of QStandardItem.
The classes stored in my standarditem all inherit from the same class, and I wish to enable collections of each subclass through dropping onto a collection type object.
E.g
--Apples
--braeburn
--golden delicious
--Oranges
--Meat
--pork
--lamb
--beef
So I can drag different types of apple underneath Apples, different meats under "Meat", etc. I do this by examining the type of both the target and the dropped item in my version of dropMimeData (i.e. get the stored class from my standardItem, check its type).
My problem is when I reject an item by returning false, the item is gone from the tree. Is there a way to get the original location of the dropped item, so I can put it back?
I wasn't sure how to word the title, but here we go.
Let's say I made a Lua function to create a 2D box appear on the screen - for example:
box = createObject("Box")
How would I create properties for box that would subsequently change how box looks or reacts? For example I may want to do
box.PositionX = 0
box.PositionY = 60
How do I do that in C++?
Just answering the direct question itself, things are simple:
Just use the standard metatable-aware add/set-table-index API.
If we look at how box itself should look, things get interesting:
If createObject "Box" returns a Lua table and you don't need to react immediately on change, just don't do anything special.
If createObject "Box" returns a Lua table but you need to react immediately, let it act as a proxy object, aka force using the metatable function by never adding that element to the table itself. Remap to another index or another table saved at a dedicated index or in the metatable/metatable function closures.
If createObject "Box" returns a userdata, do the same as for 2, maybe saving non-lua-values in C for faster access/higher efficiency, using the environment table for all other values.
I have an association like this
class Parent
List children
static hasMany =[children:Child]
I need to be able to know the order of a Child object when I look at it outside of Parent context. So that I can tell if it is a 1st child, second child, etc.
What do you mean with 'outside of Parent context'? To get index of a object in a list - you need to load it before. If you want to get index without loading Parent, then you have to use an raw SQL for this, but i'm not sure that it will be faster than loading Parent, because it's the same logic, except making mapping resultset to a model.
Btw, to get this index when you have Parent instance, you have to use:
int idx = parent.children.indexOf(child)
And don't forget to implement .equals of your Child domain.