File: inputDataItem.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 (208 lines) | stat: -rw-r--r-- 4,375 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/* TRANSLATOR BALL::QSAR

		Necessary for lupdate.
*/

#include <inputDataItem.h>
#include <mainWindow.h>

#include <BALL/QSAR/exception.h>
#include <exception.h>
#include <inputPlotter.h>

#include <QtGui/QDialog>
#include <QtGui/QDrag>
#include <QtCore/QMimeData>
#include <QtGui/QApplication>
#include <QtGui/QMessageBox>


using namespace BALL::QSAR;
using namespace BALL::Exception;
using namespace BALL::QSAR::Exception;

namespace BALL
{
	namespace VIEW
	{

		InputDataItem::InputDataItem(QString filename, bool center_data, bool center_y, DataItemView* view):
			DataItem(view),
			filename_(filename),
			center_data_(center_data),
			center_y_(center_y)
		{
			data_ = new QSARData;
			input_plotter_ = NULL;
			append_ = 0;
			checked_for_discrete_y_ = 0;
			discrete_y_ = 0;
			partitioner_IDs_.clear();
			createActions();
		}

		InputDataItem::InputDataItem(QString filename, DataItemView* view): 
			DataItem(view),
			data_(NULL),
			filename_(filename)
		{
			input_plotter_ = NULL;
			append_ = 0;
			checked_for_discrete_y_ = 0;
			discrete_y_ = 0;
			partitioner_IDs_.clear();
			createActions();
		}

		InputDataItem::InputDataItem():
			DataItem(NULL),
			data_(NULL),
			filename_(""),
			center_data_(false),
			center_y_(false)
		{
			input_plotter_ = NULL;
			append_ = 0;
			checked_for_discrete_y_ = 0;
			discrete_y_ = 0;
			partitioner_IDs_.clear();
			createActions();
		}

		InputDataItem::~InputDataItem()
		{
			if(!append_) delete data_;
			delete input_plotter_;
		}

		InputDataItem::InputDataItem(InputDataItem& item):
			DataItem(item.view_)
		{
			data_ = new QSARData(*item.data_) ;
			filename_ = item.filename_;
			center_data_ = item.center_data_;
			center_y_ = item.center_data_;
			name_ = item.name_;
			setPixmap(item.pixmap());
			center_data_ = item.center_data_;
			center_y_ = item.center_data_;
			input_plotter_ = item.input_plotter_;
			append_ = item.append_;
			checked_for_discrete_y_ = item.checked_for_discrete_y_;
			discrete_y_ = item.discrete_y_;
			partitioner_IDs_ = item.partitioner_IDs_;
			createActions();
		}


		QSARData* InputDataItem::data()
		{
			return data_;
		}


		QString InputDataItem::filename()
		{
			return filename_;
		}


		bool InputDataItem::centerData()
		{
			return center_data_;
		}

		bool InputDataItem::centerY()
		{
			return center_y_;
		}

		void InputDataItem::setCenterDataFlag(bool cd)
		{
			center_data_ = cd;
		}

		void InputDataItem::setCenterResponseFlag(bool cr)
		{
			center_y_ = cr;
		}

		void InputDataItem::setData(QSARData* data)
		{
			data_ = data;
		}

		void InputDataItem::loadFromFile(String file)
		{
			try
			{
				if(data_==NULL)
				{
					//throw BALL::Exception::GeneralException(__FILE__,__LINE__,"InputDataItem error","InputDataItem not connected to a QSARData object!!");		
					data_ = new QSARData;
				}
				data_->readFromFile(file);
			}
			catch(WrongDataType e)
			{
				QMessageBox::warning(view_,"Error",e.getMessage());
				return;
			}
			done_ = 1;
		}

		void InputDataItem::showPlotter()
		{
			if(data_==0 || data_->getNoSubstances()==0)
			{
				QMessageBox::information(view_,"No data","Data must be read before it can be plotted!\nTherefore, click \"Execute Pipeline\" first.");
				return;	
			}
			if(data_->getNoResponseVariables()==0)
			{
				QMessageBox::information(view_,"No response variable", "This input data does not contain a response variable, so that plotting of the response values is not possible.");
				return;
			}
			
			if(input_plotter_ == NULL)
			{
				input_plotter_=new InputPlotter(this);
			}
			input_plotter_->show();
		}

		void InputDataItem::setAppend(bool append)
		{
			append_ = append;
		}

		bool InputDataItem::append()
		{
			return append_;
		}

		BALL::String InputDataItem::getMouseOverText()
		{
			String s="";
			if(data_!=NULL)
			{
				if(data_->getNoSubstances()>0)
				{
					s=String(data_->getNoSubstances())+" compounds\n";
					s+=String(data_->getNoDescriptors())+" features\n";
					int no_y=data_->getNoResponseVariables();
					s+=String(no_y)+" response variable";
					if(no_y!=1) s+="s";
				}
			}
			return s;
		}

		void InputDataItem::createActions()
		{
			QAction* plot_action = new QAction(QIcon(""),tr("Plot data"), this);
			connect(plot_action, SIGNAL(triggered()), this, SLOT(showPlotter()));
			context_menu_actions_.push_back(plot_action);
		}
	}
}