Example #1
0
void PsMainWindow::psInitSize() {
	setMinimumWidth(st::wndMinWidth);
	setMinimumHeight(st::wndMinHeight);

	TWindowPos pos(cWindowPos());
	QRect avail(QDesktopWidget().availableGeometry());
	bool maximized = false;
	QRect geom(avail.x() + (avail.width() - st::wndDefWidth) / 2, avail.y() + (avail.height() - st::wndDefHeight) / 2, st::wndDefWidth, st::wndDefHeight);
	if (pos.w && pos.h) {
		QList<QScreen*> screens = App::app()->screens();
		for (QList<QScreen*>::const_iterator i = screens.cbegin(), e = screens.cend(); i != e; ++i) {
			QByteArray name = (*i)->name().toUtf8();
			if (pos.moncrc == hashCrc32(name.constData(), name.size())) {
				QRect screen((*i)->geometry());
				int32 w = screen.width(), h = screen.height();
				if (w >= st::wndMinWidth && h >= st::wndMinHeight) {
					if (pos.w > w) pos.w = w;
					if (pos.h > h) pos.h = h;
					pos.x += screen.x();
					pos.y += screen.y();
					if (pos.x < screen.x() + screen.width() - 10 && pos.y < screen.y() + screen.height() - 10) {
						geom = QRect(pos.x, pos.y, pos.w, pos.h);
					}
				}
				break;
			}
		}

		if (pos.y < 0) pos.y = 0;
		maximized = pos.maximized;
	}
	setGeometry(geom);
}
OsmAnd::RoutePlannerContext::RoutePlannerContext(
    const QList< std::shared_ptr<ObfReader> >& sources,
    const std::shared_ptr<RoutingConfiguration>& routingConfig,
    const QString& vehicle,
    bool useBasemap,
    float initialHeading /*= std::numeric_limits<float>::quiet_NaN()*/,
    QHash<QString, QString>* options /*=nullptr*/,
    size_t memoryLimit  )
    : _useBasemap(useBasemap)
    , _memoryUsageLimit(memoryLimit)
    , _loadedTiles(0)
    , _initialHeading(initialHeading)
    , sources(sources)
    , configuration(routingConfig)
    , _routeStatistics(new RouteStatistics)
    , profileContext(new RoutingProfileContext(configuration->routingProfiles[vehicle], options))
{
    _partialRecalculationDistanceLimit = Utilities::parseArbitraryFloat(configuration->resolveAttribute(vehicle, "recalculateDistanceHelp"), 10000.0f);
    _heuristicCoefficient = Utilities::parseArbitraryFloat(configuration->resolveAttribute(vehicle, "heuristicCoefficient"), 1.0f);
    _planRoadDirection = Utilities::parseArbitraryInt(configuration->resolveAttribute(vehicle, "planRoadDirection"), 0);
    _roadTilesLoadingZoomLevel = Utilities::parseArbitraryUInt(configuration->resolveAttribute(vehicle, "zoomToLoadTiles"), DefaultRoadTilesLoadingZoomLevel);

    for(auto itSource = sources.cbegin(); itSource != sources.cend(); ++itSource)
    {
        const auto& source = *itSource;

        const auto& obfInfo = source->obtainInfo();
        for(auto itRoutingSection = obfInfo->routingSections.cbegin(); itRoutingSection != obfInfo->routingSections.cend(); ++itRoutingSection)
            _sourcesLUT.insert((*itRoutingSection).get(), source);
    }
}
void printDifference(const LogOutput &actual, const LogOutput &expected)
{
    QTextStream out(stderr);

    const QList<QByteArray> actualLines = actual.text.split('\n');
    const QList<QByteArray> expectedLines = expected.text.split('\n');

    out << "-- ACTUAL:\n";
    printRawLines(out, actualLines);
    out << "-- EXPECTED:\n";
    printRawLines(out, expectedLines);

    if (actualLines.size() != expectedLines.size()) {
        out << "-- DIFFERENCE IN LINE COUNT:\n"
            << "    actual lines:" << actualLines.size() << '\n'
            << "  expected lines:" << expectedLines.size() << '\n';
    }

    out << "-- FIRST LINE THAT DIFFERS:\n";
    auto actualLineIt = actualLines.cbegin();
    auto expectedLineIt = expectedLines.cbegin();
    int line = 1;
    forever {
        if (actualLineIt == actualLines.cend() && expectedLineIt != expectedLines.cend()) {
            out << "      line: " << line << '\n';
            out << "    actual: <none>\n";
            out << "  expected: \"" << *expectedLineIt << "\"\n";
        } else if (actualLineIt != actualLines.cend() && expectedLineIt == expectedLines.cend()) {
            out << "      line: " << line << '\n';
            out << "    actual: \"" << *actualLineIt << "\"\n";
            out << "  expected: <none>\n";
        } else {
            if (*actualLineIt != *expectedLineIt) {
                out << "      line: " << line << '\n';
                out << "    actual: \"" << *actualLineIt << "\"\n";
                out << "  expected: \"" << *expectedLineIt << "\"\n";
                return;
            }
        }

        ++line;
        ++actualLineIt;
        ++expectedLineIt;
    }
}
/*!
    \internal
 */
