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

void addColumnXTreeWidget (QWidget *tree, const QString &, int, int, bool=true, const QString=QString(), const QString=QString())
 Add a column to an existing XTreeWidget. More...
 
bool copyFile (const QString &oldName, const QString &newName)
 
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...
 
QObjectcostVal ()
 Get a standard Cost QValidator. More...
 
QObjectcreateGridLayout ()
 Create a new QGridLayout. 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...
 
QObjectdayVal ()
 Get a standard Day QValidator. 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...
 
bool fileExists (const QString &name)
 
QObjectgetCreditCardProcessor ()
 Get the CreditCardProcessor object for the default service. More...
 
QString getCurrentDir ()
 
QString getFileName (const QString &path)
 
QString getHomeDir ()
 
QString getTempDir ()
 
QWidgetlastWindow () const
 Return the last window opened by this instance of the ScriptToolbox. More...
 
void layoutBoxInsertWidget (QObject *, int index, QWidget *, int stretch=0, int alignment=0)
 Insert a QWidget into an existing QBoxLayout. More...
 
void layoutGridAddLayout (QObject *, QObject *, int row, int column, int alignment=0)
 Insert a QGridLayout into an existing QGridLayout. More...
 
void layoutGridAddWidget (QObject *, QWidget *, int fromRow, int fromColumn, int rowSpan, int columnSpan, int alignment=0)
 Insert a QWidget into an existing QGridLayout. More...
 
void layoutGridAddWidget (QObject *, QWidget *, int row, int column, int alignment=0)
 Insert a QWidget into an existing QGridLayout. More...
 
void layoutStackedInsertWidget (QObject *, int index, QWidget *)
 Insert a QWidget into an existing QStackedLayout. 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...
 
bool makePath (const QString &mkPath, const QString &rootPath)
 
int menuActionCount (QObject *menu)
 Find the number of QActions in a QMenu. More...
 
QObjectmenuAddAction (QObject *menu, const QString &text, const bool enabled=true)
 Add an action to an existing QMenu. More...
 
QObjectmenuAddMenu (QObject *menu, const QString &text, const QString &name=QString())
 Add an action to an existing QMenu. More...
 
QObjectmenuAddSeparator (QObject *menu)
 Add a separator to an existing QMenu. More...
 
QObjectmenuInsertAction (QObject *menu, QObject *before, const QString &name=QString(), const bool enabled=true)
 Insert an action into an existing QMenu. More...
 
QObjectmenuInsertMenu (QObject *menu, QObject *before, const QString &name)
 Insert a QMenu into an existing QMenu. More...
 
QObjectmenuInsertSeparator (QObject *menu, QObject *before)
 Insert a separator into an existing QMenu. More...
 
void menuRemove (QObject *menu, QObject *action)
 Remove a QAction from a QMenu. More...
 
int messageBox (const QString &type, QWidget *parent, const QString &title, const QString &text, int buttons=0x00000400, int defaultButton=0x00000000)
 A wrapper around the QMessageBox static methods for standard dialogs. More...
 
QObjectmoneyVal ()
 Get a standard Money QValidator. More...
 
QObjectnegMoneyVal ()
 Get a standard Negative Money QValidator. 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...
 
QObjectorderVal ()
 Get a standard Order QValidator. More...
 
QObjectpercentVal ()
 Get a standard Percent QValidator. More...
 
void populateXTreeWidget (QWidget *tree, XSqlQuery pSql, bool=false)
 Populate an XTreeWidget with the results of the given query. More...
 
QObjectpriceVal ()
 Get a standard Price QValidator. 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...
 
QObjectqtyPerVal ()
 Get a standard Quantity Per QValidator. More...
 
QObjectqtyVal ()
 Get a standard Quantity QValidator. More...
 
QObjectratioVal ()
 Get a standard Ratio QValidator. More...
 
bool removeFile (const QString &name)
 
bool removePath (const QString &rmPath, const QString &rootPath)
 
bool renameFile (const QString &oldName, const QString &newName)
 
QString rootPath ()
 
QObjectrunTimeVal ()
 Get a standard Run Time QValidator. 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...
 
int tabCount (QWidget *tab)
 Find the number of tabs in the QTabWidget. More...
 
