mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Improve the help for a calculation
Add help text and plus AND example Improve help pages for calculator
This commit is contained in:
@@ -49,6 +49,7 @@ set(SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaVec3Tools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaEnsembleNameTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaSummaryStringTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaNetworkTools.h
|
||||
)
|
||||
|
||||
set(SOURCE_GROUP_SOURCE_FILES
|
||||
@@ -95,6 +96,7 @@ set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaEnsembleNameTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaVec3Tools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaSummaryStringTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaNetworkTools.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_SOURCE_FILES ${SOURCE_GROUP_SOURCE_FILES})
|
||||
|
||||
102
ApplicationLibCode/Application/Tools/RiaNetworkTools.cpp
Normal file
102
ApplicationLibCode/Application/Tools/RiaNetworkTools.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2022 Equinor ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RiaNetworkTools.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QEventLoop>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QStringList>
|
||||
#include <QUrl>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaNetworkTools::openUrl( const QString& urlString )
|
||||
{
|
||||
QDesktopServices::openUrl( QUrl( urlString ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaNetworkTools::createAndOpenUrlWithFallback( const QString& urlSubString )
|
||||
{
|
||||
QStringList urls;
|
||||
|
||||
QString urlStringWithPrefix = urlSubString.trimmed();
|
||||
if ( urlStringWithPrefix.isEmpty() ) return;
|
||||
if ( urlStringWithPrefix[0] != '/' ) urlStringWithPrefix = '/' + urlStringWithPrefix;
|
||||
|
||||
urls += "https://resinsight.org" + urlStringWithPrefix;
|
||||
urls += "https://opm.github.io/ResInsight-UserDocumentation" + urlStringWithPrefix;
|
||||
|
||||
openUrlWithFallback( urls );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaNetworkTools::openUrlWithFallback( const QStringList& urlList )
|
||||
{
|
||||
for ( const auto& url : urlList )
|
||||
{
|
||||
if ( doesResourceExist( url ) )
|
||||
{
|
||||
QDesktopServices::openUrl( QUrl( url ) );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaNetworkTools::doesResourceExist( const QString& urlString )
|
||||
{
|
||||
// Based on https://karanbalkar.com/posts/sending-http-request-using-qt5/
|
||||
|
||||
// create custom temporary event loop on stack
|
||||
QEventLoop eventLoop;
|
||||
|
||||
// "quit()" the event-loop, when the network request "finished()"
|
||||
QNetworkAccessManager mgr;
|
||||
QObject::connect( &mgr, SIGNAL( finished( QNetworkReply* ) ), &eventLoop, SLOT( quit() ) );
|
||||
|
||||
// the HTTP request
|
||||
const QUrl qurl( urlString );
|
||||
QNetworkRequest request( qurl );
|
||||
QNetworkReply* reply = mgr.get( request );
|
||||
eventLoop.exec(); // blocks stack until "finished()" has been called
|
||||
|
||||
auto statusCode = request.attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt();
|
||||
|
||||
auto error = reply->error();
|
||||
if ( error == QNetworkReply::NoError && statusCode == 200 )
|
||||
{
|
||||
delete reply;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
delete reply;
|
||||
|
||||
return false;
|
||||
}
|
||||
37
ApplicationLibCode/Application/Tools/RiaNetworkTools.h
Normal file
37
ApplicationLibCode/Application/Tools/RiaNetworkTools.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2022 Equinor ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RiaNetworkTools
|
||||
{
|
||||
public:
|
||||
static void openUrl( const QString& urlString );
|
||||
static void createAndOpenUrlWithFallback( const QString& urlSubString );
|
||||
static void openUrlWithFallback( const QStringList& urlList );
|
||||
|
||||
private:
|
||||
static bool doesResourceExist( const QString& urlString );
|
||||
};
|
||||
Reference in New Issue
Block a user