Huggle  build:^490^dce1e5c
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
history.cpp
1 //This program is free software: you can redistribute it and/or modify
2 //it under the terms of the GNU General Public License as published by
3 //the Free Software Foundation, either version 3 of the License, or
4 //(at your option) any later version.
5 
6 //This program is distributed in the hope that it will be useful,
7 //but WITHOUT ANY WARRANTY; without even the implied warranty of
8 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 //GNU General Public License for more details.
10 
11 #include "history.hpp"
12 #include "ui_history.h"
13 
14 using namespace Huggle;
15 
16 History::History(QWidget *parent) : QDockWidget(parent), ui(new Ui::History)
17 {
18  ui->setupUi(this);
19  ui->tableWidget->setColumnCount(4);
20  QStringList header;
21  header << "ID" << "Type" << "Target" << "Result";
22  ui->tableWidget->setHorizontalHeaderLabels(header);
23  ui->tableWidget->horizontalHeader()->setSelectionBehavior(QAbstractItemView::SelectRows);
24  ui->tableWidget->verticalHeader()->setVisible(false);
25  ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
26 #if QT_VERSION >= 0x050000
27 // Qt5 code
28  ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
29 #else
30 // Qt4 code
31  ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
32 #endif
33  //ui->tableWidget->horizontalHeaderItem(0)->setSizeHint(QSize(20,-1));
34  ui->tableWidget->setShowGrid(false);
35 }
36 
38 {
39  this->Items.insert(0, item);
40  ui->tableWidget->insertRow(0);
41  ui->tableWidget->setItem(0, 0, new QTableWidgetItem(QString::number(item.ID)));
42  ui->tableWidget->setItem(0, 1, new QTableWidgetItem(HistoryItem::TypeToString(item.Type)));
43  ui->tableWidget->setItem(0, 2, new QTableWidgetItem(item.Target));
44  ui->tableWidget->setItem(0, 3, new QTableWidgetItem(item.Result));
45 }
46 
47 void History::Refresh()
48 {
49 
50 }
51 
52 void History::Remove(HistoryItem item)
53 {
54 
55 }
56 
57 History::~History()
58 {
59  delete ui;
60 }
61 
62 QString HistoryItem::TypeToString(HistoryType type)
63 {
64  switch (type)
65  {
66  case HistoryUnknown:
67  return "Unknown";
68  case HistoryMessage:
69  return "Message";
70  case HistoryEdit:
71  return "Edit";
72  case HistoryRollback:
73  return "Rollback";
74  }
75  return "Unknown";
76 }
77 
78 
79 int History::Last = 0;
80 
81 HistoryItem::HistoryItem()
82 {
83  History::Last++;
84  this->Target = "Unknown target";
85  this->Type = HistoryUnknown;
86  this->ID = History::Last;
87  this->Result = "Unknown??";
88 }
89 
90 HistoryItem::HistoryItem(const HistoryItem &item)
91 {
92  this->ID = item.ID;
93  this->Target = item.Target;
94  this->Type = item.Type;
95  this->Result = item.Result;
96 }
97 
98 HistoryItem::HistoryItem(HistoryItem *item)
99 {
100  if (item == NULL)
101  {
102  throw new Exception("HistoryItem item must not be NULL", "HistoryItem::HistoryItem(HistoryItem *item)");
103  }
104  this->ID = item->ID;
105  this->Type = item->Type;
106  this->Target = item->Target;
107  this->Result = item->Result;
108 }
int ID
Unique ID of this item.
Definition: history.hpp:42
History of actions done by user.
Definition: history.hpp:57
void Prepend(HistoryItem item)
Insert a new item to top of list.
Definition: history.cpp:37
Every exception raised by huggle is defined by this class.
Definition: exception.hpp:20
HistoryType Type
Type of item.
Definition: history.hpp:46
History consist of these items.
Definition: history.hpp:35