List of all members | Public Slots | Public Member Functions | Static Public Member Functions
ScriptToolbox Class Reference

The ScriptToolbox provides a collection of miscellaneous utility methods used when writing xTuple ERP extension scripts. More...

#include <scripttoolbox.h>

Inheritance diagram for ScriptToolbox:
QObject

Public Slots

bool coreDisconnect (QObject *sender, const QString &signal, QObject *receiver, const QString &method)
 Break a signal/slot or signal/signal connection established in the C++ core. More...
 
QObjectcreateLayout (const QString &className, QWidget *parent, const QString &name=QString())
 Create a new layout based on the name of the desired class. More...
 
QWidgetcreateWidget (const QString &className, QWidget *parent=0, const QString &name=QString())
 Create a widget based on the name of the desired class. More...
 
QObjectcustomVal (const QString &ReqExp)
 This functions takes a regexp string and creates and returns a QRegExpValidator. More...
 
XSqlQuery executeBegin ()
 This is a convenience function that simply begins a database transaction. More...
 
XSqlQuery executeCommit ()
 This is a convenience function that simply commits the currently open database transaction. More...
 
XSqlQuery executeDbQuery (const QString &group, const QString &name)
 Execute a simple query loaded from the metasql table. More...
 
XSqlQuery executeDbQuery (const QString &group, const QString &name, const ParameterList &params)
 Execute a MetaSQL query loaded from the metasql table. More...
 
XSqlQuery executeQuery (const QString &query)
 Execute a simple database query. More...
 
XSqlQuery executeQuery (const QString &query, const ParameterList &params)
 Execute a MetaSQL query. More...
 
XSqlQuery executeRollback ()
 This is a convenience function that simply rolls back the currently open database transaction. More...
 
QString fileDialog (QWidget *parent, const QString &caption, const QString &dir, const QString &filter, int fileModeSel, int acceptModeSel)
 Open a QFileDialog window. More...
 
QObjectgetCreditCardProcessor ()
 Get the CreditCardProcessor object for the default service. More...
 
QWidgetlastWindow () const
 Return the last window opened by this instance of the ScriptToolbox. More...
 
void listProperties (const QScriptValue &obj, const bool showPrototype=true) const
 Show the properties of a QtScript object. More...
 
void loadQWebView (QWidget *webView, const QString &url)
 Load the given QWebView with the given URL. More...
 
QWidgetloadUi (const QString &screenName, QWidget *parent=0)
 Load a .ui definition from the uiform table. More...
 
int menuActionCount (QObject *menu)
 Find the number of QActions in a QMenu. More...
 
QWidgetnewDisplay (const QString pname, QWidget *parent=0, Qt::WindowModality modality=Qt::NonModal, Qt::WindowFlags flags=0)
 
void openUrl (const QString &fileUrl)
 Open a web page or open a file with an appropriate application. More...
 
QWidgetopenWindow (const QString pname, QWidget *parent=0, Qt::WindowModality modality=Qt::NonModal, Qt::WindowFlags flags=0)
 Open a new scripted or core application window. More...
 
bool printReport (const QString &name, const ParameterList &params, const bool preview, QWidget *parent=0)
 Use the embedded OpenRPT to print or preview a named report. More...
 
bool printReport (const QString &name, const ParameterList &params, const QString &pdfFilename=QString::null)
 Use the embedded OpenRPT to print a named report. More...
 
bool printReportCopies (const QString &name, const ParameterList &params, int copies)
 Print multiple copies of a single report. More...
 
int saveCreditCard (QWidget *parent, int custId, QString ccName, QString ccAddress1, QString ccAddress2, QString ccCity, QString ccState, QString ccZip, QString ccCountry, QString ccNumber, QString ccType, QString ccExpireMonth, QString ccExpireYear, int ccId=0, bool ccActive=true)
 Save a credit card definition from a script. More...
 
QString storedProcErrorLookup (const QString proc, const int result)
 This is a wrapper around the core storedProcErrorLookup. More...
 
