RTXI / rtxi

Tutorials, FAQs, and more at http://rtxi.org/docs
GNU General Public License v3.0
53 stars 15 forks source link

update(REFRESH) for DefaultGUI #52

Closed sudorook closed 9 years ago

sudorook commented 9 years ago

I keep overloading the refresh() function in DefaultGUI. By "overloading", I mean copy/pasting what's already in DefaultGUI::refresh() and adding my own stuff below it. It would make more sense if there was an update(REFRESH) built into DefaultGUI, like how there's an update(PAUSE), update(EXIT), etc.

I'll add the feature now. Just making note of my intentions here (and spamming your inboxes while I'm at it).

sudorook commented 9 years ago

membrane-test

I copied the stuff in DefaultGUI and added my bit to the bottom.

Some of our modules, when they do computationally intensive things that don't need to be (or can't be) done in real-time, do them in the GUI thread. Others need to update displays and messages.

The 1.4 versions of them have timers that set when to update the GUI, and when I rebuilt them to abstract from DefaultGUI, I overloaded refresh to have the same timer trigger all the GUI changes.

A module with a second timer (refresh not overloaded. rather, two refresh functions made)

sudorook commented 9 years ago

I'll hold off on committing any changes, then.

As far as adding code is concerned, it's a matter of adding REFRESH to update_flags_t and adding update(REFRESH) to the end of refresh(void) {...}.

enum update_flags_t {
      INIT,     /*!< The parameters need to be initialized.         */
      MODIFY,   /*!< The parameters have been modified by the user. */
      PERIOD,   /*!< The system period has changed.                 */
      PAUSE,    /*!< The Pause button has been activated            */
      UNPAUSE,  /*!< When the pause button has been deactivated     */
      EXIT,     /*!< When the module has been told to exit        */
      REFRESH,  /*!< When the screen refreshes */
};
void DefaultGUIModel::refresh(void) {
   for (std::map<QString, param_t>::iterator i = parameter.begin(); i!= parameter.end(); ++i) {
      if (i->second.type & (STATE | EVENT)) {
         i->second.edit->setText(QString::number(getValue(i->second.type, i->second.index)));
         palette.setBrush(i->second.edit->foregroundRole(), Qt::darkGray);
         i->second.edit->setPalette(palette);
      } else if ((i->second.type & PARAMETER) && !i->second.edit->isModified()
            && i->second.edit->text() != *i->second.str_value) {
         i->second.edit->setText(*i->second.str_value);
      } else if ((i->second.type & COMMENT) && !i->second.edit->isModified()
            && i->second.edit->text() != QString::fromStdString(getValueString(COMMENT, i->second.index))) {
         i->second.edit->setText(QString::fromStdString(getValueString(COMMENT, i->second.index)));
      }
   }
   pauseButton->setChecked(!getActive());

   update(REFRESH);
}