<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Is this a good case for a QStateMachine?]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I'm in the process of designing a screen that will display financial data. It is quite simple as it is a table with up to 30 columns and 100 rows. The cells will display various pieces of data either text, images or a combination of the two. The cells won’t be directly editable. I don’t have a problem creating the Model with an appropriate View to display this data but I would like some advice on how to control the visual ‘highlighting’.</p>
<p dir="auto">Part of this display is to highlight a cell when something has changed. In the simplest example it would be if a price goes up flash it blue, if it goes down flash it red.</p>
<p dir="auto">I’m thinking about using a state machine per cell because the underlying data can be in different states, ‘up/down/up on day/down on day/suspended/crossed/blah/blah/blah/…’, all of which will change the visual aspect of the cell. I’ve not used a state machine before and I was wondering if this would be a good fit?</p>
<p dir="auto">I would probably use something like a QEventTransition with barriers to cause the states to change.</p>
<p dir="auto">Is this just overkill? As I’m sure I could achieve all this with a few switch statements, and with there being circa 3000 cells is it going to be a CPU hog?</p>
<p dir="auto">Thanks.</p>
]]></description><link>https://forum.qt.io/topic/10168/is-this-a-good-case-for-a-qstatemachine</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 03:27:06 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/10168.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 06 Oct 2011 10:55:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Is this a good case for a QStateMachine? on Fri, 07 Oct 2011 10:02:36 GMT]]></title><description><![CDATA[<p dir="auto">Hmmm, one way would be to provide a custom delegate (see &lsqb;&lsqb;Doc:QStyledItemDelegate&rsqb;&rsqb;) that knows about flashing.</p>
]]></description><link>https://forum.qt.io/post/112476</link><guid isPermaLink="true">https://forum.qt.io/post/112476</guid><dc:creator><![CDATA[ZapB]]></dc:creator><pubDate>Fri, 07 Oct 2011 10:02:36 GMT</pubDate></item><item><title><![CDATA[Reply to Is this a good case for a QStateMachine? on Fri, 07 Oct 2011 08:42:57 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for getting back to me. I did a bit of R&amp;D yesterday and came to the same conclusion.</p>
<p dir="auto">I decided to have QStandardItem descendant that creates a set of objects that define the behaviour of the cells (FlashableCell), which will control the display through the data() method, exactly as you have suggested.</p>
<p dir="auto">Instead of a switch I can decide upfront, using composition, how the comparison logic and subsequent colouring will work.</p>
<p dir="auto">The next item to tackle is the flashing and how to make this efficient. My current thoughts are to populate a list of FlashableCells when a cells' content changes. This will set a timeout/expiry against the cell ... basically I'm creating a MRU ... and every second I can run through this list and see if the cell has expired. If it has I will then revert it to a non-flashed state ... anyways ...</p>
<p dir="auto">Thanks again for confirming the direction to go in.</p>
]]></description><link>https://forum.qt.io/post/112439</link><guid isPermaLink="true">https://forum.qt.io/post/112439</guid><dc:creator><![CDATA[waxwed]]></dc:creator><pubDate>Fri, 07 Oct 2011 08:42:57 GMT</pubDate></item><item><title><![CDATA[Reply to Is this a good case for a QStateMachine? on Thu, 06 Oct 2011 15:21:25 GMT]]></title><description><![CDATA[<p dir="auto">I would say that one state machine per cell is a massive overkill. Each state machine has it's own event queue and requires some processing time in the event loop.</p>
<p dir="auto">At first thought I would probably take the approach of encoding the state into a new data role so that you can query it via your model's data() function in your custom view.</p>
<p dir="auto">If you are using a standard view then in your data() function you can provide a custom value for the cell background etc. depending upon the value of your custom field using a simple switch as you say.</p>
]]></description><link>https://forum.qt.io/post/112373</link><guid isPermaLink="true">https://forum.qt.io/post/112373</guid><dc:creator><![CDATA[ZapB]]></dc:creator><pubDate>Thu, 06 Oct 2011 15:21:25 GMT</pubDate></item></channel></rss>