QString textStreamRead (const QString &name)
 Read the entire contents of a text file. More...
 
bool textStreamWrite (const QString &name, const QString &WriteText)
 Write the given text to the named file. More...
 
QObjectwidgetGetLayout (QWidget *w)
 Get the layout containing the given widget. More...
 

Public Member Functions

 ScriptToolbox (QScriptEngine *engine)
 Create a new ScriptToolbox. More...
 
virtual ~ScriptToolbox ()
 
Q_INVOKABLE int decimalPlaces (QString p)
 This is a wrapper for the C++ core function decimalPlaces. More...
 
Q_INVOKABLE QString formatCost (double val, int curr=-1)
 This is a wrapper for the C++ core function formatCost. More...
 
Q_INVOKABLE QString formatDate (const QDate &pDate)
 This is a wrapper for the C++ core function formatDate. More...
 
Q_INVOKABLE QString formatExtPrice (double val, int curr=-1)
 This is a wrapper for the C++ core function formatExtPrice. More...
 
Q_INVOKABLE QString formatMoney (double val, int curr=-1, int extra=0)
 This is a wrapper for the C++ core function formatMoney. More...
 
Q_INVOKABLE QString formatNumber (double value, int decimals)
 This is a wrapper for the C++ core function formatNumber. More...
 
Q_INVOKABLE QString formatPercent (double val)
 This is a wrapper for the C++ core function formatPercent. More...
 
Q_INVOKABLE QString formatPurchPrice (double val, int curr=-1)
 This is a wrapper for the C++ core function formatPurchPrice. More...
 
Q_INVOKABLE QString formatQty (double val)
 This is a wrapper for the C++ core function formatQty. More...
 
Q_INVOKABLE QString formatQtyPer (double val)
 This is a wrapper for the C++ core function formatQtyPer. More...
 
Q_INVOKABLE QString formatSalesPrice (double val, int curr=-1)
 This is a wrapper for the C++ core function formatSalesPrice. More...
 
Q_INVOKABLE QString formatUOMRatio (double val)
 This is a wrapper for the C++ core function formatUOMRatio. More...
 
Q_INVOKABLE QString formatWeight (double val)
 This is a wrapper for the C++ core function formatWeight. More...
 
Q_INVOKABLE QColor namedColor (QString name)
 This is a wrapper for the C++ core function namedColor. More...
 

Static Public Member Functions

static void setLastWindow (QWidget *lw)
 Override the last window opened by this toolbox instance. More...
 

Detailed Description

The ScriptToolbox provides a collection of miscellaneous utility methods used when writing xTuple ERP extension scripts.

The ScriptToolbox class provides the C++ implementation of the global toolbox object. A toolbox object is created whenever xTuple ERP creates a QScriptEngine, such as starting the application and opening a new window.

Scripts should use these methods by using the toolbox object in the script's global namespace:

var qry = toolbox.executeQuery("SELECT CURRENT_DATE AS result;");

The methods in the class are intended to be used from scripts only. Use the appropriate classes and methods directly if you are writing in C++. The descriptions of individual methods below should point you to the proper C++ classes to use.

See also
initMenu
toolbox
XDialog
XMainWindow
XWidget

Constructor & Destructor Documentation

◆ ScriptToolbox()

ScriptToolbox::ScriptToolbox ( QScriptEngine *  engine)

Create a new ScriptToolbox.

This constructor should not be called directly except in a small number of places in the xTuple ERP core. It does not install the toolbox object in the engine's global namespace.

Parameters
engineThe script engine in which to create the toolbox object

◆ ~ScriptToolbox()

ScriptToolbox::~ScriptToolbox ( )
virtual

Member Function Documentation

◆ coreDisconnect

bool ScriptToolbox::coreDisconnect ( QObject sender,
const QString &  signal,
QObject receiver,
const QString &  method 
)
slot

Break a signal/slot or signal/signal connection established in the C++ core.

