#ifndef RemoteTable_h
#define RemoteTable_h

#include <QTableWidget>
#include <QPixmap>

// A RemoteTable defines one remote control, listing all the buttons
// defined on that remote and their current learning status.
//
class RemoteTable : public QTableWidget {

   Q_OBJECT

public:

   RemoteTable();

   virtual
   ~RemoteTable();

   // Utility routines to get access to the various pixmaps used
   // as flags in the status column.

   const QPixmap &
   RedQuestion() const {
         return red_question;
      }

   const QPixmap &
   GreenQuestion() const {
         return green_question;
      }

   const QPixmap &
   GreenCheck() const {
         return green_check;
      }

      // This gets called when I'm changing a row internally so I
      // can tell the difference between me doing it and the user
      // doing it (by editing the button name).
      //
   void
   SetChangingRow(bool change_status);

      // Whenever we have filled in a name in the last row of the table,
      // add a new (empty) row for the next button to go in.
      //
   void
   CheckLastRow();

      // Copy all the button data to a safe place so the analysis
      // code can trash the active version.
      //
   void
   CopyData();

      // Restore the copied data.
      //
   void
   RestoreCopy();

private slots:

      // Qt calls this when the button name is changed by the user.
      // Triggers the CheckLastRow() processing.
      //
   void
   doItemChanged(QTableWidgetItem * item);

private:

      // Internal utility to do the work of appending a new row
      // to the table.
      //
   void
   appendNewRow();

   int
   CountDuplicates(QString txt, QTableWidgetItem * skip_item);

   bool appending_row;
   bool changing_row;
   bool in_do_item_changed;

   const QPixmap red_question;
   const QPixmap green_question;
   const QPixmap green_check;

};

#endif // RemoteTable_h
