swift
dropbase.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #include "gui/dropbase.h"
5 
6 #include <QMetaType>
7 #include <QUrl>
8 #include <QtGlobal>
9 
10 #include "gui/guiutility.h"
11 
12 using namespace swift::misc;
13 
14 namespace swift::gui
15 {
16  CDropBase::CDropBase() {}
17 
18  CDropBase::~CDropBase() {}
19 
20  void CDropBase::setAcceptedMetaTypeIds(const QList<int> &ids) { m_acceptedMetaTypes = ids; }
21 
22  void CDropBase::addAcceptedMetaTypeId(int id) { m_acceptedMetaTypes.append(id); }
23 
24  bool CDropBase::acceptDrop(const QMimeData *mime) const
25  {
26  if (!mime) { return false; }
27  if (!m_allowDrop) { return false; }
28  if (m_acceptedMetaTypes.isEmpty()) { return false; }
29 
30  if (m_acceptJsonFile && CGuiUtility::isMimeRepresentingReadableJsonFile(mime))
31  {
32  // further checks could go here
33  return true;
34  }
35 
36  if (!CGuiUtility::hasSwiftVariantMimeType(mime)) { return false; }
37  const int metaTypeId = CGuiUtility::metaTypeIdFromSwiftDragAndDropData(mime);
38  if (metaTypeId == QMetaType::UnknownType) { return false; }
39  const bool accept = m_acceptedMetaTypes.contains(metaTypeId);
40  return accept;
41  }
42 
43  CVariant CDropBase::toCVariant(const QMimeData *mime) const { return CGuiUtility::fromSwiftDragAndDropData(mime); }
44 } // namespace swift::gui
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
Definition: variant.h:66
GUI related classes.
Free functions in swift::misc.