File: rowcontroller.cpp

package info (click to toggle)
csvimp 0.4.7-2~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 1,164 kB
  • sloc: cpp: 7,182; sh: 356; makefile: 13
file content (140 lines) | stat: -rw-r--r-- 3,821 bytes parent folder | download | duplicates (2)
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
/*
 * This file is part of the xTuple ERP: PostBooks Edition, a free and
 * open source Enterprise Resource Planning software suite,
 * Copyright (c) 1999-2009 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 "rowcontroller.h"

#include <QComboBox>
#include <QSpinBox>
#include <QTableWidget>
#include <QTableWidgetItem>

RowController::RowController(QTableWidget *table, int row, QObject *parent, const char * name)
  : QObject(parent)
{
  setObjectName(name ?
                name : QString("_rowController%1").arg(row).toAscii().data());
  _row = row;
  _action = 0;
  _column = 0;
  _ifNull = 0;
  _altColumn = 0;
  _altIfNull = 0;
  _altValue = 0;
  connect(table, SIGNAL(cellChanged(int, int)), this, SLOT(valueChanged(int, int)));
}

RowController::~RowController()
{
  _row = 0;
  _action = 0;
  _column = 0;
  _ifNull = 0;
  _altColumn = 0;
  _altIfNull = 0;
  _altValue = 0;
}

void RowController::setAction(QComboBox *combo)
{
  _action = combo;
  connect(_action, SIGNAL(currentIndexChanged(int)), this, SLOT(finishSetup()));
}

void RowController::setColumn(QSpinBox *spinner)
{
  _column = spinner;
  connect(_column, SIGNAL(valueChanged(int)), this, SLOT(finishSetup()));
}

void RowController::setIfNull(QComboBox *combo)
{
  _ifNull = combo;
  connect(_ifNull, SIGNAL(currentIndexChanged(int)), this, SLOT(finishSetup()));
}

void RowController::setAltColumn(QSpinBox *spinner)
{
  _altColumn = spinner;
  connect(_altColumn, SIGNAL(valueChanged(int)), this, SLOT(finishSetup()));
}

void RowController::setAltIfNull(QComboBox *combo)
{
  _altIfNull = combo;
  connect(_altIfNull, SIGNAL(currentIndexChanged(int)), this, SLOT(finishSetup()));
}

void RowController::setAltValue(QTableWidgetItem *item)
{
  _altValue = item;
}

void RowController::finishSetup()
{
  if(!(_action && _column && _ifNull && _altColumn && _altIfNull && _altValue))
  {
    qDebug("RowController::finishSetup() called when not all values set.");
    return;
  }

  QString str = _action->currentText();
  if(str == "Default" || str == "UseEmptyString" || str == "UseNull")
  {
    _column->setEnabled(FALSE);
    _ifNull->setEnabled(FALSE);
    _altColumn->setEnabled(FALSE);
    _altIfNull->setEnabled(FALSE);
    _altValue->setFlags(_altValue->flags() & (~ Qt::ItemIsEditable));
  }
  else if(str == "UseColumn")
  {
    _column->setEnabled(TRUE);
    _ifNull->setEnabled(TRUE);

    str = _ifNull->currentText();
    if(str == "Nothing" || str == "UseDefault" || str == "UseEmptyString")
    {
      _altColumn->setEnabled(FALSE);
      _altIfNull->setEnabled(FALSE);
      _altValue->setFlags(_altValue->flags() & (~ Qt::ItemIsEditable));
    }
    else if(str == "UseAlternateValue")
    {
      _altColumn->setEnabled(FALSE);
      _altIfNull->setEnabled(FALSE);
      _altValue->setFlags(_altValue->flags() | Qt::ItemIsEditable);
    }
    else if(str == "UseAlternateColumn")
    {
      _altColumn->setEnabled(TRUE);
      _altIfNull->setEnabled(TRUE);

      str = _altIfNull->currentText();
      if(str == "UseAlternateValue")
        _altValue->setFlags(_altValue->flags() | Qt::ItemIsEditable);
      else
        _altValue->setFlags(_altValue->flags() & (~ Qt::ItemIsEditable));
    }
  }
  else if(str == "UseAlternateValue")
  {
    _column->setEnabled(FALSE);
    _ifNull->setEnabled(FALSE);
    _altColumn->setEnabled(FALSE);
    _altIfNull->setEnabled(FALSE);
    _altValue->setFlags(_altValue->flags() | Qt::ItemIsEditable);
  }
}

void RowController::valueChanged(int row, int col)
{
  if(row == _row && (col == 4 || col == 6 || col == 8))
    finishSetup();
}