File: incidentSeverities.cpp

package info (click to toggle)
postbooks 4.9.5-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 103,120 kB
  • sloc: cpp: 288,269; sh: 607; xml: 214; awk: 104; makefile: 49
file content (154 lines) | stat: -rw-r--r-- 4,737 bytes parent folder | download
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
 * This file is part of the xTuple ERP: PostBooks Edition, a free and
 * open source Enterprise Resource Planning software suite,
 * Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 * It is licensed to you under the Common Public Attribution License
 * version 1.0, the full text of which (including xTuple-specific Exhibits)
 * is available at www.xtuple.com/CPAL.  By using this software, you agree
 * to be bound by its terms.
 */

#include "incidentSeverities.h"

#include <QAction>
#include <QMenu>
#include <QMessageBox>
#include <QSqlError>
#include <QVariant>

#include <openreports.h>
#include "incidentSeverity.h"

incidentSeverities::incidentSeverities(QWidget* parent, const char* name, Qt::WindowFlags fl)
    : XWidget(parent, name, fl)
{
  setupUi(this);

  connect(_close,  SIGNAL(clicked()), this, SLOT(close()));
  connect(_delete, SIGNAL(clicked()), this, SLOT(sDelete()));
  connect(_edit,   SIGNAL(clicked()), this, SLOT(sEdit()));
  connect(_incidentSeverities, SIGNAL(populateMenu(QMenu *, QTreeWidgetItem *, int)), this, SLOT(sPopulateMenu(QMenu*)));
  connect(_incidentSeverities, SIGNAL(valid(bool)), _view, SLOT(setEnabled(bool)));
  connect(_new,   SIGNAL(clicked()), this, SLOT(sNew()));
  connect(_print, SIGNAL(clicked()), this, SLOT(sPrint()));
  connect(_view,  SIGNAL(clicked()), this, SLOT(sView()));

  _incidentSeverities->addColumn(tr("Order"),  _seqColumn, Qt::AlignRight, true, "incdtseverity_order");
  _incidentSeverities->addColumn(tr("Severity"),      100, Qt::AlignLeft, true, "incdtseverity_name" );
  _incidentSeverities->addColumn(tr("Description"),    -1, Qt::AlignLeft, true, "incdtseverity_descrip" );


  if (_privileges->check("MaintainIncidentSeverities"))
  {
    connect(_incidentSeverities, SIGNAL(valid(bool)), _edit, SLOT(setEnabled(bool)));
    connect(_incidentSeverities, SIGNAL(valid(bool)), _delete, SLOT(setEnabled(bool)));
    connect(_incidentSeverities, SIGNAL(itemSelected(int)), _edit, SLOT(animateClick()));
  }
  else
  {
    _new->setEnabled(false);
    connect(_incidentSeverities, SIGNAL(itemSelected(int)), _view, SLOT(animateClick()));
  }

  sFillList();
}

incidentSeverities::~incidentSeverities()
{
    // no need to delete child widgets, Qt does it all for us
}

void incidentSeverities::languageChange()
{
    retranslateUi(this);
}

void incidentSeverities::sFillList()
{
  XSqlQuery incidentFillList;
  incidentFillList.prepare( "SELECT incdtseverity_id, incdtseverity_order, "
	     "       incdtseverity_name, firstLine(incdtseverity_descrip) AS incdtseverity_descrip "
             "FROM incdtseverity "
             "ORDER BY incdtseverity_order, incdtseverity_name;" );
  incidentFillList.exec();
  if (incidentFillList.lastError().type() != QSqlError::NoError)
  {
    systemError(this, incidentFillList.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
  _incidentSeverities->populate(incidentFillList);
}

void incidentSeverities::sDelete()
{
  XSqlQuery incidentDelete;
  incidentDelete.prepare( "DELETE FROM incdtseverity "
             "WHERE (incdtseverity_id=:incdtseverity_id);" );
  incidentDelete.bindValue(":incdtseverity_id", _incidentSeverities->id());
  incidentDelete.exec();
  if (incidentDelete.lastError().type() != QSqlError::NoError)
  {
    systemError(this, incidentDelete.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }

  sFillList();
}

void incidentSeverities::sNew()
{
  ParameterList params;
  params.append("mode", "new");

  incidentSeverity newdlg(this, "", true);
  newdlg.set(params);

  if (newdlg.exec() != XDialog::Rejected)
    sFillList();
}

void incidentSeverities::sEdit()
{
  ParameterList params;
  params.append("mode", "edit");
  params.append("incdtseverity_id", _incidentSeverities->id());

  incidentSeverity newdlg(this, "", true);
  newdlg.set(params);

  if (newdlg.exec() != XDialog::Rejected)
    sFillList();
}

void incidentSeverities::sView()
{
  ParameterList params;
  params.append("mode", "view");
  params.append("incdtseverity_id", _incidentSeverities->id());

  incidentSeverity newdlg(this, "", true);
  newdlg.set(params);
  newdlg.exec();
}

void incidentSeverities::sPopulateMenu( QMenu *pMenu)
{
  QAction *menuItem;

  menuItem = pMenu->addAction(tr("Edit..."), this, SLOT(sEdit()));
  menuItem->setEnabled(_privileges->check("MaintainIncidentSeverities"));

  menuItem = pMenu->addAction(tr("View..."), this, SLOT(sView()));

  menuItem = pMenu->addAction(tr("Delete"), this, SLOT(sDelete()));
  menuItem->setEnabled(_privileges->check("MaintainIncidentSeverities"));
}

void incidentSeverities::sPrint()
{
  orReport report("IncidentSeveritiesList");
  if (report.isValid())
    report.print();
  else
    report.reportError(this);
}