int tabInsertTab (QWidget *tab, int idx, QWidget *page, const QString &text)
 Insert a new tab into a QTabWidget. More...
 
void tabRemoveTab (QWidget *tab, int idx)
 Remove a particular tab from a QTabWidget. More...
 
void tabSetTabEnabled (QWidget *tab, int idx, bool enable)
 Enable or disable a particular tab on a QTabWidget. More...
 
void tabSetTabText (QWidget *tab, int idx, const QString &text)
 Set the text for a particular tab on a QTabWidget. More...
 
int tabTabIndex (QWidget *tab, QWidget *page)
 Get the index of a particular tab in a QTabWidget. More...
 
QString tabtabText (QWidget *tab, int idx)
 Get the text for a particular tab on a QTabWidget. More...
 
QWidgettabWidget (QWidget *tab, int idx)
 Return the QWidget for a particular tab in a QTabWidget. 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...
 
QObjectTransQtyVal ()
 Get a standard Transfer Quantity QValidator. More...
 
QObjectweightVal ()
 Get a standard Weight QValidator. 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.

Historical note: Many methods in the ScriptToolbox are deprecated. They were created while we were learning how best to integrate QtScript with xTuple ERP. Please do not use these, as they will eventually be removed from the toolbox. The documentation for these deprecated methods refers to better ways to handle relevant situations.

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

◆ addColumnXTreeWidget

void ScriptToolbox::addColumnXTreeWidget ( QWidget tree,
const QString &  pString,
int  pWidth,
int  pAlignment,
bool  pVisible = true,
const QString  pEditColumn = QString(),
const QString  pDisplayColumn = QString() 
)
slot

Add a column to an existing XTreeWidget.

Deprecated:
Use XTreeWidget::addColumn directly.

◆ copyFile

bool ScriptToolbox::copyFile ( const QString &  oldName,
const QString &  newName 
)
slot
Deprecated:
Use QFile.copyFile(oldName, newName) instead

◆ 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

◆ costVal

QObject * ScriptToolbox::costVal ( )
slot

Get a standard Cost QValidator.

Deprecated:
Use mainwindow.costVal() instead.

◆ createGridLayout

QObject * ScriptToolbox::createGridLayout ( )
slot

Create a new QGridLayout.

Deprecated:
Use QGridLayout instead.

◆ 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.

◆ dayVal

QObject * ScriptToolbox::dayVal ( )
slot

Get a standard Day QValidator.

Deprecated:
Use mainwindow.dayVal() instead.

◆ 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

◆ fileExists

bool ScriptToolbox::fileExists ( const QString &  name)
slot
Deprecated:
Use QFile.exists(name) instead

◆ 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

◆ getCurrentDir

QString ScriptToolbox::getCurrentDir ( )
slot
Deprecated:
Use QDir.currentPath() instead

◆ getFileName

QString ScriptToolbox::getFileName ( const QString &  path)
slot
Deprecated:
Use var file = new QFileInfo(path).fileName() instead

◆ getHomeDir

QString ScriptToolbox::getHomeDir ( )
slot
Deprecated:
Use QDir.homePath() instead

◆ getTempDir

QString ScriptToolbox::getTempDir ( )
slot
Deprecated:
Use QDir.tempPath() instead

◆ lastWindow

QWidget * ScriptToolbox::lastWindow ( ) const
slot

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

◆ layoutBoxInsertWidget

void ScriptToolbox::layoutBoxInsertWidget ( QObject obj,
int  index,
QWidget widget,
int  stretch = 0,
int  alignment = 0 
)
slot

Insert a QWidget into an existing QBoxLayout.

Deprecated:
Use QBoxLayout::insertWidget directly

◆ layoutGridAddLayout

void ScriptToolbox::layoutGridAddLayout ( QObject parent,
QObject child,
int  row,
int  column,
int  alignment = 0 
)
slot

Insert a QGridLayout into an existing QGridLayout.

Deprecated:
Use QGridLayout::addLayout instead

◆ layoutGridAddWidget [1/2]

void ScriptToolbox::layoutGridAddWidget ( QObject obj,
QWidget widget,
int  fromRow,
int  fromColumn,
int  rowSpan,
int  columnSpan,
int  alignment = 0 
)
slot

