#ifndef OneButton_h
#define OneButton_h

#include <QTableWidgetItem>
#include <vector>

class OneSample;
class ButtonEditor;
class ButtonDifference;

// OneButton represents a single button in a remote. The information
// for one row of the remote definition table comes from here (this
// is always stored in column 0, and is responsible for filling in the
// text of the other columns).
//
class OneButton : public QTableWidgetItem {
public:

   OneButton();

   virtual
   ~OneButton();

      // How many IR samples do we have for this button?
      //
   unsigned int
   NumSamples() const;

      // Fetch the Nth sample (or NULL if ndx out of range).
      //
   OneSample *
   operator[](unsigned int ndx) const;

      // Recording mode calls this to add a new sample to the button.
      //
   void
   AppendSample(OneSample * new_sample);

      // Call this to update the information in column 1 and 2 of this
      // button's row. Does the analysis on the samples to see if they
      // make any sense.
      //
   void
   UpdateButtonInfo();

      // When button is being edited, we need to know when new samples
      // are added, so we tell button about the editor, so it can tell
      // the editor.
      //
   void
   SetEditor(ButtonEditor * new_edit);

   unsigned long
   MaxSampleTime() {
         return max_sample_time;
      }

   double
   LogMaxSampleTime() {
         return log_max_sample_time;
      }

      // Get a ButtonDifference struct with the differences between all the
      // button samples (warning: this object will be deleted whenever new
      // samples are added, so don't hang onto it too long - best idea is not
      // to keep a pointer, but always ask OneButton for the value).
      //
   ButtonDifference *
   GetButtonDifference();

      // Copy samples for this button to sample_copy.
      //
   void
   CopyData();

      // Restore samples from sample_copy.
      //
   void
   RestoreCopy();

private:

   void
   DeleteSamples();

   std::vector<OneSample *> sample;

   std::vector<OneSample *> sample_copy;

   ButtonEditor * button_edit;

   unsigned long max_sample_time;
   double        log_max_sample_time;

   ButtonDifference * difference;
};

#endif // OneButton_h