Much of the behavior in the core application is controlled by Qt signal/slot connections. To modify certain behaviors, scripts need to break the connection between signals emitted by core objects and the core slots.

Note that a single object can emit several signals at different times and that each signal can have multiple recipients. Make sure the script disconnects all of the required signal/slot pairs and only those required.

The caller is responsible for ensuring that the original behavior gets restored or appropriately modified. For example, if a script disconnects a Save button's clicked signal from a core method to save the data, that script developer takes responsibility to either save the data in the script or call the core's save method at an appropriate time.

Parameters
senderThe QObject that has emits the signal
signalThe particular signal that the script needs to intercept
receiverThe core object coded to receive the signal
methodThe slot (or signal) of the receiver to disconnect
Returns
Returns true if the connection is successfully broken; otherwise false
See also
QObject::disconnect
Todo:
Add an example to sample_scripts

◆ createLayout

QObject * ScriptToolbox::createLayout ( const QString &  className,
QWidget parent,
const QString &  name = QString() 
)
slot

Create a new layout based on the name of the desired class.

This is a wrapper around XUiLoader::createLayout.

Parameters
classNameThe name of the class of the desired layout
parentThe widget that should be set as the parent of the new layout
nameThe name to give the newly-created layout
Returns
The newly-created layout
See also
qboxlayoutproto.cpp
qgridlayoutproto.cpp
QBoxLayout
QGridLayout

◆ createWidget

QWidget * ScriptToolbox::createWidget ( const QString &  className,
QWidget parent = 0,
const QString &  name = QString() 
)
slot

Create a widget based on the name of the desired class.

This is a wrapper around XUiLoader::createWidget.

The following example creates a new QPushButton:

var _expand = toolbox.createWidget("QPushButton", mywindow, "_expand");
var _collapse = toolbox.createWidget("QPushButton", mywindow, "_collapse");
Parameters
classNameThe name of the class of the desired widget
parentThe widget that should be set as the parent of the new widget
nameThe name to give the newly-created widget
Returns
The newly-created widget

◆ customVal

QObject * ScriptToolbox::customVal ( const QString &  ReqExp)
slot

This functions takes a regexp string and creates and returns a QRegExpValidator.

◆ decimalPlaces()

int ScriptToolbox::decimalPlaces ( QString  p)
inline

This is a wrapper for the C++ core function decimalPlaces.

◆ executeBegin

XSqlQuery ScriptToolbox::executeBegin ( )
slot

This is a convenience function that simply begins a database transaction.

◆ executeCommit

XSqlQuery ScriptToolbox::executeCommit ( )
slot

This is a convenience function that simply commits the currently open database transaction.

◆ executeDbQuery [1/2]

XSqlQuery ScriptToolbox::executeDbQuery ( const QString &  group,
const QString &  name 
)
slot

Execute a simple query loaded from the metasql table.

This loads a query string from the metasql table in the xTuple ERP database. This string is then executed as a database query. If the string has MetaSQL tags in it, they are all treated as undefined (the ParameterList is empty).

It is the caller's responsibility to ensure that there is a record in the metasql table that matches the given group and name, and that processing the query string with an empty parameter list will result in valid SQL.

Parameters
%groupThe metasql_group value to use when searching for this query
nameThe metasql_name value to use when searching for this query
Returns
The XSqlQuery object after calling XSqlQuery::exec()
See also
MetaSQLQuery
XSqlQuery
QSqlQuery

◆ executeDbQuery [2/2]

XSqlQuery ScriptToolbox::executeDbQuery ( const QString &  group,
const QString &  name,
const ParameterList &  params 
)
slot

Execute a MetaSQL query loaded from the metasql table.

This loads a query string from the metasql table in the xTuple ERP database. The given ParameterList controls parsing of the string to generate the actual query to execute.

This method executes the query but the caller is responsible for navigating the results and checking for errors.

