File: SDFInputDialog.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 (176 lines) | stat: -rw-r--r-- 5,373 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include <SDFInputDialog.h>
#include <BALL/QSAR/exception.h>
#include <QtGui/QMessageBox>
#include <QtGui/QPushButton>
#include <QtGui/QScrollArea>
#include <QtGui/QTableWidget>
#include <QtGui/QHeaderView>

using namespace BALL::QSAR;

namespace BALL
{
	namespace VIEW
	{

		SDFInputDialog::SDFInputDialog(SDFInputDataItem* item):
			input_ok_(false),
			input_item_(item)
		{
			property_names_ = input_item_->data()->readPropertyNames(String(input_item_->filename().toStdString()));

			QGridLayout* layout = new QGridLayout(this);
			activity_edit_ = new QLineEdit();
			sd_descriptors_checkbox_ = new QCheckBox("use other properties as descriptors", 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* SDFInputDialogButtons= new QDialogButtonBox(QDialogButtonBox::Ok |QDialogButtonBox::Cancel,Qt::Horizontal, this);

			QString tmp;
			QString message_string = QString("This input file contains "+ tmp.setNum(property_names_->size())+ " properties: <br>");

			QStringList labels;
			labels << "ID" <<"Property";

			QTableWidget* table = new QTableWidget(property_names_->size(), 2, this);	
			table->verticalHeader()->hide();
			table->setHorizontalHeaderLabels (labels);
			table->setAlternatingRowColors(true);
			table->setDragDropMode(QAbstractItemView::NoDragDrop);
			table->setEditTriggers(QAbstractItemView::NoEditTriggers);
			table->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
			table->horizontalHeader()->setResizeMode(1,QHeaderView::Stretch); 
			
			for (unsigned int i=0; i< property_names_->size(); i++)
			{
				QTableWidgetItem* id = new QTableWidgetItem("[" + tmp.setNum(i) + "]");
				table->setItem(i, 0, id);	
				QTableWidgetItem* name = new QTableWidgetItem(QString(property_names_->at(i).c_str()));
				table->setItem(i, 1, name);	
			}

			QScrollArea* scrollArea = new QScrollArea(this);
			scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
			scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
			scrollArea->setFrameShape(QFrame::NoFrame);
			scrollArea->setWidget(table);
			scrollArea->setWidgetResizable(true);
			layout->addWidget(scrollArea, 1, 3, 5, 1,Qt::AlignHCenter);

			message_string += "<br> Numbers of properties that are to be used as activities: <br> (comma separated)";

			QLabel* alabel = new QLabel(message_string,this);

			layout->addWidget(alabel,1,1,1,2);
			layout->addWidget(activity_edit_,2,1,1,2);
			layout->addWidget(sd_descriptors_checkbox_,3,1,Qt::AlignLeft);
			layout->addWidget(class_names_checkbox_,4,1,Qt::AlignLeft);
			layout->addWidget(center_descriptor_values_,5,1,Qt::AlignLeft);
			layout->addWidget(center_response_values_,6,1,Qt::AlignLeft);;
			layout->addWidget(SDFInputDialogButtons,7,1,1,2, Qt::AlignHCenter);

			this->setLayout(layout);
			this->setWindowTitle("Preferences for " + input_item_->name());

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


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


		SDFInputDialog::SDFInputDialog():
			activity_edit_(NULL),
			center_descriptor_values_(NULL),
			center_response_values_(NULL)	
		{
		}

		SDFInputDialog::~SDFInputDialog()
		{
			delete activity_edit_;
			delete center_descriptor_values_;
			delete center_response_values_;
		}

		void SDFInputDialog::getNumbers()
		{
			std::vector<QString> invalid_input;
			QString input = activity_edit_->text().trimmed();
			QList<QString> substrings = input.split(",");
			numbers_.clear();

			bool ok;
			int num = 0;
			for (int i = 0; i < substrings.size(); i++)
			{
				num = substrings[i].toInt(&ok);
				if (ok && num >= 0 && num < (int)property_names_->size())
				{	
					numbers_.insert(num);
				}
				else 
				{	
					if (substrings[i] != "")
					{
						invalid_input.push_back(substrings[i]);
					}
				}
			}

			if (invalid_input.empty())
			{
				input_ok_ = true;
			}
			else
			{	
				numbers_.clear();
				input_ok_ = false;
				throw BALL::QSAR::Exception::InvalidActivityID(__FILE__,__LINE__);
			}

			input_item_->useSDProperties(sd_descriptors_checkbox_->isChecked());
			input_item_->setCenterDataFlag(center_descriptor_values_->isChecked());
			input_item_->setCenterResponseFlag(center_response_values_->isChecked());
			input_item_->setActivityValues(numbers_);
			input_item_->setNonNumericClassNames(class_names_checkbox_->isChecked());
		}

		std::multiset<int> SDFInputDialog::numbers()
		{
			return numbers_;
		}

		bool SDFInputDialog::centerDescriptorValues()
		{
			return center_descriptor_values_->isChecked();
		}

		bool SDFInputDialog::centerResponseValues()
		{
			return center_response_values_->isChecked();
		}

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