Tab selection

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Post Reply
sinase
Active Member
Posts: 47
Joined: Sat Jan 30, 2021 11:12 pm

Tab selection

Post by sinase » Wed Jun 30, 2021 10:39 am

Hi,

How can i change my tab selection by script way?

For example, in this image i have selected tab "a" and i want to select tab "c":
tabNavigate.png
tabNavigate.png (42.24 KiB) Viewed 1414 times
I need something like this:
var doc = getDocument("c");
var docIntfc = new RDocumentInterface(document);

But i dont know how it would correctly.

Many thanks.
Regards.

User avatar
andrew
Site Admin
Posts: 7814
Joined: Fri Mar 30, 2007 6:07 am

Re: Tab selection

Post by andrew » Wed Jun 30, 2021 11:40 am

Code: Select all

// find out index of window to show (2 is an example here):
var index = 2;

var mdiArea = EAction.getMdiArea();
var windows = mdiArea.subWindowList();
mdiArea.setActiveSubWindow(windows[index]);

sinase
Active Member
Posts: 47
Joined: Sat Jan 30, 2021 11:12 pm

Re: Tab selection

Post by sinase » Fri Jul 02, 2021 8:34 am

Thanks for your answer, i need to program that in dinamically mode.

Is there a function to return current tab index? Example:

var index = getCurrentIndexTab;
//My code
var mdiArea = EAction.getMdiArea();
var windows = mdiArea.subWindowList();
mdiArea.setActiveSubWindow(windows[index]);

Regards.

User avatar
andrew
Site Admin
Posts: 7814
Joined: Fri Mar 30, 2007 6:07 am

Re: Tab selection

Post by andrew » Tue Jul 06, 2021 9:00 am

You can get the current tab index using QTabBar:

Code: Select all

var appWin = RMainWindowQt.getMainWindow();
var tabBar = appWin.getTabBar();
var idx = tabBar.currentIndex;

sinase
Active Member
Posts: 47
Joined: Sat Jan 30, 2021 11:12 pm

Re: Tab selection

Post by sinase » Tue Jul 20, 2021 5:39 pm

Hi, thank you, the code works. But in my application it doesn't close the exported file and it tries to close the initial tab.

Code: Select all

include("../MyScripts.js");
 
// Constructor calls base class constructor:
function Extraer(guiAction) {
    MyScripts.call(this, guiAction);
}
Extraer.prototype = new MyScripts();
Extraer.prototype.beginEvent = function() {	
	MyScripts.prototype.beginEvent.call(this);
	var appWin = RMainWindowQt.getMainWindow();
	var tabBar = appWin.getTabBar();
	var idx = tabBar.currentIndex;
	
	var action = RGuiAction.getByScriptFile("scripts/Edit/Cut/Cut.js");
	if (!isNull(action)) {
		action.slotTrigger();
	}
	var action = RGuiAction.getByScriptFile("scripts/File/NewFile/NewFile.js");
	if (!isNull(action)) {
		action.slotTrigger();
	}	
	var di = EAction.getDocumentInterface();
	var document = di.getDocument();
	var op = new RPasteOperation(RDocument.getClipboard());
	op.setOffset(new RVector(0,0));
	op.setRotation(0.0);
	op.setScale(1.0);
	op.setFlipHorizontal(false);
	op.setFlipVertical(false);
	op.setToCurrentLayer(true);
	op.setOverwriteBlocks(true);
	//op.setCopyEmptyBlocks(true);
	
	di.applyOperation(op);
	di.autoZoom();
	
    var file = new QFile("C:/Planning/Oferta.txt");
    var flags = new QIODevice.OpenMode(QIODevice.ReadOnly | QIODevice.Text);
    if (!file.open(flags)) {
        this.terminate();
        return;
    }
	var ts = new QTextStream(file);
	ts.setCodec("UTF-8");
	var line;
	line = ts.readLine(); //Sólo necesito la linea 1.
	file.close();
	
	di.exportFile("O:/" + line + "/Temp/" + line + ".dxf", "DXF 2000");
	
	var action = RGuiAction.getByScriptFile("scripts/File/CloseFile/CloseFile.js");
	if (!isNull(action)) {
		action.slotTrigger();
	}
	
	var mdiArea = EAction.getMdiArea();
	var windows = mdiArea.subWindowList();
	mdiArea.setActiveSubWindow(windows[idx]);
	
	this.terminate();
};
Extraer.init = function(basePath) {	
    var action = new RGuiAction(qsTr("Extraer"), RMainWindowQt.getMainWindow());
    action.setRequiresDocument(true);
    action.setScriptFile(basePath + "/Extraer.js");
    action.setIcon(basePath + "/Extraer.svg");
	action.setStatusTip(qsTr("Extraer"));
    action.setDefaultShortcut(new QKeySequence("z,z"));
    action.setDefaultCommands(["extraer"]);
    action.setGroupSortOrder(73100);
    action.setSortOrder(400);
    action.setWidgetNames(["MyScriptsMenu"]);
};
I need to close (with CloseFile.js in my code) the exported file, it is not working correctly. If i omit the 3 last lines, it works ok.

Many thanks.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”