162{
163 if(dynamic_cast<QListWidget*>(Target)) {
164 auto decode = [
this] (
const QMimeData *
const data) -> QPair<bool, QStringList>
165 {
166 bool allGood = true;
167 QStringList newItems;
168
169 if(
data->hasFormat(
"application/vnd.text.list") ==
true) {
170 QByteArray encodedData =
data->data(
"application/vnd.text.list");
171 QDataStream stream(&encodedData, QIODevice::ReadOnly);
172
174
175 while(!stream.atEnd()) {
176 QStringList text;
177 stream >> text;
178
179 const QString& obj_id = text.at(0);
180 const QString& obj_class = text.at(1);
181
182 if((obj_class.toStdString() == referenceClass) ||
184 {
185 newItems.append(obj_id);
186 } else {
187 allGood = false;
188 }
189 }
190 } else {
191 allGood = false;
192 }
193
194 return qMakePair(allGood, newItems);
195 };
196
197 if(Event->type() == QEvent::DragEnter) {
198 QDragEnterEvent *tDropEvent = static_cast<QDragEnterEvent *>(Event);
199
200 const QMimeData *
const data = tDropEvent->mimeData();
201 const auto& decodedData = decode(data);
202 if((decodedData.first == true) && (decodedData.second.size() > 0)) {
203 tDropEvent->acceptProposedAction();
204 }
205
206 return true;
207 }
208
209 if(Event->type() == QEvent::Drop) {
210 QDropEvent *tDropEvent = static_cast<QDropEvent *>(Event);
211
212 const QMimeData *
const data = tDropEvent->mimeData();
213 for(const QString& o : decode(data).second) {
214
216 }
217
218 tDropEvent->acceptProposedAction();
219
220 return true;
221 }
222 } else if(QComboBox * Box = dynamic_cast<QComboBox *>(Target)) {
223 if(Event->type() == QEvent::Wheel) {
224 return true;
225 }
226
227 if(Event->type() == QEvent::KeyPress) {
228 QKeyEvent * KeyEvent = dynamic_cast<QKeyEvent *>(Event);
229
230 if(KeyEvent->key() == Qt::Key_Up || KeyEvent->key() == Qt::Key_Down) {
231 return true;
232 } else {
233 return false;
234 }
235 }
236
237 if(Event->type() == QEvent::FocusOut) {
238 QWidget * popup = Box->findChild<QFrame *>();
239 QWidget * popup1 = Box->lineEdit()->findChild<QFrame *>();
240
241 if(popup != popup1 and not popup->isHidden()) {
242 return true;
243 }
244
247 FirstItem =
new QListWidgetItem(
"Type here");
248 } else {
250 FirstItem =
new QListWidgetItem(
"No Object");
251 } else {
253 }
254 }
255
257
259 FirstItem->setBackground(Qt::GlobalColor::lightGray);
260 FirstItem->setForeground(QColor(0, 0, 0, 127));
261 }
262
264 }
else if(
FirstItem->listWidget() == ListWidget && ListWidget->itemWidget(
FirstItem) != 0) {
265 ListWidget->takeItem(ListWidget->row(
FirstItem));
266 ListWidget->setItemWidget(
FirstItem,
nullptr);
268
270 FirstItem =
new QListWidgetItem(
"Type here");
271 } else {
273 FirstItem =
new QListWidgetItem(
"No Object");
274 } else {
276 }
277 }
278
280
282 FirstItem->setBackground(Qt::GlobalColor::lightGray);
283 FirstItem->setForeground(QColor(0, 0, 0, 127));
284 }
285
287 }
288
289 return false;
290 }
291 } else if(QLineEdit* le = dynamic_cast<QLineEdit *>(Target)) {
292 if(Event->type() == QEvent::MouseButtonDblClick) {
293 const QString& value = le->text();
294
295
296 if((value.isEmpty() == false) && (value != "Type here") && (value != "No Object")) {
298 return false;
299 }
300 }
301 }
302
303 return false;
304}
static bool derived(std::string const &fromclass, std::string const &aclass)