/*! 
  Calculate the width of a layout for a given number of
  columns.

  \param numCols Given number of columns
  \param itemWidth Array of the width hints for all items
*/
int QwtDynGridLayout::maxRowWidth(int numCols) const
{
    int col;

    QwtArray<int> colWidth(numCols);
    for ( col = 0; col < (int)numCols; col++ )
        colWidth[col] = 0;

    if ( d_data->isDirty )
        ((QwtDynGridLayout*)this)->updateLayoutCache();

    for ( uint index = 0; 
        index < (uint)d_data->itemSizeHints.count(); index++ )
    {
        col = index % numCols;
        colWidth[col] = qwtMax(colWidth[col], 
            d_data->itemSizeHints[int(index)].width());
    }

    int rowWidth = 2 * margin() + (numCols - 1) * spacing();
    for ( col = 0; col < (int)numCols; col++ )
        rowWidth += colWidth[col];

    return rowWidth;
}
QSize QwtDynGridLayout::sizeHint() const
{
    if ( isEmpty() )
        return QSize();

    const uint numCols = (d_data->maxCols > 0 ) ? d_data->maxCols : itemCount();
    uint numRows = itemCount() / numCols;
    if ( itemCount() % numCols )
        numRows++;

    QwtArray<int> rowHeight(numRows);
    QwtArray<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];

    int w = 2 * margin() + (numCols - 1) * spacing(); 
    for ( int col = 0; col < (int)numCols; col++ )
        w += colWidth[col];

    return QSize(w, h);
}
예제 #3
0
QList<QRect> QwtDynGridLayout::layoutItems( const QRect &rect,
    uint numCols ) const
{
    QList<QRect> itemGeometries;
    if ( numCols == 0 || isEmpty() )
        return itemGeometries;

    uint numRows = itemCount() / numCols;
    if ( numRows % itemCount() )
        numRows++;

    QVector<int> rowHeight( numRows );
    QVector<int> colWidth( numCols );

    layoutGrid( numCols, rowHeight, colWidth );

    bool expandH, expandV;
    expandH = expandingDirections() & Qt::Horizontal;
    expandV = expandingDirections() & Qt::Vertical;

    if ( expandH || expandV )
        stretchGrid( rect, numCols, rowHeight, colWidth );

    const int maxCols = d_data->maxCols;
    d_data->maxCols = numCols;
    const QRect alignedRect = alignmentRect( rect );
    d_data->maxCols = maxCols;

    const int xOffset = expandH ? 0 : alignedRect.x();
    const int yOffset = expandV ? 0 : alignedRect.y();

    QVector<int> colX( numCols );
    QVector<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;
}
예제 #4
0
void ToyExperiments::printSetup() const {
  char txt[100];
  std::vector< std::vector<TString> > table;
  std::vector<TString> headCells;
  headCells.push_back("bin");
  headCells.push_back("bkg");
  headCells.push_back("tot unc");
  headCells.push_back("uncorr unc");
  headCells.push_back("corr unc");
  headCells.push_back("observed");
  table.push_back(headCells);
  for(unsigned int bin = 0; bin < Parameters::nBins(); ++bin) {
    std::vector<TString> cells;
    sprintf(txt,"%d",static_cast<int>(bin));
    cells.push_back(txt);
    sprintf(txt,"%.2lf",meanPredictions_.at(bin));
    cells.push_back(txt);
    sprintf(txt,"%.2lf",sqrt( uncorrelatedUncerts_.at(bin)*uncorrelatedUncerts_.at(bin) + correlatedUncerts_.at(bin)*correlatedUncerts_.at(bin) ));
    cells.push_back(txt);
    sprintf(txt,"%.2lf",uncorrelatedUncerts_.at(bin));
    cells.push_back(txt);
    sprintf(txt,"%.2lf",correlatedUncerts_.at(bin));
    cells.push_back(txt);
    sprintf(txt,"%u",observedYields_.at(bin));
    cells.push_back(txt);

    table.push_back(cells);
  }

  std::vector<int> colWidth(table.front().size(),0);
  for(unsigned int row = 0; row < table.size(); ++row) {
    for(unsigned int col = 0; col < table.at(row).size(); ++col) {
      if( table.at(row).at(col).Length() > colWidth.at(col) ) {
	colWidth.at(col) = table.at(row).at(col).Length();
      }
    }
  }
  for(unsigned int row = 0; row < table.size(); ++row) {
    for(unsigned int col = 0; col < table.at(row).size(); ++col) {
      while( table.at(row).at(col).Length() < colWidth.at(col) ) {
	table.at(row).at(col) = " "+table.at(row).at(col);
      }
    }
  }

  std::cout << "\n\n----- Setup -----" << std::endl;
  for(unsigned int row = 0; row < table.size(); ++row) {
    std::cout << " | ";
    for(unsigned int col = 0; col < table.at(row).size(); ++col) {
      std::cout << table.at(row).at(col) << " | ";
    }
    std::cout << std::endl;
  }
}
int QwtDynGridLayout::heightForWidth(int width) const
{
    if ( isEmpty() )
        return 0;

    const uint numCols = columnsForWidth(width);
    uint numRows = itemCount() / numCols;
    if ( itemCount() % numCols )
        numRows++;

    QwtArray<int> rowHeight(numRows);
    QwtArray<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;
}
예제 #6
0
bool AdminPlugin::parseMessage(gloox::Stanza* s, const QStringList& flags)
{
	Q_UNUSED(flags)

	MessageParser parser(s);
	parser.nextToken();
	QString cmd=parser.nextToken().toUpper();

	if (cmd=="QUIT")
	{
		if (isFromBotOwner(s))
		{
			reply(s, "Ok");

			bot()->onQuit("QUIT command from bot owner");
		}
		else
		{
			reply(s, "Only owner can do this");
		}
		return true;
	}
	if (cmd=="ROLES")
	{
		if (isFromBotOwner(s))
		{
			QString res;
			RoleList *list=bot()->roles();
			int cnt=list->keys().count();
			for (int i=0; i<cnt; i++)
			{
				res+=QString("\n%1: %2").arg(list->keys()[i]).arg(list->get(list->keys()[i]));
			}
			reply(s, QString("Roles: %1").arg(res));
		}
		else
		{
			reply(s, "Only owner can do this");
		}
		return true;
	}

	if (cmd=="ASYNCCOUNT")
	{
		reply(s, QString("Async requests count: %1").arg(bot()->asyncRequests()->count()));
		return true;
	}

	if (cmd=="ASYNCLIST")
	{
		if (isFromBotOwner(s))
		{
			int cnt=bot()->asyncRequests()->count();
			if (cnt==0)
				reply(s, "No async requests found");
			else
			{
				QString res;
				for (int i=0; i<cnt; i++)
				{
					AsyncRequest *req=bot()->asyncRequests()->at(i);
					QString plugin;
					QString stanza;
					if (req->plugin())
						plugin=req->plugin()->name();
					else
						plugin="UNKNOWN";
					if (req->stanza())
					{
						stanza=QString::fromStdString(req->stanza()->body());
						stanza.replace('\n', ' ');
					}
					res+=QString("\n%1: %2 | %3").arg(plugin).arg(req->name()).arg(stanza);
				}
				reply(s, "Active async requests: "+res);
			}
		}
		else
			reply(s, "Only owner can do this");
		return true;
	}

	if (cmd=="PRESENCE")
	{
		if (!isFromBotOwner(s))
		{
			reply(s, "Only owner can do this");
			return true;
		}
		QString pr=parser.nextToken().toUpper();
		gloox::Presence presence=presenceFromString(pr);
		if (presence==gloox::PresenceUnknown)
		{
			reply(s, "Available presences: available, away, xa, dnd, chat");
			return true;
		}
		QString status=parser.nextToken();
		bot()->client()->setPresence(presence, status, bot()->getPriority());
		return true;
	}

	if (cmd=="PRESENCEJID")
	{
		if (!isFromBotOwner(s))
		{
			reply(s, "Only owner can do this");
			return true;
		}

		QString target=parser.nextToken();

		QString pr=parser.nextToken().toUpper();
		gloox::Presence presence=presenceFromString(pr);
		if (presence==gloox::PresenceUnknown)
		{
			reply(s, "Syntax: presencejid JID PRESENCE STATUS.\n"
				"Available presences: available, away, xa, dnd, chat");
			return true;
		}

		QString status=parser.nextToken();
		bot()->client()->setPresence(target, presence, status);
		return true;
	}

	if (cmd=="SUBSCRIBE")
	{
		if (!isFromBotOwner(s))
		{
			reply(s, "Only owner can do this");
			return true;
		}
		QString target=parser.nextToken();
		if (target.isEmpty())
		{
			reply(s, "Syntax: subscribe JID");
		}
		else
		{
			gloox::Stanza* st;
			st=gloox::Stanza::createSubscriptionStanza(target.toStdString(),
					"GluxiBot subscribed", gloox::StanzaS10nSubscribed);
			bot()->client()->send(st);
			st=gloox::Stanza::createSubscriptionStanza(target.toStdString(),
					"GluxiBot subscription request", gloox::StanzaS10nSubscribe);
			bot()->client()->send(st);
			bot()->client()->setPresence(target, gloox::PresenceChat, QString::null);
			reply(s, "Request sent");
		}
		return true;
	}

	if (cmd=="SQL")
	{
		if (!isFromBotOwner(s))
		{
			reply(s, "Only bot owner can do this");
			return true;
		}

		QString query=parser.joinBody();
		QString queryUp=query.toUpper();
		int idx=0;
		while (!restrictedTerms[idx].isEmpty())
		{
			int ps=queryUp.indexOf(restrictedTerms[idx]+" ");
			if (ps>=0)
			{
				reply(s, QString("Restricted term found: %1 (at %2)")
						.arg(restrictedTerms[idx]).arg(ps));
				return true;
			}
			++idx;
		}

		QSqlQuery sql=DataStorage::instance()->prepareQuery(query);
		if (!sql.exec())
		{
			reply(s,sql.lastError().text());
			return true;
		}
		QSqlRecord rec = sql.record();

		int cnt=rec.count();
		QVector<QVector<QString> > resultTable;

		QVector<QString> line;
		line.reserve(cnt);
		for (int i=0; i<cnt; ++i)
		{
			line.append(rec.fieldName(i));
		}

		resultTable.append(line);
		line.clear();

		int totalRows=0;
		while (sql.next())
		{
			line.clear();
			for (int i=0; i<cnt; ++i)
				line.append(sql.value(i).toString());
			resultTable.append(line);
			if (++totalRows==10)
				break;
		}

		QVector<int> colWidth(cnt);
		colWidth.fill(0);

		for (int row=0; row<resultTable.count(); ++row)
			for (int col=0; col<cnt; ++col)
				if (resultTable[row][col].length()>colWidth[col])
					colWidth[col]=resultTable[row][col].length();

		QString result;
		for (int row=0; row<resultTable.count(); ++row)
		{
			QString line;
			QVector<QString> rowVector=resultTable[row];
			for (int col=0; col<cnt; ++col)
			{
				QString term=rowVector[col];
				int l=term.length();
				int maxL=colWidth[col];
				line+=term;
				line+=QString().fill(' ',(maxL-l)/TAB_SIZE + 1);
			}
			result+="\n"+line;
		}

		reply(s,QString("Result:")+result);
		return true;
	}

	return false;
}
예제 #7
0
void PageView::layoutPages(bool zoomChanged)
{
  // Paranoid safety check
  if (widgetList == 0)
    return;

  // If there are no widgets, e.g. because the last widget has been
  // removed, the matter is easy: set the contents size to 0. If there
  // are no widgets because previously existing widgets were removed
  // (we detect that by looking at the contentsWidth and -Height).
  if (widgetList->isEmpty()) {
    if ((contentsWidth() != 0) || (contentsHeight() != 0)) {
      QScrollView::resizeContents(0,0);
    }
    return;
  }

  // Ok, now we are in a situation where we do have some widgets that
  // shall be centered.
  int distance = distanceBetweenWidgets;
  if (singlePageFullScreenMode())
  {
    // In single page fullscreen mode we don't want a margin around the pages
    distance = 0;
  }

  QMemArray<Q_UINT32> colWidth(nrCols);
  for(Q_UINT8 i=0; i<colWidth.size(); i++)
    colWidth[i] = 0;

  Q_UINT16 numRows;
  if(nrCols <= 2)
  {
    numRows = (widgetList->size()+2*nrCols-2) / nrCols;
  }
  else
  {
    numRows = (Q_INT16)ceil(((double)widgetList->size()) / nrCols);
  }

  QMemArray<Q_UINT32> rowHeight(numRows);
  for(Q_UINT16 i=0; i<rowHeight.size(); i++)
    rowHeight[i] = 0;

  // Now find the widths and heights of the columns
  for(Q_UINT16 i=0; i<widgetList->size(); i++) 
  {
    Q_UINT8 col;
    Q_UINT16 row;

    if (nrCols == 2) {
      // In two-column display, start with the right column
      col = (i+1+nrCols) % nrCols;
      row = (i+1+nrCols) / nrCols - 1;
    } else {
      col = (i+nrCols) % nrCols;
      row = (i+nrCols) / nrCols - 1;
    }

    colWidth[col] = QMAX(colWidth[col], (Q_UINT32)widgetList->at(i)->pageSize().width());
    rowHeight[row] = QMAX(rowHeight[row], (Q_UINT32)widgetList->at(i)->pageSize().height());
  }

  // Calculate the total width and height of the display
  Q_UINT32 totalHeight = 0;
  for(Q_UINT16 i=0; i<rowHeight.size(); i++)
    totalHeight += rowHeight[i];

  totalHeight += (numRows+1)*distance;
  Q_UINT32 totalWidth = 0;
  for(Q_UINT8 i=0; i<colWidth.size(); i++)
    totalWidth += colWidth[i];

  totalWidth += (nrCols+1)*distance;
  QSize newViewportSize = viewportSize( totalWidth, totalHeight );
  Q_UINT32 centeringLeft = 0;
  if( (Q_UINT32)newViewportSize.width() > totalWidth )
    centeringLeft = ( newViewportSize.width() - totalWidth )/2;
  Q_UINT32 centeringTop = 0;
  if( (Q_UINT32)newViewportSize.height() > totalHeight )
    centeringTop = ( newViewportSize.height() - totalHeight)/2;

  // Resize the viewport
  if (((Q_UINT32)contentsWidth() != totalWidth) || ((Q_UINT32)contentsHeight() != totalHeight))
  {
    // Calculate the point in the coordinates of the contents which is currently at the center of the viewport.
    QPoint midPoint = QPoint(visibleWidth() / 2 + contentsX(), visibleHeight() / 2 + contentsY()); 
    double midPointRatioX = (double)(midPoint.x()) / contentsWidth();
    double midPointRatioY = (double)(midPoint.y()) / contentsHeight();

    resizeContents(totalWidth,totalHeight);

    // If the zoom changed recenter the former midPoint
    if (zoomChanged)
      center((int)(contentsWidth() * midPointRatioX), (int)(contentsHeight() * midPointRatioY));
  }

  // Finally, calculate the left and top coordinates of each row and
  // column, respectively
  QMemArray<Q_UINT32> colLeft(nrCols);
  colLeft[0] = distance;
  for(Q_UINT8 i=1; i<colLeft.size(); i++)
    colLeft[i] = colLeft[i-1]+colWidth[i-1]+distance;

  QMemArray<Q_UINT32> rowTop(numRows);
  rowTop[0] = distance;
  for(Q_UINT16 i=1; i<rowTop.size(); i++)
    rowTop[i] = rowTop[i-1]+rowHeight[i-1]+distance;

  for(Q_UINT16 i=0; i<widgetList->size(); i++) 
  {
    Q_UINT8 col;
    Q_UINT16 row;
    if (nrCols == 2)
    {
      // In two column-mode start with the right column.
      col = (i+nrCols-1) % nrCols;
      row = (i+nrCols-1) / nrCols;
    }
    else
    {
      col = (i+nrCols) % nrCols;
      row = i / nrCols;
    }
    if (nrCols == 2)
    {
      // in 2-column mode right justify the first column, and leftjustify the second column
      int width = widgetList->at(i)->width();
      int left;
      if (col == 0)
        left = centeringLeft + colLeft[col] + colWidth[col]-width + distance/2;
      else
        left = centeringLeft + colLeft[col];
      moveChild( widgetList->at(i), left, centeringTop+rowTop[row]);
    }
    else
    {
      // in single column and overview mode center the widgets
      int widgetWidth = widgetList->at(i)->width();
      int left = centeringLeft + colLeft[col] + ((int)colWidth[col]-widgetWidth)/2;
      moveChild(widgetList->at(i), left, centeringTop+rowTop[row]);
    }
  }
  calculateCurrentPageNumber();
}
예제 #8
0
파일: G_Layer.cpp 프로젝트: nsights/nSIGHTS
void LayerListing::CreateListing()
{
  StdTitle("Multiple Layer Specification");


  AddBoolText("Layer depth specification", enterLayerDepths, "Depth BGS", "Elevation ASL");

  const char* titleStr;
  UnitReal currThick;
  if (enterLayerDepths)
  {
    titleStr = "Depth";
    AddUnitReal("Depth of system bottom", bottomLayerDepth);
    currThick = bottomLayerDepth;
  }
  else
  {
    titleStr = "Elevation";
    AddUnitReal("Elevation of system bottom", bottomLayerElevation);
    currThick = bottomLayerElevation;
  }

  char unitStr[40];
  currThick.MakeUnitString(unitStr, 40);

  LayerStaticSupport::GeoLayerCleanup();

  SubTitle("Geology Layers");

  SC_IntArray colWidth(7, 15);
  SC_BoolArray leftJust(7, false);
  colWidth[0] = 20;
  leftJust[0] = true;
  TableSetup(colWidth, leftJust, 1, 0);
  SetTableCol("ID", titleStr, "Thickness", "Skin?", "Conductivity", "# nodes");
  SetTableCol(1, unitStr);
  SetTableCol(2, unitStr);
  AddNextLine();
  AddNextLine();

  char tempStr[80];
  for (int i = 0; i < geologyLayers.Size(); i++)
  {
    GeologyLayer& currLayer = geologyLayers[i];
    SetTableCol(0, currLayer.intervalID);

    currLayer.GetUserDepthString(tempStr, 80);
    SetTableCol(1, tempStr);

    currLayer.GetUserThickString(tempStr, 80);
    SetTableCol(2, tempStr);

    SetTableBool(3, currLayer.layerHasSkin, "Skin", "No Skin");
    SetTableBool(4, currLayer.layerIsIsotropic, "Isotropic", "Anisotropic");
    SetTableInt(5, currLayer.nintervalNodes);
    AddNextLine();
  }

  SubTitle("Wellbore Zones");

  LayerStaticSupport::WellBoreZoneCleanup();

  colWidth.SetSize(7);
  leftJust.SetSize(7);
  TableSetup(colWidth, leftJust, 1, 0);
  SetTableCol("ID", titleStr, "Thickness", "Type", "Delta Volume", "TZ Comp", "# nodes");
  SetTableCol(1, unitStr);
  SetTableCol(2, unitStr);

  char deltaVolUnitStr[40];
  wellboreZoneDeltaVolumeUnits.MakeUnitString(deltaVolUnitStr, 40);
  SetTableCol(4, unitStr);

  char tzCompUnitStr[40];
  wellboreZoneTZCompUnits.MakeUnitString(tzCompUnitStr, 40);
  SetTableCol(5, unitStr);

  AddNextLine();
  AddNextLine();


  for (int i = 0; i < wellBoreZones.Size(); i++)
  {
    WellBoreZone& currZone = wellBoreZones[i];
    SetTableCol(0, currZone.intervalID);

    currZone.GetUserDepthString(tempStr, 80);
    SetTableCol(1, tempStr);

    currZone.GetUserThickString(tempStr, 80);
    SetTableCol(2, tempStr);

    SetTableBool(3, currZone.zoneIsPacker, "Packer", "Zone");

    if (currZone.zoneIsPacker)
    {
      SetTableCol(4, "n/a");
      SetTableCol(5, "n/a");
    }
    else
    {
      currZone.GetUserDeltaVolumeString(tempStr, 80);
      SetTableCol(4, tempStr);
      currZone.GetUserTZCompString(tempStr, 80);
      SetTableCol(5, tempStr);
    }
    SetTableInt(6, currZone.nintervalNodes);

    AddNextLine();
  }

}