qint64 QWebSocketPrivate::writeFrames(const QList<QByteArray> &frames)
{
    qint64 written = 0;
    if (Q_LIKELY(m_pSocket)) {
        QList<QByteArray>::const_iterator it;
        for (it = frames.cbegin(); it < frames.cend(); ++it)
            written += writeFrame(*it);
    }
    return written;
}
Example #5
0
void ApiWrap::requestPeers(const QList<PeerData*> &peers) {
    QVector<MTPint> chats;
    QVector<MTPInputUser> users;
    chats.reserve(peers.size());
    users.reserve(peers.size());
    for (QList<PeerData*>::const_iterator i = peers.cbegin(), e = peers.cend(); i != e; ++i) {
        if (!*i || _fullPeerRequests.contains(*i) || _peerRequests.contains(*i)) continue;
        if ((*i)->chat) {
            chats.push_back(MTP_int(App::chatFromPeer((*i)->id)));
        } else {
            users.push_back((*i)->asUser()->inputUser);
        }
    }
    if (!chats.isEmpty()) MTP::send(MTPmessages_GetChats(MTP_vector<MTPint>(chats)), rpcDone(&ApiWrap::gotChats));
    if (!users.isEmpty()) MTP::send(MTPusers_GetUsers(MTP_vector<MTPInputUser>(users)), rpcDone(&ApiWrap::gotUsers));
}
Example #6
0
void PsMainWindow::psSavePosition(Qt::WindowState state) {
    if (state == Qt::WindowActive) state = windowHandle()->windowState();
	if (state == Qt::WindowMinimized || !posInited) return;

	TWindowPos pos(cWindowPos()), curPos = pos;

	if (state == Qt::WindowMaximized) {
		curPos.maximized = 1;
	} else {
		QRect r(geometry());
		curPos.x = r.x();
		curPos.y = r.y();
		curPos.w = r.width();
		curPos.h = r.height();
		curPos.maximized = 0;
	}

	int px = curPos.x + curPos.w / 2, py = curPos.y + curPos.h / 2, d = 0;
	QScreen *chosen = 0;
	QList<QScreen*> screens = App::app()->screens();
	for (QList<QScreen*>::const_iterator i = screens.cbegin(), e = screens.cend(); i != e; ++i) {
		int dx = (*i)->geometry().x() + (*i)->geometry().width() / 2 - px; if (dx < 0) dx = -dx;
		int dy = (*i)->geometry().y() + (*i)->geometry().height() / 2 - py; if (dy < 0) dy = -dy;
		if (!chosen || dx + dy < d) {
			d = dx + dy;
			chosen = *i;
		}
	}
	if (chosen) {
		curPos.x -= chosen->geometry().x();
		curPos.y -= chosen->geometry().y();
		QByteArray name = chosen->name().toUtf8();
		curPos.moncrc = hashCrc32(name.constData(), name.size());
	}

	if (curPos.w >= st::wndMinWidth && curPos.h >= st::wndMinHeight) {
		if (curPos.x != pos.x || curPos.y != pos.y || curPos.w != pos.w || curPos.h != pos.h || curPos.moncrc != pos.moncrc || curPos.maximized != pos.maximized) {
			cSetWindowPos(curPos);
			Local::writeSettings();
		}
    }
}
Example #7
0
void MainWindow::_show_updatePortNames()
{
  //we extract the names of the currently available serial ports
  QList<QSerialPortInfo> availablePorts = QSerialPortInfo::availablePorts();
  std::list<QString> availablePortNames;
  for(auto it = availablePorts.cbegin(); it != availablePorts.cend(); ++it)
    availablePortNames.push_back(it->portName());

  //has any serial port been closed since the last check?
  for(auto it = m_show_arraySerialPortActions.begin(); it != m_show_arraySerialPortActions.end(); ++it)
  {
    QString currentPortName = (*it)->text();
    bool found = false;
    for(auto jt = availablePortNames.begin(); !found && jt != availablePortNames.end(); ++jt)
      if((*jt) == currentPortName)
      {
        //this serial port is still available, and we already have a QAction for it, we remove it from availablePortNames
        std::cout << "found : " << currentPortName.toStdString() << std::endl;
        jt = availablePortNames.erase(jt);
        found = true;
      }
    if(!found)
    {
      //this serial port is no longer available, we delete it from the GUI.
      m_show_serialPortActionGroup->removeAction(*it);
      m_show_menuSerialPort->removeAction(*it);
      it = m_show_arraySerialPortActions.erase(it);
    }
  }

  //Now, availablePortNames only contains the names of the newly available serial ports.
  for(auto it = availablePortNames.cbegin(); it != availablePortNames.cend(); ++it)
  {
    QAction * serialPortAction = new QAction(*it, this);
    serialPortAction->setCheckable(true);
    m_show_arraySerialPortActions.push_back(serialPortAction);
    m_show_serialPortActionGroup->addAction(serialPortAction);
    m_show_menuSerialPort->addAction(serialPortAction);
  }
}