Or you don't understand me and my problem or... I don't know.
You say that the best solution is write for each button sparate menu and actions?
And have in class 3 menu and 3 open, copy and remove functions? please no...
I can't agree with you.
Look what i have now and comment this please
I create enum class
enum class Side {
left, right
} activeSide;
enum class Side {
left, right
} activeSide;
To copy to clipboard, switch view to plain text mode
added all buttons to QButtonGroup with id
buttonGroup.addButton( ui->button1, 1 );
buttonGroup.addButton( ui->button2, 2 );
buttonGroup.addButton( ui->button1, 1 );
buttonGroup.addButton( ui->button2, 2 );
To copy to clipboard, switch view to plain text mode
next connected buttonGroup signal buttonPressed to slot in my class where i detect active button
connect( &buttonGroup, SIGNAL(buttonPressed(int)) , this,
SLOT(registerId(int)) );
void MainWindow::registerId(int currentButton )
{
switch( currentButton ) {
case 1:
activeSide = Side::left;
break;
case 2:
activeSide = Side::right;
break;
}
}
connect( &buttonGroup, SIGNAL(buttonPressed(int)) , this,
SLOT(registerId(int)) );
void MainWindow::registerId(int currentButton )
{
switch( currentButton ) {
case 1:
activeSide = Side::left;
break;
case 2:
activeSide = Side::right;
break;
}
}
To copy to clipboard, switch view to plain text mode
and now i can create only 2 function( independent of number of buttons ).
- one without parameters
- one with parameters as QString
void MainWindow::open()
{
switch( activeSide ) {
case Side::left:
open( ui->button1.text() );
break;
case Side::right:
open( ui->button2.text() );
break;
}
}
void MainWindow
::open(const QString &path
) {
}
void MainWindow::open()
{
switch( activeSide ) {
case Side::left:
open( ui->button1.text() );
break;
case Side::right:
open( ui->button2.text() );
break;
}
}
void MainWindow::open(const QString &path)
{
QDesktopServices::openUrl( QUrl::fromLocalFile( path ) );
}
To copy to clipboard, switch view to plain text mode
What do you think about this code?
Regards,
Bookmarks