Insert a QWidget into an existing QGridLayout.

Deprecated:
Use QGridLayout::addWidget instead.

◆ layoutGridAddWidget [2/2]

void ScriptToolbox::layoutGridAddWidget ( QObject obj,
QWidget widget,
int  row,
int  column,
int  alignment = 0 
)
slot

Insert a QWidget into an existing QGridLayout.

Deprecated:
Use QGridLayout::addWidget instead.

◆ layoutStackedInsertWidget

void ScriptToolbox::layoutStackedInsertWidget ( QObject obj,
int  index,
QWidget widget 
)
slot

Insert a QWidget into an existing QStackedLayout.

Deprecated:
Use QStackedWidget::insertWidget instead.

◆ 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

◆ makePath

bool ScriptToolbox::makePath ( const QString &  mkPath,
const QString &  rootPath 
)
slot
Deprecated:
Use var dir = new QDir(rootPath) followed by dir.mkpath(mkPath) instead

◆ 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

◆ menuAddAction

QObject * ScriptToolbox::menuAddAction ( QObject menu,
const QString &  text,
const bool  enabled = true 
)
slot

Add an action to an existing QMenu.

Deprecated:
Use QMenu::addAction instead.

◆ menuAddMenu

QObject * ScriptToolbox::menuAddMenu ( QObject menu,
const QString &  text,
const QString &  name = QString() 
)
slot

Add an action to an existing QMenu.

Deprecated:
Use QMenu::addAction instead.

◆ menuAddSeparator

QObject * ScriptToolbox::menuAddSeparator ( QObject menu)
slot

Add a separator to an existing QMenu.

Deprecated:
Use QMenu::addSeparator instead.

◆ menuInsertAction

QObject * ScriptToolbox::menuInsertAction ( QObject menu,
QObject before,
const QString &  name = QString(),
const bool  enabled = true 
)
slot

Insert an action into an existing QMenu.

Deprecated:
Use QMenu::insertAction instead.

◆ menuInsertMenu

QObject * ScriptToolbox::menuInsertMenu ( QObject menu,
QObject before,
const QString &  name 
)
slot

Insert a QMenu into an existing QMenu.

Deprecated:
Use QMenu::insertMenu instead.

◆ menuInsertSeparator

QObject * ScriptToolbox::menuInsertSeparator ( QObject menu,
QObject before 
)
slot

Insert a separator into an existing QMenu.

Deprecated:
Use QMenu::insertSeparator instead.

◆ menuRemove

void ScriptToolbox::menuRemove ( QObject menu,
QObject action 
)
slot

Remove a QAction from a QMenu.

Deprecated:
Use QMenu::removeAction instead.

◆ messageBox

int ScriptToolbox::messageBox ( const QString &  type,
QWidget parent,
const QString &  title,
const QString &  text,
int  buttons = 0x00000400,
int  defaultButton = 0x00000000 
)
slot

A wrapper around the QMessageBox static methods for standard dialogs.

Deprecated:
Use QMessageBox.critical, QMessageBox.information, QMessageBox.question, or QMessageBox.warning.

◆ moneyVal

QObject * ScriptToolbox::moneyVal ( )
slot

Get a standard Money QValidator.

Deprecated:
Use mainwindow.moneyVal() instead.

◆ namedColor()

QColor ScriptToolbox::namedColor ( QString  name)
inline

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

◆ negMoneyVal

QObject * ScriptToolbox::negMoneyVal ( )
slot

Get a standard Negative Money QValidator.

Deprecated:
Use mainwindow.negMoneyVal() instead.

◆ 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

◆ orderVal

QObject * ScriptToolbox::orderVal ( )
slot

Get a standard Order QValidator.

Deprecated:
Use mainwindow.orderVal() instead.

◆ percentVal

QObject * ScriptToolbox::percentVal ( )
slot

Get a standard Percent QValidator.

Deprecated:
Use mainwindow.percentVal() instead.

◆ populateXTreeWidget

void ScriptToolbox::populateXTreeWidget ( QWidget tree,
XSqlQuery  pSql,
bool  pUseAltId = false 
)
slot

Populate an XTreeWidget with the results of the given query.

