/*! \return The preferred height for this layout, given the width w. \sa hasHeightForWidth() */ int QwtDynGridLayout::heightForWidth( int width ) const { if ( isEmpty() ) return 0; const uint numCols = columnsForWidth( width ); uint numRows = itemCount() / numCols; if ( itemCount() % numCols ) numRows++; QVector<int> rowHeight( numRows ); QVector<int> colWidth( numCols ); layoutGrid( numCols, rowHeight, colWidth ); int h = 2 * margin() + ( numRows - 1 ) * spacing(); for ( int row = 0; row < ( int )numRows; row++ ) h += rowHeight[row]; return h; }
void BorderLayout::doLayout( const QRect &rct, bool /*testonly*/ ) { int ew = 0, ww = 0, nh = 0, sh = 0; int h = 0; BorderLayoutIterator it( &list ); BorderLayoutStruct *o; BorderLayoutStruct *center = 0; while ( ( o = it.currentStruct() ) != 0 ) { ++it; if ( o->pos == North ) { o->item->setGeometry( QRect( rct.x(), nh, rct.width(), o->item->sizeHint().height() ) ); nh += o->item->geometry().height() + spacing(); } if ( o->pos == South ) { o->item->setGeometry( QRect( o->item->geometry().x(), o->item->geometry().y(), rct.width(), o->item->sizeHint().height() ) ); sh += o->item->geometry().height() + spacing(); o->item->setGeometry( QRect( rct.x(), rct.y() + rct.height() - sh + spacing(), o->item->geometry().width(), o->item->geometry().height() ) ); } if ( o->pos == Center ) center = o; } h = rct.height() - nh - sh; it.toFirst(); while ( ( o = it.currentStruct() ) != 0 ) { ++it; if ( o->pos == West ) { o->item->setGeometry( QRect( rct.x() + ww, nh, o->item->sizeHint().width(), h ) ); ww += o->item->geometry().width() + spacing(); } if ( o->pos == East ) { o->item->setGeometry( QRect( o->item->geometry().x(), o->item->geometry().y(), o->item->sizeHint().width(), h ) ); ew += o->item->geometry().width() + spacing(); o->item->setGeometry( QRect( rct.x() + rct.width() - ew + spacing(), nh, o->item->geometry().width(), o->item->geometry().height() ) ); } } if ( center ) center->item->setGeometry( QRect( ww, nh, rct.width() - ew - ww, h ) ); }
/*! Find the position, where to paint a label The position has a distance of majTickLength() + spacing() + 1 from the backbone. The direction depends on the alignment() \param value Value */ QPoint QwtScaleDraw::labelPosition( double value) const { const int tval = map().transform(value); int dist = spacing() + 1; if ( hasComponent(QwtAbstractScaleDraw::Ticks) ) dist += majTickLength(); int px = 0; int py = 0; switch(alignment()) { case RightScale: { px = d_data->pos.x() + dist; py = tval; break; } case LeftScale: { px = d_data->pos.x() - dist; py = tval; break; } case BottomScale: { px = tval; py = d_data->pos.y() + dist; break; } case TopScale: { px = tval; py = d_data->pos.y() - dist; break; } } return QPoint(px, py); }
int QGraphicsAnchor::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; #ifndef QT_NO_PROPERTIES if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< qreal*>(_v) = spacing(); break; case 1: *reinterpret_cast< QSizePolicy::Policy*>(_v) = sizePolicy(); break; } _id -= 2; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setSpacing(*reinterpret_cast< qreal*>(_v)); break; case 1: setSizePolicy(*reinterpret_cast< QSizePolicy::Policy*>(_v)); break; } _id -= 2; } else if (_c == QMetaObject::ResetProperty) { switch (_id) { case 0: unsetSpacing(); break; } _id -= 2; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 2; } #endif // QT_NO_PROPERTIES return _id; }
int MSToggleButtonBase::computeXCoord(int /*row_*/,int col_,const char *pString_,int len_) { int offset=highlightThickness()+shadowThickness()+margin(); int leftOffset=offset+textHeight()+spacing(); int r=0; if (pString_!=0) { if (alignment()&MSLeft) r=leftOffset+textWidth(pString_,col_); else if (alignment()&MSRight) { int xs=width()-offset-textWidth(pString_,len_); r=xs+textWidth(pString_,col_); } else { int delta=drawWidth()-textWidth(pString_,len_)-leftOffset; delta=(delta>0)?delta>>1:0; r=leftOffset+delta+textWidth(pString_,col_); } } return r; }
int QDeclarativeLinearLayout::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QDeclarativeLayout::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 3) qt_static_metacall(this, _c, _id, _a); _id -= 3; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< qreal*>(_v) = spacing(); break; } _id -= 1; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setSpacing(*reinterpret_cast< qreal*>(_v)); break; } _id -= 1; } else if (_c == QMetaObject::ResetProperty) { _id -= 1; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 1; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 1; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 1; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 1; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 1; } #endif // QT_NO_PROPERTIES return _id; }
void ControlledLayout::setGeometry(const QRect &rect) { if (items.isEmpty()) return; int left, top, right, bottom; getContentsMargins(&left, &top, &right, &bottom); QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom); int TotalWid=0; int CountTapped=0; foreach(QLayoutItem *item,items) { if(!static_cast<CardViewer*>(item->widget())->GetCardToDisplay()) continue; if(static_cast<CardViewer*>(item->widget())->GetCardToDisplay()->IsTapped()) { TotalWid+=item->minimumSize().height(); ++CountTapped; } else TotalWid+=item->minimumSize().width(); } int AvailableWid=effectiveRect.width()-spacing()*(count()-1); int CurrentX=effectiveRect.x(); if (TotalWid>AvailableWid) { //Lay Items One over the other int IncrementOnX=0; if(count()>1) { if(static_cast<CardViewer*>(items.last()->widget())->GetCardToDisplay()) { if(static_cast<CardViewer*>(items.last()->widget())->GetCardToDisplay()->IsTapped()) IncrementOnX=(effectiveRect.width()-items.last()->minimumSize().height())/(count()-1); else IncrementOnX=(effectiveRect.width()-items.last()->minimumSize().width())/(count()-1); } } foreach(QLayoutItem *item,items) { if(!static_cast<CardViewer*>(item->widget())->GetCardToDisplay()) continue; if(static_cast<CardViewer*>(item->widget())->GetCardToDisplay()->IsTapped()) item->setGeometry(QRect(CurrentX,effectiveRect.y(),item->minimumSize().height(),effectiveRect.height())); else item->setGeometry(QRect(CurrentX,effectiveRect.y(),item->minimumSize().width(),effectiveRect.height())); item->widget()->raise(); CurrentX+=IncrementOnX; } }
int QLayout::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; #ifndef QT_NO_PROPERTIES if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< int*>(_v) = margin(); break; case 1: *reinterpret_cast< int*>(_v) = spacing(); break; case 2: *reinterpret_cast< SizeConstraint*>(_v) = sizeConstraint(); break; } _id -= 3; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setMargin(*reinterpret_cast< int*>(_v)); break; case 1: setSpacing(*reinterpret_cast< int*>(_v)); break; case 2: setSizeConstraint(*reinterpret_cast< SizeConstraint*>(_v)); break; } _id -= 3; } else if (_c == QMetaObject::ResetProperty) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 3; } #endif // QT_NO_PROPERTIES return _id; }
//-------------------------------------------------------------- void ofApp::draw() { ofBackgroundGradient(ofColor(64), ofColor(0)); cam.begin(); ofEnableDepthTest(); ofRotateY(ofGetElapsedTimef() * 30); // slowly rotate the model ofScale(1, -1, 1); // make y point down ofScale(.5, .5, .5); // make everything a bit smaller img.bind(); // bind the image to begin texture mapping int n = 5; // make a 5x5 grid ofVec2f spacing(img.getWidth(), img.getHeight()); // spacing between meshes ofTranslate(-spacing.x * n / 2, -spacing.y * n / 2, 0); // center the grid for(int i = 0; i < n; i++) { // loop through the rows for(int j = 0; j < n; j++) { // loop through the columns ofPushMatrix(); ofTranslate(i * spacing.x, j * spacing.y); // position the current mesh ofTranslate(spacing.x / 2, spacing.y / 2); // center the mesh if(ofGetKeyPressed()) { vboMesh.draw(); // draw a vboMesh (faster) when a key is pressed } else { mesh.draw(); // draw an ofMesh (slower) when no key is pressed } ofPopMatrix(); } } img.unbind(); ofDisableDepthTest(); cam.end(); // draw the framerate in the top left corner ofDrawBitmapString(ofToString((int) ofGetFrameRate()) + " fps", 10, 20); ofDrawBitmapString("Hold any key for ofVboMesh mode.", 10, 40); string mode = (ofGetKeyPressed() ? "ofVboMesh" : "ofMesh"); ofDrawBitmapString("Current mode: " + mode, 10, 60); }
void LoadedMap::loadTileset(XMLElement *element) { Logger.logMessage(LOG_STATE, LOG_MAP, "LoadedMap::loadTileset\n"); assert(element); TileSet tileset; tileset.name = element->Attribute(XML_TILESET_NAME.c_str()); stringstream tilewidth (element->Attribute(XML_TILESET_WIDTH.c_str())); stringstream tileheight (element->Attribute(XML_TILESET_HEIGHT.c_str())); stringstream spacing (element->Attribute(XML_TILESET_SPACING.c_str())); stringstream margin (element->Attribute(XML_TILESET_MARGIN.c_str())); tilewidth >> tileset.tilewidth; tileheight >> tileset.tileheight; spacing >> tileset.spacing; margin >> tileset.margin; XMLElement *image = element->FirstChildElement(XML_IMAGE.c_str()); assert(image); loadImageSource(image, &tileset); XMLElement *terrains = element->FirstChildElement(XML_TERRAINTYPE.c_str()); assert(terrains); loadTerrains(terrains, &tileset); XMLElement *first_tile = element->FirstChildElement(XML_TILE.c_str()); assert(first_tile); //NOTE: MUST push first because we reference afterwards (terrain //pointers) m_tilesets.push_back(tileset); loadTiles(first_tile, &m_tilesets.back()); Logger.logMessage(LOG_STATE, LOG_MAP, "LoadedMap::loadTileset end\n"); }
void run(UniformRandomNumberGenerator f, Counter & count, int n_total) const { typedef typename UniformRandomNumberGenerator::result_type result_type; assert(std::numeric_limits<result_type>::is_integer); assert(f.min() == 0); assert(f.max() == static_cast<result_type>(m-1)); for(int j = 0; j < n_total; j++) { std::vector<result_type> v(n); std::generate_n(v.begin(), n, f); std::sort(v.begin(), v.end()); std::vector<result_type> spacing(n); for(int i = 0; i < n-1; i++) spacing[i] = v[i+1]-v[i]; spacing[n-1] = v[0] + m - v[n-1]; std::sort(spacing.begin(), spacing.end()); unsigned int k = 0; for(int i = 0; i < n-1; ++i) { if(spacing[i] == spacing[i+1]) ++k; } count(std::min(k, classes()-1)); } }
void QDeclarativeGrid::doPositioning(QSizeF *contentSize) { int c = m_columns; int r = m_rows; int numVisible = positionedItems.count(); if (m_columns <= 0 && m_rows <= 0){ c = 4; r = (numVisible+3)/4; } else if (m_rows <= 0){ r = (numVisible+(m_columns-1))/m_columns; } else if (m_columns <= 0){ c = (numVisible+(m_rows-1))/m_rows; } QList<int> maxColWidth; QList<int> maxRowHeight; int childIndex =0; if (m_flow == LeftToRight) { for (int i=0; i < r; i++){ for (int j=0; j < c; j++){ if (j==0) maxRowHeight << 0; if (i==0) maxColWidth << 0; if (childIndex == positionedItems.count()) continue; const PositionedItem &child = positionedItems.at(childIndex++); if (!child.item || isInvisible(child.item)) continue; if (child.item->width() > maxColWidth[j]) maxColWidth[j] = child.item->width(); if (child.item->height() > maxRowHeight[i]) maxRowHeight[i] = child.item->height(); } } } else { for (int j=0; j < c; j++){ for (int i=0; i < r; i++){ if (j==0) maxRowHeight << 0; if (i==0) maxColWidth << 0; if (childIndex == positionedItems.count()) continue; const PositionedItem &child = positionedItems.at(childIndex++); if (!child.item || isInvisible(child.item)) continue; if (child.item->width() > maxColWidth[j]) maxColWidth[j] = child.item->width(); if (child.item->height() > maxRowHeight[i]) maxRowHeight[i] = child.item->height(); } } } int xoffset=0; int yoffset=0; int curRow =0; int curCol =0; for (int i = 0; i < positionedItems.count(); ++i) { const PositionedItem &child = positionedItems.at(i); if (!child.item || isInvisible(child.item)) continue; if((child.item->x()!=xoffset)||(child.item->y()!=yoffset)){ positionX(xoffset, child); positionY(yoffset, child); } if (m_flow == LeftToRight) { contentSize->setWidth(qMax(contentSize->width(), xoffset + child.item->width())); contentSize->setHeight(yoffset + maxRowHeight[curRow]); xoffset+=maxColWidth[curCol]+spacing(); curCol++; curCol%=c; if (!curCol){ yoffset+=maxRowHeight[curRow]+spacing(); xoffset=0; curRow++; if (curRow>=r) break; } } else { contentSize->setHeight(qMax(contentSize->height(), yoffset + child.item->height())); contentSize->setWidth(xoffset + maxColWidth[curCol]); yoffset+=maxRowHeight[curRow]+spacing(); curRow++; curRow%=r; if (!curRow){ xoffset+=maxColWidth[curCol]+spacing(); yoffset=0; curCol++; if (curCol>=c) break; } } } }
void ListView_Impl::paintDropTarget(QPainter *painter, const QModelIndex& index, int where) { QStyleOptionViewItem option = viewOptions(); QRect rect = this->visualRect(index); QWidget *viewport = this->viewport(); QColor highlight = palette().color(QPalette::HighlightedText); QColor color = option.state & QStyle::State_Selected ? highlight : palette().color(QPalette::Highlight); QPen pen(color); painter->save(); if (!index.isValid()) where = SL_EVENT_DRAG_ON_VIEWPORT; switch (where) { case SL_EVENT_DRAG_BELOW_ITEM: case SL_EVENT_DRAG_ABOVE_ITEM: { if (viewMode() == IconMode) { QSize size = gridSize(); if (size.isEmpty()) size = rect.size(); int x, y, height = size.height(); int cellWidth = size.width() + spacing(); int cellHeight = height + spacing(); x = rect.left() + horizontalOffset(); if (where == SL_EVENT_DRAG_BELOW_ITEM) x += cellWidth; x = ((x / cellWidth) * cellWidth) - horizontalOffset(); y = (((rect.top() + verticalOffset()) / cellHeight) * cellHeight) - verticalOffset(); height = qMax(5, height - 5); painter->setRenderHint(QPainter::Antialiasing); pen.setWidth(3); pen.setColor(highlight); painter->setPen(pen); painter->drawEllipse(QPointF(x, y + height), 3, 3); painter->drawLine(x, y + 5, x, y + height - 3); pen.setWidth(2); pen.setColor(color); painter->setPen(pen); painter->drawEllipse(QPointF(x, y + height), 3, 3); painter->drawLine(x, y + 5, x, y + height - 3); } else { int x, y, width; if (where == SL_EVENT_DRAG_BELOW_ITEM) y = rect.bottom() + 1; else y = rect.top(); x = rect.left(); width = viewport->width() - rect.left() - 10; painter->setRenderHint(QPainter::Antialiasing); pen.setWidth(3); pen.setColor(highlight); painter->setPen(pen); painter->drawEllipse(QPointF(x + width, y), 3, 3); painter->drawLine(x, y, x + width - 3, y); pen.setWidth(2); pen.setColor(color); painter->setPen(pen); painter->drawEllipse(QPointF(x + width, y), 3, 3); painter->drawLine(x, y, x + width - 3, y); } } break; case SL_EVENT_DRAG_ON_ITEM: { option.rect = rect; rect.adjust(1, 1, -1, -1); painter->setRenderHint(QPainter::Antialiasing); int radius = qMin(8, rect.height() / 2); pen.setWidth(3); pen.setColor(highlight); painter->setPen(pen); painter->drawRoundedRect(rect, radius, radius); pen.setWidth(2); if (viewMode() == IconMode) { color = palette().color(QPalette::Inactive, QPalette::Highlight); pen.setColor(color); painter->setPen(pen); painter->setBrush(QBrush(color)); painter->drawRoundedRect(rect, radius, radius); QItemSelectionModel *selection = selectionModel(); if ((selection) && (selection->isSelected(index))) option.state |= QStyle::State_Selected; if (!(model()->flags(index) & Qt::ItemIsEnabled)) option.state &= ~QStyle::State_Enabled; if (option.state & QStyle::State_Enabled) option.palette.setCurrentColorGroup(QPalette::Normal); else option.palette.setCurrentColorGroup(QPalette::Disabled); itemDelegate(index)->paint(painter, option, index); } else { pen.setColor(color); painter->setPen(pen); painter->drawRoundedRect(rect, radius, radius); } } break; case SL_EVENT_DRAG_ON_VIEWPORT: { rect = viewport->rect(); rect.adjust(0, 0, -1, -1); painter->setRenderHint(QPainter::Antialiasing, false); pen.setWidth(5); pen.setColor(highlight); painter->setPen(pen); painter->drawRect(rect); pen.setWidth(3); pen.setColor(color); painter->setPen(pen); painter->drawRect(rect); } break; } painter->restore(); }
SHAPE_LINE_CHAIN PNS_MEANDER_SHAPE::genMeanderShape( VECTOR2D aP, VECTOR2D aDir, bool aSide, PNS_MEANDER_TYPE aType, int aAmpl, int aBaselineOffset ) { const PNS_MEANDER_SETTINGS& st = Settings(); int cr = cornerRadius(); int offset = aBaselineOffset; int spc = spacing(); if( aSide ) offset *= -1; VECTOR2D dir_u_b( aDir.Resize( offset ) ); VECTOR2D dir_v_b( dir_u_b.Perpendicular() ); if( 2 * cr > aAmpl ) { cr = aAmpl / 2; } if( 2 * cr > spc ) { cr = spc / 2; } SHAPE_LINE_CHAIN lc; start( &lc, aP + dir_v_b, aDir ); switch( aType ) { case MT_EMPTY: { lc.Append( aP + dir_v_b + aDir ); break; } case MT_START: { arc( cr - offset, false ); uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr ); forward( std::min( cr - offset, cr + offset ) ); forward( std::abs( offset ) ); break; } case MT_FINISH: { start( &lc, aP - dir_u_b, aDir ); turn ( 90 ); forward( std::min( cr - offset, cr + offset ) ); forward( std::abs( offset ) ); uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr ); arc( cr - offset, false ); break; } case MT_TURN: { start( &lc, aP - dir_u_b, aDir ); turn( 90 ); forward( std::abs( offset ) ); uShape ( aAmpl - cr, cr + offset, spc - 2 * cr ); forward( std::abs( offset ) ); break; } case MT_SINGLE: { arc( cr - offset, false ); uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr ); arc( cr - offset, false ); lc.Append( aP + dir_v_b + aDir.Resize ( 2 * st.m_spacing ) ); break; } default: break; } if( aSide ) { SEG axis ( aP, aP + aDir ); for( int i = 0; i < lc.PointCount(); i++ ) lc.Point( i ) = reflect( lc.CPoint( i ), axis ); } return lc; }
int PNS_MEANDER_SHAPE::cornerRadius() const { int cr = (int64_t) spacing() * Settings().m_cornerRadiusPercentage / 200; return cr; }
KexiDataSourcePage::KexiDataSourcePage(QWidget *parent) : KexiPropertyPaneViewBase(parent) , m_noDataSourceAvailableSingleText( i18n("No data source could be assigned for this widget.") ) , m_noDataSourceAvailableMultiText( i18n("No data source could be assigned for multiple widgets.") ) , m_insideClearFormDataSourceSelection(false) #ifdef KEXI_NO_AUTOFIELD_WIDGET , m_tableOrQuerySchema(0) #endif { /*moved Q3VBoxLayout *vlyr = new Q3VBoxLayout(this); m_objectInfoLabel = new KexiObjectInfoLabel(this); m_objectInfoLabel->setObjectName("KexiObjectInfoLabel"); vlyr->addWidget(m_objectInfoLabel);*/ //moved vlyr->addSpacing(8); //Section 1: Form's/Widget's Data Source /*2.0 KoProperty::GroupContainer *container = new KoProperty::GroupContainer( i18n("Data Source"), this); layout()->addWidget(container); QWidget *contents = new QWidget(container); container->setContents(contents);*/ //2.0 QVBoxLayout *contentsVlyr = new QVBoxLayout(this); //2.0 contentsVlyr->setContentsMargins(0, 0, 0, 0); infoLabel()->setContentsMargins(0, 0, 0, spacing()); m_noDataSourceAvailableLabel = new QLabel(m_noDataSourceAvailableSingleText, this); m_noDataSourceAvailableLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); m_noDataSourceAvailableLabel->setContentsMargins(0, 0, 0, spacing()); //m_noDataSourceAvailableLabel->setAutoFillBackground(true); //m_noDataSourceAvailableLabel->setPaletteBackgroundColor(Qt::red); //2.0 m_noDataSourceAvailableLabel->setMargin(2); m_noDataSourceAvailableLabel->setAlignment(Qt::AlignBottom | Qt::AlignLeft); m_noDataSourceAvailableLabel->setWordWrap(true); mainLayout()->addWidget(m_noDataSourceAvailableLabel); //-Widget's Data Source QHBoxLayout *hlyr = new QHBoxLayout(); mainLayout()->addLayout(hlyr); #if 0 //! @todo unhide this when expression work // m_widgetDSLabel = new QLabel(i18nc("Table Field, Query Field or Expression", "Source field or expression"), this); #else m_widgetDSLabel = new QLabel( i18nc("Table Field or Query Field", "Widget's data source"), this); #endif m_widgetDSLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); //2.0 m_widgetDSLabel->setMargin(2); //2.0 m_widgetDSLabel->setMinimumHeight(IconSize(KIconLoader::Small) + 4); m_widgetDSLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); hlyr->addWidget(m_widgetDSLabel); #if 0 //2.0: clear button is available in the combobox itself m_clearWidgetDSButton = new KexiSmallToolButton( koIcon("edit-clear-locationbar-rtl"), QString(), this); m_clearWidgetDSButton->setObjectName("clearWidgetDSButton"); m_clearWidgetDSButton->setMinimumHeight(m_widgetDSLabel->minimumHeight()); m_clearWidgetDSButton->setToolTip(i18n("Clear widget's data source")); hlyr->addWidget(m_clearWidgetDSButton); connect(m_clearWidgetDSButton, SIGNAL(clicked()), this, SLOT(clearWidgetDataSourceSelection())); #endif m_widgetDataSourceCombo = new KexiFieldComboBox(this); m_widgetDataSourceCombo->setObjectName("sourceFieldCombo"); m_widgetDataSourceCombo->setContentsMargins(0, 0, 0, 0); m_widgetDSLabel->setBuddy(m_widgetDataSourceCombo); connect(m_widgetDataSourceCombo->lineEdit(), SIGNAL(clearButtonClicked()), this, SLOT(clearWidgetDataSourceSelection())); mainLayout()->addWidget(m_widgetDataSourceCombo); m_widgetDataSourceComboSpacer = addWidgetSpacer(); /* m_dataSourceSeparator = new Q3Frame(contents); m_dataSourceSeparator->setFrameShape(Q3Frame::HLine); m_dataSourceSeparator->setFrameShadow(Q3Frame::Sunken); mainLayout()->addWidget(m_dataSourceSeparator);*/ // addSpacing(); //- Form's Data Source hlyr = new QHBoxLayout(); hlyr->setContentsMargins(0, 0, 0, 0); mainLayout()->addLayout(hlyr); m_dataSourceLabel = new QLabel(i18n("Form's data source"), this); m_dataSourceLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); //2.0 m_dataSourceLabel->setMargin(2); //2.0 m_dataSourceLabel->setMinimumHeight(IconSize(KIconLoader::Small) + 4); m_dataSourceLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); hlyr->addWidget(m_dataSourceLabel); //m_dataSourceLabel->setAutoFillBackground(true); //m_dataSourceLabel->setPaletteBackgroundColor(Qt::red); m_gotoButton = new KexiSmallToolButton( koIcon("go-jump"), QString(), this); m_gotoButton->setObjectName("gotoButton"); //2.0 m_gotoButton->setMinimumHeight(m_dataSourceLabel->minimumHeight()); m_gotoButton->setToolTip(i18n("Go to selected form's data source")); m_gotoButton->setWhatsThis(i18n("Goes to selected form's data source")); hlyr->addWidget(m_gotoButton); connect(m_gotoButton, SIGNAL(clicked()), this, SLOT(slotGotoSelected())); #if 0 //2.0: clear button is available in the combobox itself m_clearDSButton = new KexiSmallToolButton( koIcon("edit-clear-locationbar-rtl"), QString(), this); m_clearDSButton->setObjectName("clearDSButton"); m_clearDSButton->setMinimumHeight(m_dataSourceLabel->minimumHeight()); m_clearDSButton->setToolTip(i18n("Clear form's data source")); hlyr->addWidget(m_clearDSButton); connect(m_clearDSButton, SIGNAL(clicked()), this, SLOT(clearFormDataSourceSelection())); #endif m_formDataSourceCombo = new KexiDataSourceComboBox(this); m_formDataSourceCombo->setObjectName("dataSourceCombo"); m_formDataSourceCombo->setContentsMargins(0, 0, 0, 0); m_dataSourceLabel->setBuddy(m_formDataSourceCombo); connect(m_formDataSourceCombo->lineEdit(), SIGNAL(clearButtonClicked()), this, SLOT(clearFormDataSourceSelection())); mainLayout()->addWidget(m_formDataSourceCombo); m_formDataSourceComboSpacer = addWidgetSpacer(); #ifdef KEXI_NO_AUTOFIELD_WIDGET m_availableFieldsLabel = 0; m_addField = 0; // m_fieldListView = 0; mainLayout()->addStretch(); #else // addSpacing(); /* Q3Frame *separator = new QFrame(this); separator->setFrameShape(Q3Frame::HLine); separator->setFrameShadow(Q3Frame::Sunken); vlyr->addWidget(separator);*/ /* KPopupTitle *title = new KPopupTitle(this); title->setTitle(i18n("Inserting fields")); vlyr->addWidget(title); vlyr->addSpacing(4);*/ //2. Inserting fields /*2.0 container = new KoProperty::GroupContainer(i18n("Inserting Fields"), this); static_cast<QBoxLayout*>(layout())->addWidget(container, 1);*/ //helper info //! @todo allow to hide such helpers by adding global option //2.0 contents = new QWidget(container); //2.0 container->setContents(contents); //2.0 mainLayout() = new QVBoxLayout(contents); hlyr = new QHBoxLayout(); hlyr->setContentsMargins(0, 0, 0, 0); mainLayout()->addLayout(hlyr); m_mousePointerLabel = new QLabel(this); hlyr->addWidget(m_mousePointerLabel); m_mousePointerLabel->setPixmap(koIcon("mouse_pointer")); m_mousePointerLabel->setFixedWidth(m_mousePointerLabel->pixmap() ? m_mousePointerLabel->pixmap()->width() : 0); m_availableFieldsDescriptionLabel = new QLabel( i18n("Select fields from the list below and drag them onto" " a form or click the \"Insert\" button"), this); m_availableFieldsDescriptionLabel->setAlignment(Qt::AlignLeft); m_availableFieldsDescriptionLabel->setWordWrap(true); hlyr->addWidget(m_availableFieldsDescriptionLabel); //Available Fields //2.0 mainLayout()->addSpacing(4); hlyr = new QHBoxLayout(); hlyr->setContentsMargins(0, 0, 0, 0); mainLayout()->addLayout(hlyr); m_availableFieldsLabel = new QLabel(i18n("Available fields"), this); m_availableFieldsLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); //2.0 m_availableFieldsLabel->setMargin(2); //2.0 m_availableFieldsLabel->setMinimumHeight(IconSize(KIconLoader::Small)); hlyr->addWidget(m_availableFieldsLabel); m_addField = new KexiSmallToolButton( koIcon("add_field"), i18nc("Insert selected field into form", "Insert"), this); m_addField->setObjectName("addFieldButton"); //2.0 m_addField->setMinimumHeight(m_availableFieldsLabel->minimumHeight()); // m_addField->setTextPosition(QToolButton::Right); m_addField->setFocusPolicy(Qt::StrongFocus); m_addField->setToolTip(i18n("Insert selected fields into form")); m_addField->setWhatsThis(i18n("Inserts selected fields into form")); hlyr->addWidget(m_addField); connect(m_addField, SIGNAL(clicked()), this, SLOT(slotInsertSelectedFields())); m_fieldListView = new KexiFieldListView(this, KexiFieldListView::ShowDataTypes | KexiFieldListView::AllowMultiSelection); m_fieldListView->setObjectName("fieldListView"); m_fieldListView->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding)); m_availableFieldsLabel->setBuddy(m_fieldListView); mainLayout()->addWidget(m_fieldListView, 1); connect(m_fieldListView, SIGNAL(selectionChanged()), this, SLOT(slotFieldListViewSelectionChanged())); connect(m_fieldListView, SIGNAL(fieldDoubleClicked(QString,QString,QString)), this, SLOT(slotFieldDoubleClicked(QString,QString,QString))); #endif mainLayout()->addStretch(1); connect(m_formDataSourceCombo, SIGNAL(textChanged(QString)), this, SLOT(slotFormDataSourceTextChanged(QString))); connect(m_formDataSourceCombo, SIGNAL(dataSourceChanged()), this, SLOT(slotFormDataSourceChanged())); connect(m_widgetDataSourceCombo, SIGNAL(selected()), this, SLOT(slotFieldSelected())); clearFormDataSourceSelection(); slotFieldListViewSelectionChanged(); }
// Arranges widgets and returns height required. int PackedLayout::arrange(const QRect& rect, bool set) const { int x = rect.x(); int y = rect.y(); int yrow = 0; QList<QRect> posn; int end = mItems.count(); QList<QLayoutItem*> items; for (int i = 0; i < end; ++i) { QLayoutItem* item = mItems[i]; if (item->isEmpty()) continue; QSize size = item->sizeHint(); int right = x + size.width(); if (right > rect.right() && x > rect.x()) { x = rect.x(); y = y + yrow + spacing(); right = x + size.width(); yrow = size.height(); } else yrow = qMax(yrow, size.height()); items.append(item); posn.append(QRect(QPoint(x, y), size)); x = right + spacing(); } if (set) { int count = items.count(); if (mAlignment == Qt::AlignLeft) { // Left aligned: no position adjustment needed // Set the positions of all the layout items for (int i = 0; i < count; ++i) items[i]->setGeometry(posn[i]); } else { // Set the positions of all the layout items for (int i = 0; i < count; ) { // Adjust item positions a row at a time y = posn[i].y(); int last; // after last item in this row for (last = i + 1; last < count && posn[last].y() == y; ++last) ; int n = last - i; // number of items in this row int free = rect.right() - posn[last - 1].right(); switch (mAlignment) { case Qt::AlignJustify: if (n == 1) { items[i]->setGeometry(posn[i]); ++i; } else if (n > 1) { for (int j = 0; i < last; ++j, ++i) items[i]->setGeometry(QRect(QPoint(posn[i].x() + (free * j)/(n - 1), y), posn[i].size())); } break; case Qt::AlignHCenter: free /= 2; // fall through to AlignRight case Qt::AlignRight: for ( ; i < last; ++i) items[i]->setGeometry(QRect(QPoint(posn[i].x() + free, y), posn[i].size())); break; default: break; } } } } return y + yrow - rect.y(); }
virtual int sizeHintForRow (int row) const { return QListView::sizeHintForRow(row) + spacing() * 2; }
void ZBorderLayout::setGeometry(const QRect &rect) { ItemWrapper *center = 0; int eastWidth = 0; int westWidth = 0; int northHeight = 0; int southHeight = 0; int centerHeight = 0; int i; QLayout::setGeometry(rect); for (i = 0; i < list.size(); ++i) { ItemWrapper *wrapper = list.at(i); QLayoutItem *item = wrapper->item; Position position = wrapper->position; if (position == North) { item->setGeometry(QRect(rect.x(), northHeight, rect.width(), item->sizeHint().height())); northHeight += item->geometry().height() + spacing(); } else if (position == South) { item->setGeometry(QRect(item->geometry().x(), item->geometry().y(), rect.width(), item->sizeHint().height())); southHeight += item->geometry().height() + spacing(); item->setGeometry(QRect(rect.x(), rect.y() + rect.height() - southHeight + spacing(), item->geometry().width(), item->geometry().height())); } else if (position == Center) { center = wrapper; } } centerHeight = rect.height() - northHeight - southHeight; for (i = 0; i < list.size(); ++i) { ItemWrapper *wrapper = list.at(i); QLayoutItem *item = wrapper->item; Position position = wrapper->position; if (position == West) { item->setGeometry(QRect(rect.x() + westWidth, northHeight, item->sizeHint().width(), centerHeight)); westWidth += item->geometry().width() + spacing(); } else if (position == East) { item->setGeometry(QRect(item->geometry().x(), item->geometry().y(), item->sizeHint().width(), centerHeight)); eastWidth += item->geometry().width() + spacing(); item->setGeometry(QRect( rect.x() + rect.width() - eastWidth + spacing(), northHeight, item->geometry().width(), item->geometry().height())); } } if (center) center->item->setGeometry(QRect(westWidth, northHeight, rect.width() - eastWidth - westWidth, centerHeight)); }
qreal Brush::spacingDist(qreal pressure) const { return spacing() * radius(pressure)/100.0; }
void ClipboardBrowser::preload(int minY, int maxY) { ClipboardBrowser::Lock lock(this); QModelIndex ind; int i = 0; int y = spacing(); const int s = 2 * spacing(); int offset = verticalOffset(); // Find first index to preload. forever { ind = index(i); if ( !ind.isValid() ) return; if ( !isIndexHidden(ind) ) { const int h = d.sizeHint(ind).height(); y += h; // bottom of item if (y >= offset) break; y += s; // top of next item } d.setRowVisible(i, false); ++i; } // Absolute to relative. y -= offset; bool update = false; // Preload items backwards. forever { const int lastIndex = i; for ( ind = index(--i); ind.isValid() && isIndexHidden(ind); ind = index(--i) ) {} if ( !ind.isValid() ) { i = lastIndex; ind = index(i); break; } const QRect oldRect(visualRect(ind)); // Fetch item. d.cache(ind); const int h = d.sizeHint(ind).height(); // Re-layout rows afterwards if size has changed. const int dy = h - oldRect.height(); if (dy != 0) { maxY += dy; update = true; } // Done? y -= h; // top of item if (y + h < minY) break; y -= s; // bottom of previous item } y = visualRect(ind).y(); bool lastToPreload = false; // Render visible items, re-layout rows and correct scroll offset. forever { if (m_lastFiltered != -1 && m_lastFiltered < i) break; const QRect oldRect(update ? QRect() : visualRect(ind)); // Fetch item. d.cache(ind); const int h = d.sizeHint(ind).height(); // Re-layout rows afterwards if row position or size has changed. if (!update) update = (y != oldRect.y() || h != oldRect.height()); // Correct widget position. d.updateRowPosition(i, y); d.setRowVisible(i, true); // Next. ind = index(++i); // Done? y += h + s; // top of item if (y > maxY) { if (lastToPreload) break; lastToPreload = true; // One more item to preload. } // Skip hidden. for ( ; ind.isValid() && isIndexHidden(ind); ind = index(++i) ) {} if ( !ind.isValid() ) break; } // Hide the rest. for ( ; i < m.rowCount(); ++i ) d.setRowVisible(i, false); if (update) scheduleDelayedItemsLayout(); }
// // Use the QuikGrid library to generate a grid from a set of 3D points. // bool vtElevLayer::CreateFromPoints(vtFeatureSet *set, const IPoint2 &size, float fDistanceRatio) { #if SUPPORT_QUIKGRID vtFeatureSetPoint3D *fsp3 = dynamic_cast<vtFeatureSetPoint3D *>(set); if (!fsp3) return false; DRECT extent; fsp3->ComputeExtent(extent); int iMaxSize = fsp3->NumEntities(); ScatData sdata(iMaxSize); DPoint3 p; for (int i = 0; i < iMaxSize; i++) { fsp3->GetPoint(i, p); sdata.SetNext(p.x, p.y, p.z); } // Make a SurfaceGrid to hold the results DPoint2 spacing(extent.Width() / (size.x-1), extent.Height() / (size.y-1)); SurfaceGrid Zgrid(size.x, size.y); for (int x = 0; x < size.x; x++) Zgrid.xset(x, extent.left + spacing.x * x); for (int y = 0; y < size.y; y++) Zgrid.yset(y, extent.bottom + spacing.y * y); // "When any new points will not contributed more than 1/(scan bandwidth cutoff) // towards the value of a grid intersection scanning will cease in that // direction. " int x1 = XpandScanRatio(); // default 16, valid values 1..100 // "The Distance cutoff specifies a percent of the Density Distance" int x2 = XpandDensityRatio(); // default 150, valid values 1..10000 int x3 = XpandEdgeFactor(); // default 100, valid values 1..10000 float x4 = XpandUndefinedZ(); long x5 = XpandSample(); XpandDensityRatio((int) (fDistanceRatio * 100)); // Do the expand operation, gradually so we get progress XpandInit(Zgrid, sdata); int count = 0, total = size.x * size.y; while (XpandPoint( Zgrid, sdata)) { if ((count % 100) == 0) { if (progress_callback(count * 99 / total)) { // user cancelled return false; } } count++; } // copy the result to a ElevationGrid m_pGrid = new vtElevationGrid(extent, size, true, set->GetAtProjection()); for (int x = 0; x < size.x; x++) for (int y = 0; y < size.y; y++) { float value = Zgrid.z(x,y); if (value == -99999) m_pGrid->SetFValue(x, y, INVALID_ELEVATION); else m_pGrid->SetFValue(x, y, value); } m_pGrid->ComputeHeightExtents(); m_pGrid->SetupLocalCS(); return true; #else // No QuikGrid return false; #endif }
// takes in assembly, name to call the file, list of residue names and number of residues in the list void outputResPDB(assembly* asmbl, char* file_name, int* residues, int outrn){ //Tells the user what's going on printf("Writing to file: %s...\n",file_name); FILE* file; //char current_line[80] = ""; char temporary[40] = ""; //char* curLine = current_line; char* temp = temporary; char temp[40]; char curLine[80]; char* resName; char* atmName; int i,j,k,x,atmTot,resNum,resTot; atom curAtm; molecule* mol; file = myfopen(file_name,"w"); for(k = 0; k < (*asmbl).nm; k++){ mol = ((*asmbl).m+k)[0]; // changed by BLF on 20080622 -- might need revisiting resTot = (*mol).nr; // printf("resTot=%d,outrn=%d\n",resTot,outrn); for(i = 0; i < resTot; i++){ resNum = (*((*mol).r+i)).n; // printf("resNum=%d\n",resNum); for (x=0; x<outrn;x++){ if (residues[x]==resNum){ // only output if resNum in the residue list resName = (*((*mol).r+i)).N; atmTot = (*((*mol).r+i)).na; for(j = 0; j < atmTot; j++){ curAtm = (*((*((*mol).r+i)).a+j)); atmName = curAtm.N; if (strcmp(curAtm.N,"a9")!=0){ strcpy(curLine,""); strcat(curLine,"ATOM"); sprintf(temp,"%d", curAtm.n); //Based on how large the atom # is, depends on the # of spaces strcat(curLine,spacing(strlen(temp),7)); //"ATOM atom# atom_name" sprintf(temp,"%d %s", curAtm.n, atmName); strcat(curLine,temp); //Based on how many char are in the residue name, " " spaces strcat(curLine,spacing(strlen(atmName),4)); //"ATOM atom# atom_name res_name" strcat(curLine,resName); sprintf(temp,"%d",resNum); //Based on how large the residue # is, " " spaces strcat(curLine,spacing(strlen(temp),6)); //"ATOM atom# atom_name res_name res#" strcat(curLine,temp); sprintf(temp,"%.3lf",curAtm.x.i); //Based on how large the x cordinate is, " " spaces strcat(curLine,spacing(strlen(temp),12)); //"ATOM atom# atom_name res_name x" strcat(curLine,temp); sprintf(temp,"%.3lf",curAtm.x.j); //Based on how large the y cordinate is, " " spaces strcat(curLine,spacing(strlen(temp),8)); //"ATOM atom# atom_name res_name x y" strcat(curLine,temp); sprintf(temp,"%.3lf",curAtm.x.k); //Based on how large the z cordinate is, " " spaces strcat(curLine,spacing(strlen(temp),8)); //"ATOM atom# atom_name res_name x y z 1.00 0.00" sprintf(temp,"%.3lf 1.00 0.00",curAtm.x.k); strcat(curLine,temp); //Output the line to the new .pbd file fprintf(file,"%s\n",curLine); // printf("curLine=%s\n",curLine); } //fprintf(file,"TER \n"); } } } } } fclose(file); }
virtual int sizeHintForColumn(int column) const { return QListView::sizeHintForColumn(column) + spacing() * 2; }
QSize GUIContainer::sizeForLayout() { QSize size(0, 0); switch(_layout) { case HorizontalLayout: { bool first[3] = {true, true, true}; foreach(GUIWidget* child, childWidgets()) { if(child->isHidden()) continue; QSize pref = child->preferredSize(); int flot = valForFloatAttr(child->wattr()); if(first[flot]) first[flot] = false; else pref.setWidth(pref.width() + spacing().x()); size.setWidth(size.width() + pref.width()); if(pref.height() > size.height()) size.setHeight(pref.height()); } break; } case VerticalLayout: { bool first[3] = {true, true, true}; foreach(GUIWidget* child, childWidgets()) { if(child->isHidden()) continue; QSize pref = child->preferredSize(); int flot = valForFloatAttr(child->wattr()); if(first[flot]) first[flot] = false; else pref.setHeight(pref.height() + spacing().y()); size.setHeight(size.height() + pref.height()); if(pref.width() > size.width()) size.setWidth(pref.width()); } break; } case FreeformLayout: foreach(GUIWidget* child, childWidgets()) { int w = child->x() + child->width(); int h = child->y() + child->height(); if(w > size.width()) size.setWidth(w); if(h > size.height()) size.setHeight(h); } }
/*! * This function returns the height items in our list should have. This is * generally the larger of our icon size and our font size, plus the spacing * our items have around them. * * \return The height of a list item. */ int CSIconListWidget::getItemHeight() const { return qMax(iconSize().height(), QFontMetrics(font()).lineSpacing()) + (spacing() * 2); }
uint numCols) const #else QList<QRect> QwtDynGridLayout::layoutItems(const QRect &rect, uint numCols) const #endif { #if QT_VERSION < 0x040000 QValueList<QRect> itemGeometries; #else QList<QRect> itemGeometries; #endif if ( numCols == 0 || isEmpty() ) return itemGeometries; uint numRows = itemCount() / numCols; if ( numRows % itemCount() ) numRows++; QwtArray<int> rowHeight(numRows); QwtArray<int> colWidth(numCols); layoutGrid(numCols, rowHeight, colWidth); bool expandH, expandV; #if QT_VERSION >= 0x040000 expandH = expandingDirections() & Qt::Horizontal; expandV = expandingDirections() & Qt::Vertical; #else expandH = expanding() & QSizePolicy::Horizontally; expandV = expanding() & QSizePolicy::Vertically; #endif if ( expandH || expandV ) stretchGrid(rect, numCols, rowHeight, colWidth); QwtDynGridLayout *that = (QwtDynGridLayout *)this; const int maxCols = d_data->maxCols; that->d_data->maxCols = numCols; const QRect alignedRect = alignmentRect(rect); that->d_data->maxCols = maxCols; const int xOffset = expandH ? 0 : alignedRect.x(); const int yOffset = expandV ? 0 : alignedRect.y(); QwtArray<int> colX(numCols); QwtArray<int> rowY(numRows); const int xySpace = spacing(); rowY[0] = yOffset + margin(); for ( int r = 1; r < (int)numRows; r++ ) rowY[r] = rowY[r-1] + rowHeight[r-1] + xySpace; colX[0] = xOffset + margin(); for ( int c = 1; c < (int)numCols; c++ ) colX[c] = colX[c-1] + colWidth[c-1] + xySpace; const int itemCount = d_data->itemList.size(); for ( int i = 0; i < itemCount; i++ ) { const int row = i / numCols; const int col = i % numCols; QRect itemGeometry(colX[col], rowY[row], colWidth[col], rowHeight[row]); itemGeometries.append(itemGeometry); } return itemGeometries; }
vtkmDataSet * ConvertVTKToVTKm(vtkDataSet *data) { vtkmDataSet *ret = NULL; if (data->GetDataObjectType() == VTK_RECTILINEAR_GRID) { // // Get VTK data. // vtkRectilinearGrid *rgrid = (vtkRectilinearGrid *) data; vtkDataArray *xCoords = rgrid->GetXCoordinates(); vtkDataArray *yCoords = rgrid->GetYCoordinates(); vtkDataArray *zCoords = rgrid->GetZCoordinates(); float *xPts = static_cast<float*>(xCoords->GetVoidPointer(0)); float *yPts = static_cast<float*>(yCoords->GetVoidPointer(0)); float *zPts = static_cast<float*>(zCoords->GetVoidPointer(0)); int dims[3]; rgrid->GetDimensions(dims); // // Create the VTKm data set. // ret = new vtkmDataSet; // Add the structured cell set. const vtkm::Id3 vdims(dims[0], dims[1], dims[2]); vtkm::cont::CellSetStructured<3> cs("cells"); cs.SetPointDimensions(vdims); ret->ds.AddCellSet(cs); // Add the coordinate system. vtkm::Vec<vtkm::Float32,3> origin(xPts[0], yPts[0], zPts[0]); vtkm::Vec<vtkm::Float32,3> spacing( static_cast<vtkm::Float32>(xPts[1] - xPts[0]), static_cast<vtkm::Float32>(yPts[1] - yPts[0]), static_cast<vtkm::Float32>(zPts[1] - zPts[0])); vtkm::cont::ArrayHandleUniformPointCoordinates coordinates(vdims, origin, spacing); ret->ds.AddCoordinateSystem( vtkm::cont::CoordinateSystem("coordinates", 1, coordinates)); } else if (data->GetDataObjectType() == VTK_STRUCTURED_GRID) { // // Get VTK data. // vtkStructuredGrid *sgrid = (vtkStructuredGrid *) data; vtkIdType nPoints = sgrid->GetNumberOfPoints(); vtkPoints *points = sgrid->GetPoints(); float *pts = static_cast<float*>(points->GetVoidPointer(0)); int dims[3]; sgrid->GetDimensions(dims); // // Create the VTKm data set. // ret = new vtkmDataSet; // Add the structured cell set. const vtkm::Id3 vdims(dims[0], dims[1], dims[2]); vtkm::cont::CellSetStructured<3> cs("cells"); cs.SetPointDimensions(vdims); ret->ds.AddCellSet(cs); // Add the coordinate system. vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32,3> > coordinates; coordinates.Allocate(nPoints); for (vtkm::Id i = 0; i < nPoints; ++i) { vtkm::Vec<vtkm::Float32,3> point(pts[i*3], pts[i*3+1], pts[i*3+2]); coordinates.GetPortalControl().Set(i, point); } ret->ds.AddCoordinateSystem( vtkm::cont::CoordinateSystem("coordinates", 1, coordinates)); } else if (data->GetDataObjectType() == VTK_UNSTRUCTURED_GRID) { // // Get VTK data. // vtkUnstructuredGrid *ugrid = (vtkUnstructuredGrid *) data; vtkIdType nPoints = ugrid->GetNumberOfPoints(); vtkPoints *points = ugrid->GetPoints(); vtkUnsignedCharArray *cellTypes = ugrid->GetCellTypesArray(); vtkIdTypeArray *cellLocations = ugrid->GetCellLocationsArray(); vtkCellArray *cells = ugrid->GetCells(); vtkIdType nCells = cells->GetNumberOfCells(); vtkIdType nConnectivity = cells->GetNumberOfConnectivityEntries(); vtkIdType *nl = cells->GetPointer(); unsigned char *ct = cellTypes->GetPointer(0); // // Create the VTKm data set. // ret = new vtkmDataSet; // Add the unstructured cell set. vtkm::cont::ArrayHandle<vtkm::Id> connectivity; vtkm::cont::ArrayHandle<vtkm::IdComponent> nIndices; vtkm::cont::ArrayHandle<vtkm::UInt8> shapes; connectivity.Allocate(nConnectivity - nCells); nIndices.Allocate(nCells); shapes.Allocate(nCells); vtkm::cont::ArrayHandle<vtkm::Id>::PortalControl connectivityPortal = connectivity.GetPortalControl(); vtkm::cont::ArrayHandle<vtkm::IdComponent>::PortalControl nIndicesPortal = nIndices.GetPortalControl(); vtkm::cont::ArrayHandle<vtkm::UInt8>::PortalControl shapesPortal = shapes.GetPortalControl(); vtkm::Id nCellsActual = 0, connInd = 0; for (vtkm::Id i = 0; i < nCells; ++i) { vtkm::IdComponent nInds = static_cast<vtkm::IdComponent>(*nl++); switch (*ct) { #if 0 case vtkm::CELL_SHAPE_VERTEX: case vtkm::CELL_SHAPE_LINE: case vtkm::CELL_SHAPE_TRIANGLE: case vtkm::CELL_SHAPE_QUAD: case vtkm::CELL_SHAPE_TETRA: #endif case vtkm::CELL_SHAPE_HEXAHEDRON: #if 0 case vtkm::CELL_SHAPE_WEDGE: case vtkm::CELL_SHAPE_PYRAMID: #endif nIndicesPortal.Set(nCellsActual, nInds); for (vtkm::IdComponent j = 0; j < nInds; ++j, ++connInd) { connectivityPortal.Set(connInd, static_cast<vtkm::Id>(*nl++)); } shapesPortal.Set(nCellsActual, static_cast<vtkm::UInt8>(*ct++)); nCellsActual++; break; default: // Unsupported type, skipping. ct++; nl += static_cast<vtkIdType>(nInds); break; } } // If we skipped any cells adjust the cell set array lengths. if (nCellsActual < nCells) { connectivity.Shrink(connInd); nIndices.Shrink(nCellsActual); shapes.Shrink(nCellsActual); } vtkm::cont::CellSetExplicit<> cs(0, "cells"); cs.Fill(shapes, nIndices, connectivity); ret->ds.AddCellSet(cs); // Add the coordinate system. if (points->GetDataType() == VTK_FLOAT) { float *pts = static_cast<float*>(points->GetVoidPointer(0)); vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32,3> > coordinates; coordinates.Allocate(nPoints); for (vtkm::Id i = 0; i < nPoints; ++i) { vtkm::Vec<vtkm::Float32,3> point(pts[i*3], pts[i*3+1], pts[i*3+2]); coordinates.GetPortalControl().Set(i, point); } ret->ds.AddCoordinateSystem( vtkm::cont::CoordinateSystem("coordinates", 1, coordinates)); } else { double *pts = static_cast<double*>(points->GetVoidPointer(0)); vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float64,3> > coordinates; coordinates.Allocate(nPoints); for (vtkm::Id i = 0; i < nPoints; ++i) { vtkm::Vec<vtkm::Float64,3> point(pts[i*3], pts[i*3+1], pts[i*3+2]); coordinates.GetPortalControl().Set(i, point); } ret->ds.AddCoordinateSystem( vtkm::cont::CoordinateSystem("coordinates", 1, coordinates)); } } // // Add the fields. // int nArrays = data->GetPointData()->GetNumberOfArrays(); for (int i = 0; i < nArrays; ++i) { vtkDataArray *array = data->GetPointData()->GetArray(i); if (array->GetNumberOfComponents() == 1 && array->GetDataType() == VTK_FLOAT) { vtkIdType nVals = array->GetNumberOfTuples(); float *vals = vtkFloatArray::SafeDownCast(array)->GetPointer(0); vtkm::cont::ArrayHandle<vtkm::Float32> fieldArray; fieldArray.Allocate(nVals); for (vtkm::Id j = 0; j < nVals; ++j) fieldArray.GetPortalControl().Set(j, vals[j]); ret->ds.AddField( vtkm::cont::Field(array->GetName(), 1, vtkm::cont::Field::ASSOC_POINTS, fieldArray)); } else if (array->GetNumberOfComponents() == 1 && array->GetDataType() == VTK_DOUBLE) { vtkIdType nVals = array->GetNumberOfTuples(); double *vals = vtkDoubleArray::SafeDownCast(array)->GetPointer(0); vtkm::cont::ArrayHandle<vtkm::Float64> fieldArray; fieldArray.Allocate(nVals); for (vtkm::Id j = 0; j < nVals; ++j) fieldArray.GetPortalControl().Set(j, vals[j]); ret->ds.AddField( vtkm::cont::Field(array->GetName(), 1, vtkm::cont::Field::ASSOC_POINTS, fieldArray)); } } return ret; }
void ParagraphParameters::read(Lexer & lex, bool merge) { if (!merge) clear(); while (lex.isOK()) { lex.nextToken(); string const token = lex.getString(); if (token.empty()) continue; if (token[0] != '\\') { lex.pushToken(token); break; } if (token == "\\noindent") { noindent(true); } else if (token == "\\indent") { //not found in LyX files but can be used with lfuns noindent(false); } else if (token == "\\indent-toggle") { //not found in LyX files but can be used with lfuns noindent(!noindent()); } else if (token == "\\leftindent") { lex.next(); Length value(lex.getString()); leftIndent(value); } else if (token == "\\start_of_appendix") { startOfAppendix(true); } else if (token == "\\paragraph_spacing") { lex.next(); string const tmp = rtrim(lex.getString()); if (tmp == "default") { //not found in LyX files but can be used with lfuns spacing(Spacing(Spacing::Default)); } else if (tmp == "single") { spacing(Spacing(Spacing::Single)); } else if (tmp == "onehalf") { spacing(Spacing(Spacing::Onehalf)); } else if (tmp == "double") { spacing(Spacing(Spacing::Double)); } else if (tmp == "other") { lex.next(); spacing(Spacing(Spacing::Other, lex.getString())); } else { lex.printError("Unknown spacing token: '$$Token'"); } } else if (token == "\\align") { lex.next(); int tmpret = findToken(string_align, lex.getString()); if (tmpret == -1) ++tmpret; align(LyXAlignment(1 << tmpret)); } else if (token == "\\labelwidthstring") { lex.eatLine(); labelWidthString(lex.getDocString()); } else { lex.pushToken(token); break; } } }
void main_loop() { while (true) { unsigned int maxLen = 4; // Reset all counters for (auto& ov: objectMap) ov.second.call<void>("clearStats"); qi::os::msleep(interval * 1000); Stats stats; // Fetch stats from monitored objects and fill stats for(ObjectMap::value_type& ov: objectMap) { qi::ObjectStatistics os = ov.second.call<qi::ObjectStatistics>("stats"); const std::string& serviceName = ov.first; for(qi::ObjectStatistics::value_type& s: os) { if (s.first == 83) continue; // hide clearstats std::string name = boost::lexical_cast<std::string>(s.first); if (!numeric) { qi::MetaObject mo = ov.second.metaObject(); qi::MetaMethod* m = mo.method(s.first); if (m) name = m->name(); else { qi::MetaSignal* sig = mo.signal(s.first); if (sig) name = sig->name(); else name = name + "(??" ")"; // trigraph protect mode on } } maxLen = std::max(maxLen, (unsigned int)name.size()); stats.push_back(std::make_pair(std::make_pair(serviceName, name), s.second)); } } if (!full) maxLen = std::min(maxLen, 25u); // Now, sort std::sort(stats.begin(), stats.end(), StatCompare()); // display std::cout << "MODULE" << std::string(maxLen + 2 - 6, ' ') << "METHOD" << std::string((full?maxServiceLength:17) + 2 - 6, ' ') << " %CPU " << "COUNT " << "USER" << std::string(6*3 - 2, ' ') << "SYS " << std::string(6*3 - 2, ' ') << "WALL" << std::endl; for(const Stat& s: stats) { const qi::MethodStatistics& ms = s.second; std::string serviceName = s.first.first; std::string methodName = s.first.second; if (!full && serviceName.size() > 17) serviceName = serviceName.substr(0, 14) + "..."; if (!full && methodName.size() > 25) methodName = methodName.substr(0, 22) + "..."; std::string spacing(maxLen + 2 - methodName.size(), ' '); std::string spacing2((full?maxServiceLength:17) + 2 - serviceName.size(), ' '); std::cout << serviceName << spacing2 << methodName << spacing << std::setw(6) << (((ms.user().cumulatedValue() + ms.system().cumulatedValue()) * 100) / interval) << "% " << std::setw(3) << ms.count() << "x " << us(ms.user().cumulatedValue() / (float)ms.count()) << ' ' << us(ms.user().minValue()) << ' ' << us(ms.user().maxValue()) << " " << us(ms.system().cumulatedValue() / (float)ms.count()) << ' ' << us(ms.system().minValue()) << ' ' << us(ms.system().maxValue()) << " " << us(ms.wall().cumulatedValue() / (float)ms.count()) << ' ' << us(ms.wall().minValue()) << ' ' << us(ms.wall().maxValue()) << " " << std::endl; } } }