File: progressDebug.cc

package info (click to toggle)
gpsshogi 0.7.0-3.3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 111,280 kB
  • sloc: cpp: 80,962; perl: 12,610; ruby: 3,929; javascript: 1,631; makefile: 1,202; sh: 473; tcl: 166; ansic: 67
file content (115 lines) | stat: -rw-r--r-- 2,946 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "progressDebug.h"
#include "ui_progressdebugdialog.h"
#include "osl/progress.h"

#include <QAbstractTableModel>

class NewProgressDebugModel : public QAbstractTableModel
{
public:
  NewProgressDebugModel(const osl::NumEffectState &state,
                        QObject *parent = 0);
  int rowCount(const QModelIndex &parent = QModelIndex()) const;
  int columnCount(const QModelIndex &parent = QModelIndex()) const;
  QVariant data(const QModelIndex &index, int role) const;
  QVariant headerData(int section, Qt::Orientation orientation,
		      int role = Qt::DisplayRole) const;
private:
  QStringList column_headers, row_headers;
  osl::progress::ml::NewProgressDebugInfo debug_info;
};

NewProgressDebugModel::NewProgressDebugModel(
  const osl::NumEffectState &state,
  QObject *parent)
  : QAbstractTableModel(parent)
{
  osl::progress::ml::NewProgress progress(state);
  debug_info = progress.debugInfo();
  column_headers << "Black" << "White" << "Sum";
  row_headers << "ATTACK_5X3"
              << "DEFENSE_5X3"
              << "ATTACK5X5"
              << "STAND"
              << "EFFECT5X5"
              << "KING_RELATIVE_ATTACK"
              << "KING_RELATIVE_DEFENSE"
              << "NON_PAWN_ATTACKED_PAIR";
}

int NewProgressDebugModel::rowCount(const QModelIndex &) const
{
  return row_headers.size();
}

int NewProgressDebugModel::columnCount(const QModelIndex &) const
{
  return column_headers.size();
}

QVariant NewProgressDebugModel::headerData(int section,
                                          Qt::Orientation orientation,
                                          int role) const
{
  if (role != Qt::DisplayRole)
  {
    return QVariant();
  }

  if (orientation == Qt::Vertical && section < row_headers.size())
  {
    return row_headers[section];
  }
  else if (orientation == Qt::Horizontal && section < column_headers.size())
  {
    return column_headers[section];
  }
  return QVariant();
}

QVariant NewProgressDebugModel::data(const QModelIndex &index, int role) const
{
  if (!index.isValid())
  {
    return QVariant();
  }
  if (role != Qt::DisplayRole)
  {
    return QVariant();
  }
  const int column = index.column();
  const int row = index.row();
  if (row > rowCount() ||
      column >  columnCount())
  {
    return QVariant();
  }

  if (column == 0)
  {
    return debug_info.black_values[row];
  }
  else if (column == 1)
  {
    return debug_info.white_values[row];
  }
  else if (column == 2)
  {
    return debug_info.black_values[row] + debug_info.white_values[row];
  }
  return QVariant();
}

NewProgressDebugDialog::NewProgressDebugDialog(const osl::NumEffectState &state,
                                               QWidget *parent)
  : QDialog(parent), ui(new Ui::ProgressDebugDialog)
{
  ui->setupUi(this);
  model = new NewProgressDebugModel(state, this);
  ui->tableView->setModel(model);
}

NewProgressDebugDialog::~NewProgressDebugDialog()
{
  delete ui;
}