The following scripted example creates a ParameterList params, populates it with the number of days preauthorized credit card charges are configured to be valid (defaults to 7) and defines some standard text values to display instead of internal codes (e.g. Preauthorization), then queries the database for a list of credit card transactions. The query itself it taken from the metasql table where the metasql_group is ccpayments and the metasql_name is list. The results are then used to populate an XTreeWidget.

function sPopulateTransactions()
{
var params = new Object;
params.preauth = "Preauthorization";
params.charge = "Charge";
params.refund = "Refund/Credit";
params.authorized = "Authorized";
params.approved = "Approved";
params.declined = "Declined/Denied";
params.voided = "Voided";
params.noapproval = "Not Approved";
if (metrics.value("CCValidDays") > 0)
params.ccValidDays = metrics.value("CCValidDays");
else
params.ccValidDays = 7;
_transactions.populate(toolbox.executeDbQuery("ccpayments", "list", params));
}
Parameters
%groupThe metasql_group value to use when searching for this query
nameThe metasql_name value to use when searching for this query
paramsThe ParameterList used by MetaSQL to formulate the final query
Returns
The XSqlQuery object after calling XSqlQuery::exec()
See also
MetaSQLQuery
XSqlQuery
QSqlQuery

◆ executeQuery [1/2]

XSqlQuery ScriptToolbox::executeQuery ( const QString &  query)
slot

Execute a simple database query.

The passed-in string is sent to the database engine for execution. The resulting XSqlQuery object is returned. The calling script is responsible for navigating the results, including reading the query results and checking for errors.

For example, let's say you want a warning every day when you log in about currencies with missing exchange rates. The following lines check the database for currencies that do not have exchange rates defined for today:

var fxqry = toolbox.executeQuery("SELECT curr_abbr, curr_rate "
+ " FROM curr_symbol LEFT OUTER JOIN"
+ " curr_rate ON (curr_symbol.curr_id=curr_rate.curr_id"
+ " AND CURRENT_DATE BETWEEN curr_effective AND curr_expires + 1)"
+ " WHERE curr_rate IS NULL;");

Now the script must loop through the results to inform you of each row found:

while (fxqry.next())
QMessageBox.warning(mainwindow, qsTr("No exchange rate"),
qsTr("%1 has no exchange rate for today.")
.arg(fxqry.value("curr_abbr")));

Without this loop, the script would have asked the database for the missing exchange rates but nothing would have been done with the results.

Parameters
queryThe database query to execute
Returns
The XSqlQuery object after calling XSqlQuery::exec()
See also
QSqlQuery
XSqlQuery

◆ executeQuery [2/2]

XSqlQuery ScriptToolbox::executeQuery ( const QString &  query,
const ParameterList &  params 
)
slot

Execute a MetaSQL query.

The passed-in string is processed as a MetaSQL query and then sent to the database engine for execution. The given ParameterList controls parsing of the string to generate the actual query to execute.

This method executes the query but the caller is responsible for navigating the results and checking for errors.

The following scripted example creates a ParameterList params, sets the site parameter to the internal id of the currently selected _site widget, then queries the database for a list of items associated with that itemsite. The results are then used to populate an XTreeWidget.

function sFillList()
{
var params = new Object;
params.site = _site.id();
var qry = toolbox.executeQuery('SELECT item_id, itemsite_id, item_number, '
+ ' itemsite_loccntrl, itemsite_controlmethod '
+ 'FROM itemsite '
+ ' JOIN item ON (itemsite_item_id=item_id) '
+ 'WHERE itemsite_warehous_id=<? value("site") ?> '
+ 'ORDER BY item_number;',
params);
_itemsite.populate(qry, true);
}
Parameters
queryThe MetaSQL string from which to build the query
paramsThe ParameterList used by MetaSQL to formulate the final query
Returns
The XSqlQuery object after calling XSqlQuery::exec()
See also
MetaSQLQuery
XSqlQuery
QSqlQuery

◆ executeRollback

XSqlQuery ScriptToolbox::executeRollback ( )
slot

