File: CSVInputDialog.C

package info (click to toggle)
ball 1.4.3~beta1-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 318,984 kB
  • sloc: cpp: 346,579; ansic: 4,097; python: 2,664; yacc: 1,778; lex: 1,099; xml: 964; sh: 688; sql: 316; awk: 118; makefile: 108
file content (139 lines) | stat: -rw-r--r-- 4,096 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
#include <CSVInputDialog.h>
#include <BALL/QSAR/exception.h>
#include <QtGui/QMessageBox>
#include <QtGui/QPushButton>

using namespace BALL::QSAR;

namespace BALL
{
	namespace VIEW
	{

		CSVInputDialog::CSVInputDialog(CSVInputDataItem* item):
			input_ok_(false),
			input_item_(item)
		{
			layout_ = new QGridLayout(this);
			QString tmp; tmp.setNum(1);
			activity_edit_ = new QLineEdit(tmp);
			
			separator_box_ = new QComboBox;
			separator_box_->addItem("comma",0);
			separator_box_->addItem("tabulator",1);
			separator_box_->addItem("semicolon",2);
			separator_box_->addItem("space",3);
			
			x_labels_ = new QCheckBox("File contains descriptor names", this);
			y_labels_ = new QCheckBox("File contains compound names", this);
			class_names_checkbox_ = new QCheckBox("non-numeric class names",this);
			center_descriptor_values_ = new QCheckBox("Center descriptor values", this);
			center_descriptor_values_->setChecked(true);
			center_response_values_ = new QCheckBox("Center response values",this);
			center_response_values_->setChecked(true);
			QDialogButtonBox* inputDialogButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,Qt::Horizontal, this);

			QString message_string = "Number of response variables:<br>(assumed to be located in last columns)";
			QString sep_string = "Character used as seperator<br>within the csv-file:";

			alabel_ = new QLabel(message_string,this);
			blabel_ = new QLabel(sep_string,this);
			layout_->addWidget(alabel_,1,1,3,3); layout_->addWidget(activity_edit_,3,4); 
			layout_->addWidget(blabel_,4,1,2,3); layout_->addWidget(separator_box_,4,4);
			layout_->addWidget(x_labels_,6,1,Qt::AlignLeft);
			layout_->addWidget(y_labels_,7,1,Qt::AlignLeft);
			layout_->addWidget(class_names_checkbox_,8,1,Qt::AlignLeft);
			layout_->addWidget(center_descriptor_values_,9,1,Qt::AlignLeft);
			layout_->addWidget(center_response_values_,10,1,Qt::AlignLeft);;
			layout_->addWidget(inputDialogButtons,11,1,1,2, Qt::AlignHCenter);
			
			setLayout(layout_);
			setWindowTitle("Preferences for " + input_item_->name());

			connect(inputDialogButtons, SIGNAL(accepted()), this, SLOT(accept()));
			connect(inputDialogButtons, SIGNAL(rejected()), this, SLOT(reject()));
			connect(class_names_checkbox_,SIGNAL(clicked()),this,SLOT(classNamesChange()));
		}

		CSVInputDialog::~CSVInputDialog()
		{
			delete separator_box_;
			delete activity_edit_;
			delete x_labels_;
			delete y_labels_;
			delete center_descriptor_values_;
			delete center_response_values_;
			delete layout_;
			delete alabel_;
			delete blabel_;
		}


		// SLOT
		void CSVInputDialog::classNamesChange()
		{
			if(class_names_checkbox_->isChecked())
			{
				center_response_values_->setChecked(0);
				center_response_values_->setEnabled(0);
			}
			else
			{
				center_response_values_->setEnabled(1);
			}
		}	


		void CSVInputDialog::readNumY()
		{
			QString input = activity_edit_->text().trimmed();
			QString sep = separator_box_->currentText().trimmed();
			if(sep=="tabulator") sep="	";
			else if(sep=="comma") sep=",";
			else if(sep=="semicolon") sep=";";
			else if(sep=="space") sep=" ";

			bool ok;
			int num = 0;
			num = input.toInt(&ok);
			if (ok && num >= 0)
			{	
				no_y_ = num;
				input_ok_ = true;
			}
			else 
			{	
				input_ok_ = false;
				throw BALL::QSAR::Exception::InvalidActivityID(__FILE__,__LINE__);
			}

			input_item_->setCenterDataFlag(center_descriptor_values_->isChecked());
			input_item_->setCenterResponseFlag(center_response_values_->isChecked());
			input_item_->setXLabelFlag(x_labels_->isChecked());
			input_item_->setYLabelFlag(y_labels_->isChecked());
			input_item_->setNumOfActivities(no_y_);
			input_item_->setSeperator(sep.toStdString());
			input_item_->setNonNumericClassNames(class_names_checkbox_->isChecked());
		}

		bool CSVInputDialog::xLabels()
		{
			return x_labels_;
		}

		bool CSVInputDialog::yLabels()
		{
			return y_labels_;
		}

		bool CSVInputDialog::inputOk()
		{
			return input_ok_;
		}

		int CSVInputDialog::numberOfActivities()
		{
			return no_y_;
		}
	}
}