The ScriptToolbox provides a collection of miscellaneous utility methods used when writing xTuple ERP extension scripts. More...
#include <scripttoolbox.h>
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... | |
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... | |
QObject * | costVal () |
Get a standard Cost QValidator. More... | |
QObject * | createGridLayout () |
Create a new QGridLayout. More... | |
QObject * | createLayout (const QString &className, QWidget *parent, const QString &name=QString()) |
Create a new layout based on the name of the desired class. More... | |
QWidget * | createWidget (const QString &className, QWidget *parent=0, const QString &name=QString()) |
Create a widget based on the name of the desired class. More... | |
QObject * | customVal (const QString &ReqExp) |
This functions takes a regexp string and creates and returns a QRegExpValidator. More... | |
QObject * | dayVal () |
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 ¶ms) |
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 ¶ms) |
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) |
QObject * | getCreditCardProcessor () |
Get the CreditCardProcessor object for the default service. More... | |
QString | getCurrentDir () |
QString | getFileName (const QString &path) |
QString | getHomeDir () |
QString | getTempDir () |
QWidget * | lastWindow () 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 row, int column, int alignment=0) |
Insert a QWidget 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 | 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... | |
QWidget * | loadUi (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... | |
QObject * | menuAddAction (QObject *menu, const QString &text, const bool enabled=true) |
Add an action to an existing QMenu. More... | |
QObject * | menuAddMenu (QObject *menu, const QString &text, const QString &name=QString()) |
Add an action to an existing QMenu. More... | |
QObject * | menuAddSeparator (QObject *menu) |
Add a separator to an existing QMenu. More... | |
QObject * | menuInsertAction (QObject *menu, QObject *before, const QString &name=QString(), const bool enabled=true) |
Insert an action into an existing QMenu. More... | |
QObject * | menuInsertMenu (QObject *menu, QObject *before, const QString &name) |
Insert a QMenu into an existing QMenu. More... | |
QObject * | menuInsertSeparator (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... | |
QObject * | moneyVal () |
Get a standard Money QValidator. More... | |
QObject * | negMoneyVal () |
Get a standard Negative Money QValidator. More... | |
QWidget * | newDisplay (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... | |
QWidget * | openWindow (const QString pname, QWidget *parent=0, Qt::WindowModality modality=Qt::NonModal, Qt::WindowFlags flags=0) |
Open a new scripted or core application window. More... | |
QObject * | orderVal () |
Get a standard Order QValidator. More... | |
QObject * | percentVal () |
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... | |
QObject * | priceVal () |
Get a standard Price QValidator. More... | |
bool | printReport (const QString &name, const ParameterList ¶ms, const QString &pdfFilename=QString::null) |
Use the embedded OpenRPT to print a named report. More... | |
bool | printReport (const QString &name, const ParameterList ¶ms, const bool preview, QWidget *parent=0) |
Use the embedded OpenRPT to print or preview a named report. More... | |
bool | printReportCopies (const QString &name, const ParameterList ¶ms, int copies) |
Print multiple copies of a single report. More... | |
QObject * | qtyPerVal () |
Get a standard Quantity Per QValidator. More... | |
QObject * | qtyVal () |
Get a standard Quantity QValidator. More... | |
QObject * | ratioVal () |
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 () |
QObject * | runTimeVal () |
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... | |
QWidget * | tabWidget (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... | |
QObject * | TransQtyVal () |
Get a standard Transfer Quantity QValidator. More... | |
QObject * | weightVal () |
Get a standard Weight QValidator. More... | |
QObject * | widgetGetLayout (QWidget *w) |
Get the layout containing the given widget. More... | |
Static Public Member Functions | |
static void | setLastWindow (QWidget *lw) |
Override the last window opened by this toolbox instance. More... | |
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:
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.
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.
engine | The script engine in which to create the toolbox object |
|
virtual |
|
slot |
Add a column to an existing XTreeWidget.
|
slot |
|
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.
sender | The QObject that has emits the signal |
signal | The particular signal that the script needs to intercept |
receiver | The core object coded to receive the signal |
method | The slot (or signal) of the receiver to disconnect |
|
slot |
Get a standard Cost QValidator.
|
slot |
Create a new QGridLayout.
|
slot |
Create a new layout based on the name of the desired class.
This is a wrapper around XUiLoader::createLayout.
className | The name of the class of the desired layout |
parent | The widget that should be set as the parent of the new layout |
name | The name to give the newly-created layout |
|
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:
className | The name of the class of the desired widget |
parent | The widget that should be set as the parent of the new widget |
name | The name to give the newly-created widget |
|
slot |
This functions takes a regexp string and creates and returns a QRegExpValidator.
|
slot |
Get a standard Day QValidator.
|
inline |
This is a wrapper for the C++ core function decimalPlaces.
|
slot |
This is a convenience function that simply begins a database transaction.
|
slot |
This is a convenience function that simply commits the currently open database transaction.
|
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.
%group | The metasql_group value to use when searching for this query |
name | The metasql_name value to use when searching for this query |
|
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.
%group | The metasql_group value to use when searching for this query |
name | The metasql_name value to use when searching for this query |
params | The ParameterList used by MetaSQL to formulate the final 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:
Now the script must loop through the results to inform you of each row found:
Without this loop, the script would have asked the database for the missing exchange rates but nothing would have been done with the results.
query | The database query to execute |
|
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.
query | The MetaSQL string from which to build the query |
params | The ParameterList used by MetaSQL to formulate the final query |
|
slot |
This is a convenience function that simply rolls back the currently open database transaction.
|
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.
parent | The QWidget to set as the parent of the QFileDialog | ||||||||||
caption | The caption to use on the dialog | ||||||||||
dir | Start at the given directory | ||||||||||
filter | A semicolon-separated list of strings to filter the directory contents | ||||||||||
fileModeSel | An 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:
| ||||||||||
acceptModeSel | An integer controlling whether the dialog is to be opened to let the user open a file or save a file
|
|
slot |
|
inline |
This is a wrapper for the C++ core function formatCost.
|
inline |
This is a wrapper for the C++ core function formatDate.
|
inline |
This is a wrapper for the C++ core function formatExtPrice.
|
inline |
This is a wrapper for the C++ core function formatMoney.
|
inline |
This is a wrapper for the C++ core function formatNumber.
|
inline |
This is a wrapper for the C++ core function formatPercent.
|
inline |
This is a wrapper for the C++ core function formatPurchPrice.
|
inline |
This is a wrapper for the C++ core function formatQty.
|
inline |
This is a wrapper for the C++ core function formatQtyPer.
|
inline |
This is a wrapper for the C++ core function formatSalesPrice.
|
inline |
This is a wrapper for the C++ core function formatUOMRatio.
|
inline |
This is a wrapper for the C++ core function formatWeight.
|
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.
|
slot |
|
slot |
|
slot |
|
slot |
|
slot |
Return the last window opened by this instance of the ScriptToolbox.
|
slot |
Insert a QWidget into an existing QBoxLayout.
|
slot |
Insert a QGridLayout into an existing QGridLayout.
|
slot |
Insert a QWidget into an existing QGridLayout.
|
slot |
Insert a QWidget into an existing QGridLayout.
Insert a QWidget into an existing QStackedLayout.
|
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 does 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,
will show a line similar to this:
rather than the usually-more-useful
obj | The object whose properties should be listed |
|
slot |
Load the given QWebView with the given URL.
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.
screenName | The name of the .ui to load (uiform_name ) |
parent | The widget to set as the parent of the loaded .ui |
|
slot |
|
slot |
|
slot |
Add an action to an existing QMenu.
|
slot |
Add an action to an existing QMenu.
Add a separator to an existing QMenu.
|
slot |
Insert an action into an existing QMenu.
|
slot |
Insert a QMenu into an existing QMenu.
Insert a separator into an existing QMenu.
Remove a QAction from a QMenu.
|
slot |
A wrapper around the QMessageBox static methods for standard dialogs.
|
slot |
Get a standard Money QValidator.
|
inline |
This is a wrapper for the C++ core function namedColor.
|
slot |
Get a standard Negative Money QValidator.
|
slot |
|
slot |
Open a web page or open a file with an appropriate application.
This is a wrapper around QDesktopServices::openUrl.
fileUrl | The file or URL to open. |
|
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.
pname | The name of the uiform or core application class of the window to open |
parent | The widget to set as the parent of the newly-created window |
modality | This can be any of the defined Qt::WindowModality values |
flags | This can be any Qt::WindowFlags value |
|
slot |
Get a standard Order QValidator.
|
slot |
Get a standard Percent QValidator.
|
slot |
Populate an XTreeWidget with the results of the given query.
|
slot |
Get a standard Price QValidator.
|
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.
name | The name of the report definition to use |
params | The MetaSQL parameters used to control the report output |
pdfFilename | The name of the PDF file to create. If empty the function uses the standard print methodology |
|
slot |
Use the embedded OpenRPT to print or preview a named report.
Print or preview on-screen the report using the given parameters.
name | The name of the report definition to use |
params | The MetaSQL parameters used to control the report output |
preview | If preview is true, open a report preview window; otherwise print using the standard print methodology |
parent | The parent widget to set for the preview window (optional) |
|
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.
name | The name of the report definition to use |
params | The MetaSQL parameters used to control the report output |
copies | The number of copies to print |
|
slot |
Get a standard Quantity Per QValidator.
|
slot |
Get a standard Quantity QValidator.
|
slot |
Get a standard Ratio QValidator.
|
slot |
|
slot |
|
slot |
|
slot |
|
slot |
Get a standard Run Time QValidator.
|
slot |
Save a credit card definition from a script.
This is a wrapper around creditCard::saveCreditCard().
|
static |
Override the last window opened by this toolbox instance.
|
slot |
This is a wrapper around the core storedProcErrorLookup.
|
slot |
Find the number of tabs in the QTabWidget.
|
slot |
Insert a new tab into a QTabWidget.
|
slot |
Remove a particular tab from a QTabWidget.
|
slot |
Enable or disable a particular tab on a QTabWidget.
|
slot |
Set the text for a particular tab on a QTabWidget.
Get the index of a particular tab in a QTabWidget.
|
slot |
Get the text for a particular tab on a QTabWidget.
Return the QWidget for a particular tab in a QTabWidget.
|
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.
name | The name of the file to open |
|
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.
pName | The name of the file to create |
WriteText | The string to write to the file |
|
slot |
Get a standard Transfer Quantity QValidator.
|
slot |
Get a standard Weight QValidator.
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.
w | The widget whose layout you want to find |
Generated on Fri Oct 7 2016 14:23:32 | xTuple ERP Programmer Reference, Version 4.2.0 | 1.8.10 |