Deprecated:
Use XTreeWidget::populate directly.

◆ priceVal

QObject * ScriptToolbox::priceVal ( )
slot

Get a standard Price QValidator.

Deprecated:
Use mainwindow.priceVal() instead.

◆ 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

◆ qtyPerVal

QObject * ScriptToolbox::qtyPerVal ( )
slot

Get a standard Quantity Per QValidator.

Deprecated:
Use mainwindow.qtyPerVal() instead.

◆ qtyVal

QObject * ScriptToolbox::qtyVal ( )
slot

Get a standard Quantity QValidator.

Deprecated:
Use mainwindow.qtyVal() instead.

◆ ratioVal

QObject * ScriptToolbox::ratioVal ( )
slot

Get a standard Ratio QValidator.

Deprecated:
Use mainwindow.ratioVal() instead.

◆ removeFile

bool ScriptToolbox::removeFile ( const QString &  name)
slot
Deprecated:
Use QFile.removeFile(oldName, newName) instead

◆ removePath

bool ScriptToolbox::removePath ( const QString &  rmPath,
const QString &  rootPath 
)
slot
Deprecated:
Use var dir = new QDir(rootPath) followed by dir.rmpath(rmPath) instead

◆ renameFile

bool ScriptToolbox::renameFile ( const QString &  oldName,
const QString &  newName 
)
slot
Deprecated:
Use QFile.rename(oldName, newName) instead

◆ rootPath

QString ScriptToolbox::rootPath ( )
slot
Deprecated:
Use QDir.rootPath() instead

◆ runTimeVal

QObject * ScriptToolbox::runTimeVal ( )
slot

Get a standard Run Time QValidator.

Deprecated:
Use mainwindow.runTimeVal() instead.

◆ 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.

◆ tabCount

int ScriptToolbox::tabCount ( QWidget tab)
slot

Find the number of tabs in the QTabWidget.

Deprecated:
Use QTabWidget::count directly.

◆ tabInsertTab

int ScriptToolbox::tabInsertTab ( QWidget tab,
int  idx,
QWidget page,
const QString &  text 
)
slot

Insert a new tab into a QTabWidget.

Deprecated:
Use QTabWidget::insertTab directly.

◆ tabRemoveTab

void ScriptToolbox::tabRemoveTab ( QWidget tab,
int  idx 
)
slot

Remove a particular tab from a QTabWidget.

Deprecated:
Use QTabWidget::removeTab directly.

◆ tabSetTabEnabled

void ScriptToolbox::tabSetTabEnabled ( QWidget tab,
int  idx,
bool  enable 
)
slot

Enable or disable a particular tab on a QTabWidget.

Deprecated:
Use QTabWidget::setTabEnabled directly.

◆ tabSetTabText

void ScriptToolbox::tabSetTabText ( QWidget tab,
int  idx,
const QString &  text 
)
slot

Set the text for a particular tab on a QTabWidget.

Deprecated:
Use QTabWidget::setTabText directly.

◆ tabTabIndex

int ScriptToolbox::tabTabIndex ( QWidget tab,
QWidget page 
)
slot

Get the index of a particular tab in a QTabWidget.

Deprecated:
Use QTabWidget::indexOf directly.

◆ tabtabText

QString ScriptToolbox::tabtabText ( QWidget tab,
int  idx 
)
slot

Get the text for a particular tab on a QTabWidget.

Deprecated:
Use QTabWidget::tabText directly.

◆ tabWidget

QWidget * ScriptToolbox::tabWidget ( QWidget tab,
int  idx 
)
slot

Return the QWidget for a particular tab in a QTabWidget.

Deprecated:
Use QTabWidget::widget directly.

◆ 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

◆ TransQtyVal

QObject * ScriptToolbox::TransQtyVal ( )
slot

Get a standard Transfer Quantity QValidator.

Deprecated:
Use mainwindow.transQtyVal() instead.

◆ weightVal

QObject * ScriptToolbox::weightVal ( )
slot

Get a standard Weight QValidator.

Deprecated:
Use mainwindow.weightVal() instead.

◆ 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 Mon May 3 2021 xTuple ERP Programmer Reference, Version 4.12.0 doxygen 1.8.17