This is a convenience function that simply rolls back the currently open database transaction.

◆ fileDialog

QString ScriptToolbox::fileDialog ( QWidget parent,
const QString &  caption,
const QString &  dir,
const QString &  filter,
int  fileModeSel,
int  acceptModeSel 
)
slot

Open a QFileDialog window.

This is a convenience wrapper around common uses for the QFileDialog class. It can be used to open files or directories or to save a file.

Parameters
parentThe QWidget to set as the parent of the QFileDialog
captionThe caption to use on the dialog
dirStart at the given directory
filterA semicolon-separated list of strings to filter the directory contents
fileModeSelAn integer limiting what the user may select. Note that the values accepted here are not the same as the integer values of the named Qt constants:
1QFileDialog::ExistingFile
2QFileDialog::Directory
3QFileDialog::DirectoryOnly
4QFileDialog::ExistingFiles
anything elseQFileDialog::AnyFile
acceptModeSelAn integer controlling whether the dialog is to be opened to let the user open a file or save a file
1QFileDialog::AcceptSave
anything elseQFileDialog::AcceptOpen
See also
QFileDialog

◆ formatCost()

QString ScriptToolbox::formatCost ( double  val,
int  curr = -1 
)
inline

This is a wrapper for the C++ core function formatCost.

◆ formatDate()

QString ScriptToolbox::formatDate ( const QDate &  pDate)
inline

This is a wrapper for the C++ core function formatDate.

◆ formatExtPrice()

QString ScriptToolbox::formatExtPrice ( double  val,
int  curr = -1 
)
inline

This is a wrapper for the C++ core function formatExtPrice.

◆ formatMoney()

QString ScriptToolbox::formatMoney ( double  val,
int  curr = -1,
int  extra = 0 
)
inline

This is a wrapper for the C++ core function formatMoney.

◆ formatNumber()

QString ScriptToolbox::formatNumber ( double  value,
int  decimals 
)
inline

This is a wrapper for the C++ core function formatNumber.

◆ formatPercent()

QString ScriptToolbox::formatPercent ( double  val)
inline

This is a wrapper for the C++ core function formatPercent.

◆ formatPurchPrice()

QString ScriptToolbox::formatPurchPrice ( double  val,
int  curr = -1 
)
inline

This is a wrapper for the C++ core function formatPurchPrice.

◆ formatQty()

QString ScriptToolbox::formatQty ( double  val)
inline

This is a wrapper for the C++ core function formatQty.

◆ formatQtyPer()

QString ScriptToolbox::formatQtyPer ( double  val)
inline

This is a wrapper for the C++ core function formatQtyPer.

◆ formatSalesPrice()

QString ScriptToolbox::formatSalesPrice ( double  val,
int  curr = -1 
)
inline

This is a wrapper for the C++ core function formatSalesPrice.

◆ formatUOMRatio()

QString ScriptToolbox::formatUOMRatio ( double  val)
inline

This is a wrapper for the C++ core function formatUOMRatio.

◆ formatWeight()

QString ScriptToolbox::formatWeight ( double  val)
inline

This is a wrapper for the C++ core function formatWeight.

◆ getCreditCardProcessor

QObject * ScriptToolbox::getCreditCardProcessor ( )
slot

Get the CreditCardProcessor object for the default service.

This is a wrapper around CreditCardProcessor::getProcessor. There is no scriptable way to get a CreditCardProcessor object for a named service provider.

Returns
A CreditCardProcessor object for the current service provider
See also
CreditCardProcessor::getProcessor

◆ lastWindow

QWidget * ScriptToolbox::lastWindow ( ) const
slot

Return the last window opened by this instance of the ScriptToolbox.

◆ listProperties

void ScriptToolbox::listProperties ( const QScriptValue &  obj,
const bool  showPrototype = true 
) const
slot

Show the properties of a QtScript object.

This writes all of the properties of a QtScript object using qWarning. This is a debugging tool, most useful when not using the Qt script debugger. The property list is not sorted and is not generally recursive. This method can show prototype properties in a separately labeled list if the given object has a prototype.

