BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
DesignerMimeData Class Reference

Mime data for use with SampleDesigner drag and drop operations. More...

Inheritance diagram for DesignerMimeData:
[legend]
Collaboration diagram for DesignerMimeData:
[legend]

Public Member Functions

 DesignerMimeData (const QString &name, const QString &xmldescr, QDrag *drag)
 
virtual ~DesignerMimeData ()
 
QString getClassName () const
 

Static Public Member Functions

static Qt::DropAction execDrag (const QString &name, const QString &xmldescr, QWidget *dragSource)
 Execute a drag and drop operation. More...
 

Private Member Functions

QPixmap getPixmap (const QString &name)
 
void read_widget (QXmlStreamReader &reader)
 
void read_xmldescr (const QString &xmldescr)
 

Private Attributes

QString m_classname
 
QString m_entryname
 
QString m_xmldescr
 

Detailed Description

Mime data for use with SampleDesigner drag and drop operations.

Definition at line 24 of file DesignerMimeData.h.

Constructor & Destructor Documentation

◆ DesignerMimeData()

DesignerMimeData::DesignerMimeData ( const QString &  name,
const QString &  xmldescr,
QDrag *  drag 
)

Definition at line 31 of file DesignerMimeData.cpp.

32  : m_entryname(entryname), m_xmldescr(xmldescr)
33 {
34  drag->setMimeData(this);
35 
37 
38  QByteArray itemData;
39  QDataStream dataStream(&itemData, QIODevice::WriteOnly);
40  dataStream << xmldescr;
41  setData("bornagain/widget", itemData);
42 
43  drag->setPixmap(getPixmap(m_classname));
44  drag->setHotSpot(QPoint(drag->pixmap().width() / 2, drag->pixmap().height() / 2));
45 }
void read_xmldescr(const QString &xmldescr)
QPixmap getPixmap(const QString &name)

References getPixmap(), m_classname, m_xmldescr, and read_xmldescr().

Referenced by execDrag().

Here is the call graph for this function:

◆ ~DesignerMimeData()

virtual DesignerMimeData::~DesignerMimeData ( )
inlinevirtual

Definition at line 28 of file DesignerMimeData.h.

28 {}

Member Function Documentation

◆ execDrag()

Qt::DropAction DesignerMimeData::execDrag ( const QString &  name,
const QString &  xmldescr,
QWidget *  dragSource 
)
static

Execute a drag and drop operation.

Definition at line 91 of file DesignerMimeData.cpp.

93 {
94  if (xmldescr.size() == 0)
95  return Qt::IgnoreAction;
96 
97  QDrag* drag = new QDrag(dragSource);
98  DesignerMimeData* mimeData = new DesignerMimeData(name, xmldescr, drag);
99  Q_UNUSED(mimeData);
100 
101  const Qt::DropAction executedAction = drag->exec(Qt::CopyAction);
102 
103  return executedAction;
104 }
Mime data for use with SampleDesigner drag and drop operations.
DesignerMimeData(const QString &name, const QString &xmldescr, QDrag *drag)
QString const & name(EShape k)
Definition: particles.cpp:21

References DesignerMimeData(), and RealSpace::Particles::name().

Referenced by qdesigner_internal::WidgetBox::handleMousePress().

Here is the call graph for this function:

◆ getClassName()

QString DesignerMimeData::getClassName ( ) const
inline

◆ getPixmap()

QPixmap DesignerMimeData::getPixmap ( const QString &  name)
private

Definition at line 106 of file DesignerMimeData.cpp.

107 {
109 }
static QPixmap getMimePixmap(const QString &name)
returns Mime pixmap for givew IView name

References DesignerHelper::getMimePixmap(), and RealSpace::Particles::name().

Referenced by DesignerMimeData().

Here is the call graph for this function:

◆ read_widget()

void DesignerMimeData::read_widget ( QXmlStreamReader &  reader)
private

Definition at line 77 of file DesignerMimeData.cpp.

78 {
79  for (const QXmlStreamAttribute& attribute : reader.attributes()) {
80  QStringRef name = attribute.name();
81  if (name == "class") {
82  m_classname = attribute.value().toString();
83  continue;
84  }
85  reader.raiseError("Unexpected attribute " + name.toString());
86  }
87  reader.skipCurrentElement();
88 }

References m_classname, and RealSpace::Particles::name().

Referenced by read_xmldescr().

Here is the call graph for this function:

◆ read_xmldescr()

void DesignerMimeData::read_xmldescr ( const QString &  xmldescr)
private

Definition at line 47 of file DesignerMimeData.cpp.

48 {
49  QXmlStreamReader reader(xmldescr);
50 
51  bool widget_found = false;
52  while (!reader.atEnd()) {
53  if (reader.readNext() == QXmlStreamReader::StartElement) {
54  const QStringRef name = reader.name();
55  if (widget_found)
56  reader.raiseError("Unexpected element <" + name.toString() + ">");
57  if (name.compare(QStringLiteral("widget"), Qt::CaseInsensitive) == 0)
58  read_widget(reader);
59  else
60  reader.raiseError("Unexpected element <" + name.toString() + ">");
61  }
62  }
63  if (reader.hasError()) {
64  QString errorMessage = tr("A parse error occurred at line %1, column %2 of the XML code "
65  "specified for the widget %3: %4\n%5")
66  .arg(reader.lineNumber())
67  .arg(reader.columnNumber())
68  .arg(m_entryname)
69  .arg(reader.errorString())
70  .arg(xmldescr);
71  std::cout << "DesignerMimeData::read_xmldescr() -> Error during parse." << std::endl;
72  std::cout << errorMessage.toStdString() << std::endl;
73  }
74 }
#define QStringLiteral
void read_widget(QXmlStreamReader &reader)

References m_entryname, RealSpace::Particles::name(), QStringLiteral, and read_widget().

Referenced by DesignerMimeData().

Here is the call graph for this function:

Member Data Documentation

◆ m_classname

QString DesignerMimeData::m_classname
private

Definition at line 44 of file DesignerMimeData.h.

Referenced by DesignerMimeData(), getClassName(), and read_widget().

◆ m_entryname

QString DesignerMimeData::m_entryname
private

Definition at line 42 of file DesignerMimeData.h.

Referenced by read_xmldescr().

◆ m_xmldescr

QString DesignerMimeData::m_xmldescr
private

Definition at line 43 of file DesignerMimeData.h.

Referenced by DesignerMimeData().


The documentation for this class was generated from the following files: