Double text selection in code editor of Qt Creator - qt-creator

How to make a double (triple) text selection in Qt Creator Code Editor, the same as is after inserting code snippet from Parameters menu, which will allow me to do edit simutaneously in different places?
For example: After inserting for snippet
for (int ***index*** = 0; ***index*** < count; ++***index***) {
}
I can change index, and it'll be changed in other places of fors declaration.

In the Qt Editor you can change names of variables, classes, functions, etc. with the Refactor option Rename Symbol. It allows you to change it at all places in one step.
You can activate it through:
either right mouse > Refactor > Rename Symbol Under Cursor;
or in the menu: Tools > C++ > Rename Symbol Under Cursor;
or Shift-Ctrl-R.
Edit:
In the case of the text not being a 'symbol' (variable/class/etc.)
the best option would be Find/Replace to simultaneously change certain text. However to limit it to lines in which the variable is in a for heading you would need a regular expression, which makes it a bit more complex.
For example for:
void func1() {
for(int index=0; index<10; index++) {
//some code...
}
}
void func2()
{
for(int index=0; index<10; index++) {
\\code
}
}
You could use the Regular expression:
for\s*\(\s*(\w+)\s+index([^;]*);\s*index([^;]*);\s+index(.*)\)
and replace it with:
for(\1 i\2; i\3; i\4)
Which results in:
void func1() {
for(int i=0; i<10; i++) {
//some code...
}
}
void func2()
{
for(int i=0; i<10; i++) {
\\code
}
}

Related

Is it possible to put a variable in a key() function?

I am trying to make a calculator in processing. My thought process for how this is going to work is to make a function for if a certain number is pressed on the keyboard. So I would create some sort of for loop or array even that would sense when a number is pressed, and then return true if it goes through the if statements, however, in order for this to work, I would need to put a variable in the place of a specific key on the keyboard. Is this possible?
Code (so far):
void setup() {
size(800,600);
}
void draw() {
background(0);
Nums.create();
}
class Nums {
void create() {
for (int i = 0; i < 9; i++) {
zero(i);
}
}
boolean zero(int amnt) {
if (keyPressed) {
if (key == amnt) {
return true;
} else {
return false;
}
}
}
}
They keyPressed variable and the functions like keyPressed() and keyReleased() are specifically for keyboard input. They don't, and shouldn't, be concerned with on-screen buttons that you click with the mouse.
Instead, you should probably use the mousePressed() function to detect when the mouse is clicked, and then use if statements to figure out which button was clicked. You can use point-rectangle collision detection to detect which button was clicked. There's also a button sketch in the examples that come with the Processing editor.

Changeing imageicons instantly in for loop