The output has the name of each property and the result of toString() , so properties which are functions show as something like function() . The values which would be returned by these functions are not displayed. For example,

toolbox.listProperties(_aWarehouseClusterWidget);

will show a line similar to this:

id = "function() returning int"

rather than the more useful

id = -1
Parameters
objThe object whose properties should be listed
showPrototypetrue: show the properties of obj 's prototype false: show just the top-level properties of obj

◆ loadQWebView

void ScriptToolbox::loadQWebView ( QWidget webView,
const QString &  url 
)
slot

Load the given QWebView with the given URL.

◆ loadUi

QWidget * ScriptToolbox::loadUi ( const QString &  screenName,
QWidget parent = 0 
)
slot

Load a .ui definition from the uiform table.

Instantiate a new user interface using a .ui definition that has been stored in the uiform table. If multiple rows in the uiform match the given name, the enabled row with the highest uiform_order is used.

Parameters
screenNameThe name of the .ui to load (uiform_name)
parentThe widget to set as the parent of the loaded .ui
Returns
A widget representing the user interface; 0 if no record matches or if there was an error

◆ menuActionCount

int ScriptToolbox::menuActionCount ( QObject menu)
slot

Find the number of QActions in a QMenu.

Parameters
menuThe QMenu whose QAction children you want to count
Returns
The number of QAction objects in the menu or 0 if menu isn't really a QMenu

◆ namedColor()

QColor ScriptToolbox::namedColor ( QString  name)
inline

This is a wrapper for the C++ core function namedColor.

◆ newDisplay

QWidget * ScriptToolbox::newDisplay ( const QString  pname,
QWidget parent = 0,
Qt::WindowModality  modality = Qt::NonModal,
Qt::WindowFlags  flags = 0 
)
slot

◆ openUrl

void ScriptToolbox::openUrl ( const QString &  fileUrl)
slot

Open a web page or open a file with an appropriate application.

This is a wrapper around QDesktopServices::openUrl.

Parameters
fileUrlThe file or URL to open.

◆ openWindow

QWidget * ScriptToolbox::openWindow ( const QString  pname,
QWidget parent = 0,
Qt::WindowModality  modality = Qt::NonModal,
Qt::WindowFlags  flags = 0 
)
slot

Open a new scripted or core application window.

This method opens a new window on the display. It can be defined in its .ui as an XWidget, XDialog, or XMainWindow. If there is a record in the uiform table, this .ui is instantiated; otherwise openWindow opens a core application window with the given name if one exists.

Windows that inherit from QDialog are handled specially. If the modality passed is Qt::NonModal, the modality is changed to Qt::WindowModal. The flags parameter gets Qt::Dialog set even if the caller did not set it. Because of the way the new windows are created, a special mydialog object gets created to allow access to the QDialog properties and methods, such as QDialog::exec.

Parameters
pnameThe name of the uiform or core application class of the window to open
parentThe widget to set as the parent of the newly-created window
modalityThis can be any of the defined Qt::WindowModality values
flagsThis can be any Qt::WindowFlags value
Returns
The newly-opened window; 0 if there was an error

◆ printReport [1/2]

bool ScriptToolbox::printReport ( const QString &  name,
const ParameterList &  params,
const bool  preview,
QWidget parent = 0 
)
slot

Use the embedded OpenRPT to print or preview a named report.

Print or preview on-screen the report using the given parameters.

Parameters
nameThe name of the report definition to use
paramsThe MetaSQL parameters used to control the report output
previewIf preview is true, open a report preview window; otherwise print using the standard print methodology
parentThe parent widget to set for the preview window (optional)
Returns
True if the report printed successfully; false if there was an apparent error printing or previewing

◆ printReport [2/2]

bool ScriptToolbox::printReport ( const QString &  name,
const ParameterList &  params,
const QString &  pdfFilename = QString::null 
)
slot

