I am trying to update a QTreeWidget every 60 seconds. I have it on a QTimer right now but my concern is that when it updates it will disrupt the users progress(for example if they have a parent opened up so you can see the children, when I update it completely resets the structure). Is there a model or anything I can do to prevent this from hurting their progress?
It is not possible for the view to update and remember the previously expanded items. You could cache the state of your view and reconstruct it with QTreeWidget::expand and QTreeWidget::scrollTo after an update, but the user will still see how the view closes and expands again. Also, it would not be enough to store the currently expanded item's index because that might change after the update. So you'd have to cache some unique identifier and search it in the upated widget afterwards.
What you are trying to do, is quite unusual, since normally you'd only update the widget when the data changes instead of using a fixed interval of time.
Consider using a QTreeView in combination with a QAbstractListModel instead of a QTreeWidget because the latter is designed to hold constant data. Then you can emit dataChanged on the model which automatically updates the QTreeView.
Related
I am trying to understand change feeds in Azure. I see I can trigger an event when something changes in cosmos db. This is useful. However, in some situations, I expect a document to be changed after a while. A question should have a status change that it has been answered. After a while an order should have a status change "confirmed" and a problem should have status change "resolved" or should a have priority change (to "low"). It is useful to trigger an event when such a change is happening for a certain document. However, it is even more useful to trigger an event when such a change after a (specified) while (like 1 hour) does not happen. A problem needs to be resolved after a while, an order needs to be confirmed after while etc. Can I use change feeds and azure functions for that too? Or do I need something different? It is great that I can visualize changes (for example in power BI) once they happen after a while but I am also interested in visualizing changes that do not occur after a while when they are expected to occur.
Achieving that with Change Feed doesn't sound possible, because as you describe it, Change Feed is reacting based on operations/events that happen.
In your case it sounds as if you needed an agent that needs to be running every X amount of time (maybe an Azure Functions with a TimerTrigger?) and executes a query to find items with X state that have not been modified in the past Y pre-defined interval (possibly the time interval associated with the TimerTrigger). This could be done by checking the _ts field of the state documents or your own timestamp field, see https://stackoverflow.com/a/39214165/5641598.
If your goal is to just deploy it on a dashboard, you could query using Power BI too.
As long as you don't need too much time precision (the Change Feed notifications are usually delayed by a few seconds) for this task, the Azure CosmosDB Change Feed could be easily used as a solution, but it would require some extra work from the Microsoft team to also support capturing deletion TTL expiration events.
A potential solution, if the Change Feed were to capture such TTL expiration events, would be: whenever you insert (or in your use case: change priority of) a document for which you want to monitor lack of changes, you also insert another document (possibly in another collection) that acts as a timer, specifying a TTL of 1h.
You would delete the timer document manually or by consuming the Change Feed for changes, in case a change actually happened.
You could also easily consume from the Change Feed the TTL expiration event and assert that if the TTL expired then there were no changes in the specified time window.
If you'd like this feature, you should consider voting issues such as this one: https://github.com/Azure/azure-cosmos-dotnet-v2/issues/402 and feature requests such as this one: https://feedback.azure.com/forums/263030-azure-cosmos-db/suggestions/14603412-execute-a-procedure-when-ttl-expires, which would make the Change Feed a perfect fit for scenarios such as yours. Sadly it is not available yet :(
TL;DR No, the Change Feed as it stands would not be a right fit for your use case. It would need some extra functionalities that are planned but not implemented yet.
PS. In case you'd like to know more about the Change Feed and its main use cases anyways, you can check out this article of mine :)
What will happen when we move from one state to other in Phaser i.e. Array, objects, images loaded in the previous state are flushed when we move to the next state?
Thanks in Advance!!
By default, all display objects that you added to the game world (sprites, texts, etc.) are removed when switching to a different state. All of your loaded assets remain in the cache and you can use them in your new state.
You can change this behavior when you call start method on State manager.
game.state.start("nextState", true, true);
The second parameter specifies whether game objects should be cleared.
The third parameter says whether game cache should be cleared.
I'm creating an application that will sort items in the DB in order to create a selective process.
This process, will consist of Users, and Registers in courses.
Each course, will have Users in it, and the SORT method to select them will vary depending on each course.
I'm implementing a way of 'simulating' the position of a user in a course, without matriculating it in the course, so that he can 'know' it's position prior to entering the selection process.
To do so, I imagined that I could use the same logic used after the user has already registered: Sort in the DB, return the list of ID's, and see what's the user index in that list.
However, I want just to simulate, without creating/updating anything. I cannot find a way to do that, without during the query, inserting a 'fake' document, but that cannot happen for reasons of security and integrity (inserting/removing items let the DB integrity broken during a short period of time, and can cause conflicts within logics of the application).
Doing the sorting on the DB, and re-doing it on the system is also not a good Idea as well, since there will be duplicated logic going on.
How can I 'fake' an document, without creating it during a query?
I have a background process receiving and applying changes to Core Data entities from a back end server using Restkit which works really well. All the entities have a version number property which updates when the back end accepts changes and publishes a new version. If an entity the user is viewing is changed I need to update the view with the latest version information.
Using KVO to observe version number for the current entity and refreshing the view when it changes works really well as long as version number is the last property.
That is, the 'column order' matters, and property updates are atomic. If the version number is the last property then when the observer is invoked all changes to all entity properties will have been applied.
If version number is not the last property defined, then when the observer is invoked the updated values of the properties after version will not been applied.
The solution is to change the database and ensure that version number is always last. This works however I cannot find anything in the documentation to suggest that the sequence of property changes is guaranteed.
I assume the only way to get a water-tight non-atomic notification is to register for managed object context change notifications and then process those notifications looking for changes to objects of interest. My concern with this is that it is not fined grained and there will be a lot of unnecessary processing to find relatively few things of interest.
Is this correct or is there a way to ensure an non-atomic view of an object when using KVO?
If you wanted to use KVO you would need to layer some change management on top, such as when the managed object is saved you check the version number and change another (non-persistent) attribute that is being observed. You can be sure that everything has been updated in a logical set when the object is saved.
Generally the context save notification is the approved approach. So long as you aren't making thousands of changes or making few large saves to the context it shouldn't be an issue. You can also look at using predicates to filter the changes and / or a fetched results controller (which does the observation for you).
I have a Core Data based UIKit application that allows the user the drag objects around on the screen. While an object is being dragged, I update its position attribute on each touchesMoved: event. To support undoing a drag operation in one go, I start a new undo group at the beginning of the drag, and end the group when the user lifts their finger.
To save memory and to make undo operations fast, I want to coalesce undo data belonging to the drag operation, but Core Data makes this difficult. The problem is that processPendingChanges is called at the end of each run loop cycle, and it forces Core Data to file a new undo record for the position change that happened in that iteration. A drag operation can easily accumulate hundreds of such undo records, all of which but the first are unnecessary.
Is there a way for me to keep using Core Data's magical built-in undo support, but without wasting precious memory on such duplicate undo records? I love that I don't need to care about maintaining object graph consistency across undo/redo operations, but not being able to correctly handle these continuous attribute updates seems to be a showstopper.
I think setting the undo managers setGroupsByEvent: will do what you want.
Sets a Boolean value that specifies
whether the receiver automatically
groups undo operations during the run
loop. If YES, the receiver creates
undo groups around each pass through
the run loop; if NO it doesn’t.
A cleaner solution might be to simply not commit the objects position to the data model until the end of the drag event.
One solution is to disable all undo registration after the very first drag event, and keep it disabled until the entire gesture is finished.
If you have groupsByEvent on, you'll need to keep in mind that the undo manager ignores all grouping messages while registration is off, including the one that ends the implicit group automatically at the end of the event. So if you plan to leave registration turned off at the end of the run loop, you'll have to manually close the implicit group yourself:
[moc processPendingChanges];
while ([moc.undoManager groupingLevel])
[moc.undoManager endUndoGrouping];
[moc.undoManager disableUndoRegistration];
Once the drag gesture is finished, you can re-enable undo registration with the following code:
[moc processPendingChanges];
[moc.undoManager enableUndoRegistration];
This solution works, but it is a bit kludgy. The one suggested by TechZen is much cleaner: don't update model attributes until the drag gesture is done.