I am creating a minesweeper in java. Now my problem is, when the game ends, i want to reveal where the bombs were when the user clicks on one. So i decided to write a function which will be called when one of the bombs are being clicked on. This function will loop over the table(10x10 grid layout), and checks if a tile is a bomb or not. If so, it's image icon will be changed to another one, and i will call a "Thread.sleep(200)". In this way the bombs will appear from the top to the bottom. My problem is, that changing ImageIcons in java is not instant. If i code like i mentioned above the "Thread.sleep(200) will be called, and i have to wait for that, but the icons only show at the end(i suppose when the user gets the input again). How can i reveal the image icons while in for loop?
Here is my code(gombok is my JButton array that i want to change the icon of):
public void gameover() {
for(int i = 0; i < 10; i ++){
for(int j = 0; j < 10; j ++){
if(tiles[i][j].isIsbomb()) {
gombok[i][j].setIcon(bomb);
try {
Thread.sleep(200);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
}
dispose();
System.out.println("Game Over");
}

visual c++ dataGridView cellclick event

I googled about cellclick event in dataGridView for c++. All results are about c#.
My dataGridView1 selection mode is FullRowSelect. My target is when I clicked to any cell (row), detect that row and do something.
int i;
private: System::Void dataGridView1_CellDoubleClick(System::Object^ sender, System::Windows::Forms::DataGridViewCellEventArgs^ e)
{
if (double clicked row 1)
{
int = 1;
}
if (double clicked row 2)
{
int = 2;
}
}
I need any simple example or any source for learning. Thank you.
ok found a solution on c# tutorials and converted for c++-clr
if (e->RowIndex == 1) //that's what i looking for, you can use ColumnIndex too.
{
int = 1;
}
works perfect for c++-clr.
DataGridViewCell.RowIndex Property on msdn helps too.

Adding a condition to Amibroker code

This is my Amibroker code for a 2 bar swing chart, I need to add a condition that if price falls below the previous swing low in one bar, then to treat it as a two bar move. The problem I have is, holding the last swing low price variable to check against todays low. I have commented the problem lines in caps. What I have I thought would work but the condition is not showing up on the swing chart. Can someone tell me what I am doing wrong.Thanks.
_SECTION_BEGIN("2 day swing");
upBar = H>Ref(H,-1);
dnBar = L<Ref(L,-1);
HighBarPrice=LowBarPrice=Null;
inLong=inShort=upCount=dnCount=fupbar=fdnbar=0;
for( i=1; i<BarCount; i++ )
{
if(inLong==0 AND inShort==0)
{
if(upBar[i])
{
upCount=upCount+1;
if(upCount==2)
{
fupbar[i] = 1;
inLong=1;
dnCount=0;
}
}
if(dnBar[i])
{
dnCount=dnCount+1;
if(dnCount==2)
{
fdnbar[i] = 1;
inShort=1;
upCount=0;
}
}
if(inLong==1)
{
if(dnBar[i])
{
dnCount=dnCount+1;
if(L[i]<LowBarPrice) {dnCount=2;} //THIS IS THE PROBLEM
if(dnCount==2)
{
fdnbar[i]=1;
inShort=1;
if(upBar[i])
{
upCount=1;
}
else
{
upCount=0;
}
continue;
}
}
if(upBar[i]) {HighBarPrice=H[i];}
if(upBar[i] AND NOT dnBar[i]){ dnCount=0;}
}
if(inShort==1)
{
if(upBar[i])
{
upCount=upCount+1;
if(H[i]>HighBarPrice) {upCount=2;}
if(upCount==2)
{
fupbar[i]=1;
inLong=1;
if(dnBar[i])
{
dnCount=1;
}
else
{
dnCount=0;
}
continue;
}
}
if(dnBar[i]) {LowBarPrice=L[i];}// DOWN BAR IN SHORT SWING SHOULD GIVE NEW LOW
if(dnBar[i] AND NOT upBar[i]){ upCount=0;}
}
}
// Swing chart drawn here
_SECTION_END();
Your LowBarPrice doesn't have an array indexer on it. Also, you initialize it as null and it stays that way because you never assign any value to it after initialization. So technically, in your condition, you're saying, if L[i] < null.
Write your conditions outside the loop. That'll create an array that will hold your price until you reference it in the loop.
So, for example, initialize LowBarPrice like this:
LowBarPrice = ValueWhen(DownBar, Ref(L,-1));
Thereafter, you'll get the price when you reference it in the loop.
if(L[i] < LowBarPrice[i])
This article really helped me get my head around looping in AmiBroker. It might give some context around your issue. The part that relates specifically to your question is under the section "Array Indexing
http://www.amibrokerforum.com/index.php?topic=50.0

Tree View not getting displayed

I was trying to create a treeview browser for my application but got stuck somewhere.
The treeview isn't getting displayed.
Code:
System::IO::DirectoryInfo^ info = gcnew System::IO::DirectoryInfo(path);
System::IO::Directory^ dir;
if (dir->Exists(path))
{
try
{
array<System::IO::DirectoryInfo^>^ dirs = info->GetDirectories();
if (dirs->Length > 0)
{
for (int i = 0; i < dirs->Length; i++)
{
TreeNode^ node = treeView1->Nodes[0]->Nodes->Add(dirs[i]->Name);
node->ImageIndex = 1;
for (int j = 0; j < dirs[i]->GetFiles()->Length; j++)
{
if (dirs[i]->GetFiles()[j]->Exists)
{
TreeNode^ nodes = treeView1->Nodes[0]->Nodes[node->Index]->Nodes->Add(dirs[i]->GetFiles()[j]->Name);
nodes->ImageIndex = 2;
}
}
}
}
}
catch (Exception^ e)
{
MessageBox::Show(e->Message);
}
}
Did you use splitcontainer and fill in the first section with your data first?
How did you initialize the new treeview class?
Example:
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
[DockingAttribute(DockingBehavior::Ask)]
public ref class TreeView : public Control
Then you can implement treeview and imageview.
For example, ShGetFolderLocation is one way to pull file locations, for windows OS.
Remember you have to populate the view and tell the system to display it for you to see it.
Or just go to: this earlier solution for the same issue
Follow up with the code for nodemouse click or whatever input response you are looking for such as expand or close, go to link and so on.

Resources