Use the embedded OpenRPT to print a named report.

Print the report using the given parameters, optionally saving the output to a PDF file.

Parameters
nameThe name of the report definition to use
paramsThe MetaSQL parameters used to control the report output
pdfFilenameThe name of the PDF file to create. If empty the function uses the standard print methodology
Returns
True if the report printed successfully; false if there was an apparent error printing

◆ printReportCopies

bool ScriptToolbox::printReportCopies ( const QString &  name,
const ParameterList &  params,
int  copies 
)
slot

Print multiple copies of a single report.

Print the same report multiple times using the same set of parameters as part of the same print job. This serves as a scriptable replacement for multi-part forms. Note that all copies of the report are identical as only one set of parameters is passed in.

Parameters
nameThe name of the report definition to use
paramsThe MetaSQL parameters used to control the report output
copiesThe number of copies to print
Returns
True if the report printed successfully; false if there was an error or the user canceled printing

◆ saveCreditCard

int ScriptToolbox::saveCreditCard ( QWidget parent,
int  custId,
QString  ccName,
QString  ccAddress1,
QString  ccAddress2,
QString  ccCity,
QString  ccState,
QString  ccZip,
QString  ccCountry,
QString  ccNumber,
QString  ccType,
QString  ccExpireMonth,
QString  ccExpireYear,
int  ccId = 0,
bool  ccActive = true 
)
slot

Save a credit card definition from a script.

This is a wrapper around creditCard::saveCreditCard().

See also
creditCard::saveCreditCard

◆ setLastWindow()

void ScriptToolbox::setLastWindow ( QWidget lw)
static

Override the last window opened by this toolbox instance.

◆ storedProcErrorLookup

QString ScriptToolbox::storedProcErrorLookup ( const QString  proc,
const int  result 
)
slot

This is a wrapper around the core storedProcErrorLookup.

◆ textStreamRead

QString ScriptToolbox::textStreamRead ( const QString &  name)
slot

Read the entire contents of a text file.

This method opens a text file, reads its contents into a string, and closes the file again.

Parameters
nameThe name of the file to open
Returns
The textual content of the file, or "error" if the file could not be opened
See also
QFile
QTextStream

◆ textStreamWrite

bool ScriptToolbox::textStreamWrite ( const QString &  pName,
const QString &  WriteText 
)
slot

Write the given text to the named file.

Create or overwrite a file with the given name, using the given contents. If the file name passed does not contain a suffix, .txt is appended when the file is created.

Parameters
pNameThe name of the file to create
WriteTextThe string to write to the file
Returns
True if successful; false if any errors were detected
See also
QFile
QTextStream

◆ widgetGetLayout

QObject * ScriptToolbox::widgetGetLayout ( QWidget w)
slot

Get the layout containing the given widget.

Search the object hierarchy and find the smallest QLayout that contains the given widget. This lets a script create a new QWidget and insert it into the user interface near another widget.

var _expand = toolbox.createWidget("QPushButton", mywindow, "_expand");
var _collapse = toolbox.createWidget("QPushButton", mywindow, "_collapse");
/* Set the text of those buttons.
qsTr allows the text to be translated while the & creates a hotkey
that can be used to click the button from the keyboard.
*/
_expand.text = qsTr("E&xpand All");
_collapse.text = qsTr("C&ollapse All");
// To position the new buttons, first find the layout container that holds _list
var _layout = toolbox.widgetGetLayout(_list);
/* _layout happens to be a QGridLayout and _list is in row 2, column 0. To put
_expand and _collapse under _list, we place them in rows 3 and 4, col 0.
*/
_layout.addWidget(_expand, 3, 0);
_layout.addWidget(_collapse, 4, 0);
Parameters
wThe widget whose layout you want to find
Returns
A pointer to the layout or 0 if no such layout could be found

The documentation for this class was generated from the following files:

Generated on Fri Apr 9 2021 xTuple ERP Programmer Reference, Version 5.1.0 doxygen 1.8.17