MFC - How to send messages between 2 different Views - mfc

I have 2 CView-derived classes, CThumbView and CMainView. The CThumbView class displays thumbnails of images and the CMainView class controls the View that displays the original image.
I want to display the first thumbnail and its original when my application starts up. I tried using OnInitialUpdate, but that is not the ideal way as it bothered the other functionalities that was handling the main view.
How can I do this by sending a user-defined message between the 2 views?

Since you are using the Document View Architecture you need to take advantage of the CDocument::UpdateAllViews function of the document from your view in order to update rest of the views. This function will call OnUpdate of each view.
The data is held by the document. Views access the data & update themselves accordingly.

Related

Qt - how to use the same delegate for different views in a stacked widget

Ok, so I am creating an app that includes a stacked widget that has two pages with two different views that display different information. Both views require different delegates for individual columns, For example the first two columns use line edits, the next two use spin boxes, etc. However both views hold different information and manipulate and store them in different ways, and I do this by setModelData method from within the delegate.
I can't use the exact same code in the setModelData method for both views because the data is not stored the same, so is there a way to be able to tell within the delegate what page the stackedWidget is on so I can use control statements to choose what to do with the data? Or I am stuck with having to create all new delegates for each view?

MS Access Web App: set filter on sub view based on master view

My application has a list view (master) containing a data sheet view in a sub view element.
In the list view, I would like to use some control like a button or a combo box to filter the data in the sub view. How can I pass a parameter for the filter from the master view to the sub view?
I don't believe the scenario you are looking at here will be directly possible within the Access web app context. Let me explain.
In Access 2013 web apps, there is no macro action available to requery or refresh a specific control on a view. The same goes for trying to refresh a Subview control on a view. The only way you can pass parameters to a different view in the web app context is by using the OpenPopup macro action. In that case the view will open as a popup which is not what you want here either.
So you might not be able to achieve your end goal. One suggestion that might work is to have say an unbound text box control on the main parent view. For the Subview control, use that unbound control as the Master Field (in the property list). Access will attempt to match records from this unbound control to whatever field you designate as the Child Field property. If you update that unbound text box control on the main view, Access should filter the results in the Subview. I "think" that will work.
It works in my app. SubForm updates with filter when focus leaves the txtbox. Unfortunately, you can only search one field per subview as it is set as a property at design time and AFAIK there is no way to change at runtime.

Qt Views [not] updating upon underlying structure of the model changes

I have encountered an issue that is most likely WAD but I still need to solve. I originally thought it was a problem with my custom models but it is in fact present with Qt native model classes as well.
Consider this little program: https://drive.google.com/file/d/0B9MLVHQaeHKxeFBSYzVGVF9sQ0U/edit?usp=sharing
It is just fresh Qt GUI app with 2 QTreeViews and two sets of buttons for inserting/removing rows and columns on each view. The underlying models are QStandardItemModel in one view and QIdentityProxyModel in the other. The navigation is accomplished by clicking on the models – the index is stored and then used by the buttons.
Try inserting/removing rows and columns and you will notice that the views do not update right after the underlying data structure will have changed. Rather they will be updated after you hover over them. And that is the problem because in my other project I have incoming network data that updates the model data that is being displayed to user via standard Qt views. Therefore I need the views to be updated after the data changed and NOT when user hovers over them which he may not do as he may not be aware of the change.
You may notice there is the updateViews() function where I have tried to force-update the views. Neither update() nor repaint() changed anything. The former probably correctly as the documentation says but the repaint should as I understand it cause the widgets to get repainted… Is there any other way to force-update the views?
Also, the reason why I set up the proxy model is that in my project the proxies are heavily used and therefore I need to cause the view-update via them rather than via external slot/function call as is the case in the example given. But if need be this could work as a work-around as well.
Thanks!
EDIT: Problem is manifesting with columns manipulation only it seems. See detail in comments below.

Using multiple adapters in an application

I am making an application in Ember which would do the functionalists.
Allowing the user to upload an Image and then crop or zoom it. (The values associated with the image I am storing into a model using Fixture Adapter as I don't want the data to be persistent).
I am allowing the user to write some message and also change the font-size, color of the text. (Again I am storing it in the same way.)
I am adding recipients. (Again I am storing them the same way)
Now I want to get a list of previous recipients from the server which will then be shown to the user so that he can add or select previous recipients.
Now the problem is I want to get recipient list and store it in some kind of model. But I am not getting how to do that. I am thinking of making another model for previous recipients and display the list from there. But is it possible to get the values of different model and show it in different view?
Looking forward to hear different views.

Modelling self-modifying data / wrapper models in Qt

In Qt, I'm writing my own tree model (by subclassing QAbstractItemModel) which wraps around an existing data structure. It should be possible to update the data structure internally (not via the model) as well as via the model (so views can change it). In order to imagine it better: it's a scene graph which should be possible to edit using a scene view (without going via the Qt model) but also using an outliner (QTreeView which uses a Qt model as a proxy around the scene graph).
To avoid confusion we should consider two different scenarios (in the following, I use the "remove" operation as an example):
The user uses the Qt view to remove a node. The view wants to remove a row from the model using QAbstractItemModel::removeRow. This should in turn remove a corresponding node from the underlying data structure, the scene graph.
The user uses the scene view to remove a node. The scene view wants to remove a node from the scene graph. The model which wraps around the scene graph gets notified and in turn wants to notify connected views that a row has just been removed.
While I think I know how to implement 1., I don't know how to implement the notifying part in 2. There is the signal QAbstractItemModel::rowsAboutToBeRemoved() as well as rowsRemoved() which sound like they're my friends. But they are private signals (they say in the header source code: "can only be emitted by QAbstractItemModel"). There also is beginRemoveRows() and endRemoveRows() but according to their documentation, they should be called when the updates happens from the view, i.e. when removeRow has been called. Also, when I tried to use them, the view was screwed up totally.
According to the documentation it seems like it's not intended that the model class can model self-modifying data. Let's take a file system as another example. When using file system watching, which can detect changes in directories, a model should notify a view so the changes in the directory can be displayed live, even if the view was not used to modify the file system. Are such models even possible in Qt?
You're reading it wrong. The model must signal to its users when it's about to start changing its "geometry". So, no matter what is removing the rows from the model, it must tell the outside world that it happened. The sequence of events when a view removes rows from the model is such:
The view calls model->removeRows().
The model calls beginRemoveRows()
The model actually removes the rows from the internal data.
The model calls endRemoveRows().
If you implement some other interface that will remove the rows without calling model->removeRows(), you have to do exactly the same thing. It doesn't matter if it's a view or some other code that removes rows from the model, the model's behavior must be the same or else nothing will work.
You can architect an adapter class that's inserted between your SceneGraph and the Model. It should hold a pointer to the scenegraph and the model, and translate the operations between the two.