void Drop::dropEvent(QDropEvent *event) { if (!m_data->widget) return; const std::string str = event->mimeData()->text().toStdString(); try { TypeDescriptor_ptr descriptor = m_data->widget->getReflective(); Holder holder = descriptor->create_holder(); bool res = json::parse(descriptor, holder, str.c_str(), str.size()); if (res && m_data->widget) { m_data->widget->fromHolder(holder); event->acceptProposedAction(); } } catch(...) { // parse exception: nothing to do } }
EnumWidget::EnumWidget(TypeDescriptor_ptr reflective, QWidget * parent) : QComboBox(parent), ReflectiveWidgetBase(reflective) { assert(reflective->is_enum()); unsigned int count = reflective->get_children_count(); for (unsigned int i = 0; i < count; i++) { addItem(reflective->get_child_name(i)); } }
TypeDescriptor_ptr followPath( TypeDescriptor_ptr message, const ReflectivePath_t& path) { TypeDescriptor_ptr res = message; ReflectivePath_t::const_iterator it = path.begin(); for (; it != path.end() && res; ++it) { res = res->get_child(*it); } return res; }
BCDWidget::BCDWidget(TypeDescriptor_ptr reflective, QWidget * parent) : IntegerWidget(reflective, parent) { using namespace gsim::core; const descriptor_type type = reflective->get_type(); switch(type) { case TYPE_OCTET: setRange(0, max_bcd< unsigned char >()); break; case TYPE_USHORT: setRange(0, max_bcd< unsigned short >()); break; case TYPE_ULONG: setRange(0, max_bcd< uint32_t >()); break; case TYPE_ULONGLONG: setRange(0, max_bcd< uint64_t >()); break; default: break; } }
UnionWidget::UnionWidget( TypeDescriptor_ptr reflective, WidgetFactory_t factory, QWidget * parent) : QWidget(parent), ReflectiveWidgetBase(reflective) { assert(reflective->get_type() == core::TYPE_UNION); QGridLayout * layout = new QGridLayout(this); unsigned int count = reflective->get_children_count(); m_widgets.resize(count, NULL); // discriminator { const char * child_name = reflective->get_child_name(0); core::reflective_base const * child = reflective->get_child(0); QWidget * child_widget = factory(child, this); child_widget->setObjectName(child_name); m_widgets[0] = dynamic_cast< ReflectiveWidgetBase* >(child_widget); child_widget->setObjectName(child_name); layout->addWidget(new QLabel(child_name), 0, 0); layout->addWidget(child_widget, 0, 1); if (qobject_cast< QComboBox * >(child_widget)) { connect(child_widget, SIGNAL(currentIndexChanged(int)), this, SLOT(discriminatorChanged())); } else if (qobject_cast< QSpinBox * >(child_widget)) { connect(child_widget, SIGNAL(valueChanged(int)), this, SLOT(discriminatorChanged())); } else if (qobject_cast< QDoubleSpinBox * >(child_widget))
StringWidget::StringWidget(TypeDescriptor_ptr reflective, QWidget * parent) : QLineEdit(parent), ReflectiveWidget(reflective) { using namespace gsim::core; bool array = reflective->get_type() == TYPE_ARRAY && reflective->get_slice()->get_type() == TYPE_CHAR; assert(reflective->get_type() == TYPE_STRING || array); if (array) { Holder dummy; unsigned length = reflective->get_length(dummy); setMaxLength((int) length); } }
BitSetWidget::BitSetWidget(TypeDescriptor_ptr reflective, const QString& tags, QWidget * parent) : FormWidget(parent), ReflectiveWidget(reflective) { const QStringList tagList (tags.split(';')); setBigWidget(true); using namespace gsim::core; const descriptor_type type = reflective->get_type(); int bits = 0; switch(type) { case TYPE_OCTET: case TYPE_CHAR: bits = 8; break; case TYPE_SHORT: case TYPE_USHORT: bits = 16; break; case TYPE_LONG: case TYPE_ULONG: bits = 32; break; case TYPE_LONGLONG: case TYPE_ULONGLONG: bits = 64; break; default: break; } for (int i = 0; i < bits; i++) { const QString tag = ((i < tagList.size() && !tagList.at(i).isEmpty())? tagList.at(i): QString::number(i)); QCheckBox * sp = new QCheckBox(); addField(tag, sp); m_spinBoxes.push_back(sp); connect(sp, SIGNAL(stateChanged(int)), this, SIGNAL(editingFinished())); } }
void Drag::mouseMoveEvent(QMouseEvent *event) { if (!m_data->widget) return; if (!(event->buttons() & Qt::LeftButton)) return; if ((event->globalPos() - m_data->dragStartPosition).manhattanLength() < QApplication::startDragDistance()) return; TypeDescriptor_ptr descriptor = m_data->widget->getReflective(); Holder holder (descriptor->create_holder()); m_data->widget->toHolder(holder); if (core::utils::calculate_size(holder) < GSIM_DRAG_MAX_SIZE) { QDrag * drag = new QDrag(m_data->qwidget); QMimeData * mimeData = new QMimeData; std::ostringstream oss; json::write(oss, descriptor, holder); mimeData->setText(oss.str().c_str()); drag->setMimeData(mimeData); /* Qt::DropAction dropAction = */ drag->exec(Qt::CopyAction); } else { QMessageBox::information(m_data->qwidget, "Information", "Drag events have been disabled for performance reasons."); } }
bool followPath( TypeDescriptor_ptr message, Holder holder, const ReflectivePath_t& path, TypeDescriptor_ptr& descriptor, Holder& value) { value = holder; descriptor = message; ReflectivePath_t::const_iterator it = path.begin(); for (; it != path.end() && descriptor; ++it) { if (descriptor->is_variable_length()) return false; value = descriptor->get_child_value(value, *it); descriptor = descriptor->get_child(*it); } // valid if descriptor not null return (descriptor); }
StructWidget::StructWidget( TypeDescriptor_ptr reflective, WidgetFactory_t factory, QWidget * parent) : qt::FormWidget(parent), ReflectiveWidgetBase(reflective) { assert(reflective->get_type() == core::TYPE_STRUCT); unsigned int count = reflective->get_children_count(); m_widgets.resize(count, NULL); for (unsigned int i = 0; i < count; i++) { core::reflective_base const * child = reflective->get_child(i); const char * child_name = reflective->get_child_name(i); QWidget * child_widget = factory(child, this); m_widgets[i] = dynamic_cast< ReflectiveWidgetBase* >( child_widget); child_widget->setObjectName(child_name); if (child->is_primitive() || child->is_enum()) { addField(child_name, child_widget); } else { addBigField(child_name, child_widget); } } }
IntegerWidget::IntegerWidget(TypeDescriptor_ptr reflective, QWidget * parent) : QSpinBox(parent), ReflectiveWidgetBase(reflective) { using namespace corbasim::core; const reflective_type type = reflective->get_type(); switch(type) { case TYPE_OCTET: setRange(std::numeric_limits< unsigned char >::min(), std::numeric_limits< unsigned char >::max()); break; case TYPE_CHAR: setRange(std::numeric_limits< char >::min(), std::numeric_limits< char >::max()); break; case TYPE_SHORT: setRange(std::numeric_limits< short >::min(), std::numeric_limits< short >::max()); break; case TYPE_USHORT: setRange(std::numeric_limits< unsigned short >::min(), std::numeric_limits< unsigned short >::max()); break; case TYPE_LONG: setRange(std::numeric_limits< int32_t >::min(), std::numeric_limits< int32_t >::max()); break; // TODO custom widget case TYPE_ULONG: setRange(std::numeric_limits< uint32_t >::min(), std::numeric_limits< int32_t >::max()); break; case TYPE_LONGLONG: setRange(std::numeric_limits< int32_t >::min(), std::numeric_limits< int32_t >::max()); break; case TYPE_ULONGLONG: setRange(std::numeric_limits< uint32_t >::min(), std::numeric_limits< int32_t >::max()); break; default: break; } }
FloatWidget::FloatWidget(TypeDescriptor_ptr reflective, QWidget * parent) : QDoubleSpinBox(parent), ReflectiveWidgetBase(reflective) { using namespace corbasim::core; setDecimals(10); const reflective_type type = reflective->get_type(); switch(type) { case TYPE_DOUBLE: setRange(-std::numeric_limits< double >::max(), std::numeric_limits< double >::max()); break; case TYPE_FLOAT: setRange(-std::numeric_limits< float >::max(), std::numeric_limits< float >::max()); break; default: break; } }
QString getMessageName(TypeDescriptor_ptr d) { QString res(d->get_type_name().c_str()); res = res.toUpper(); return res; }
void ReflectivePlot::appendValue(Request_ptr req, TypeDescriptor_ptr reflec, Holder hold) { if (reflec->is_primitive()) { m_plot->append(reflec->to_double(hold)); } else if(reflec->is_repeated() && reflec->get_slice()->is_primitive()) { QVector< double > values; const unsigned int length = reflec->get_length(hold); core::reflective_base const * slice = reflec->get_slice(); for (unsigned int i = 0; i < length; i++) { const core::holder h = reflec->get_child_value(hold, i); values.push_back(slice->to_double(h)); } if (!values.isEmpty()) m_plot->append(values); } // N-dimensional types else if(reflec->is_repeated() && reflec->get_slice()->is_repeated()) { unsigned int length = reflec->get_length(hold); for (unsigned int i = 0; i < length; i++) { core::holder h = reflec->get_child_value(hold, i); // Recursive appendValue(req, reflec->get_slice(), h); } } }