@@ -568,57 +568,81 @@ QgsMssqlLayerItem::QgsMssqlLayerItem( QgsDataItem *parent, const QString &name,
568
568
#ifdef HAVE_GUI
569
569
QList<QAction *> QgsMssqlLayerItem::actions ( QWidget *actionParent )
570
570
{
571
- QgsMssqlConnectionItem *connItem = qobject_cast<QgsMssqlConnectionItem *>( parent () ? parent ()->parent () : nullptr );
572
-
573
571
QList<QAction *> lst;
574
572
575
573
// delete
576
- QAction *actionDeleteLayer = new QAction ( tr ( " Delete Table" ), actionParent );
574
+ const QString deleteText = selectedItems ().count () == 1 ? tr ( " Delete Table" )
575
+ : tr ( " Delete Selected Tables" );
576
+ QAction *actionDeleteLayer = new QAction ( deleteText, actionParent );
577
577
connect ( actionDeleteLayer, &QAction::triggered, this , [ = ]
578
578
{
579
- if ( QMessageBox::question ( nullptr , QObject::tr ( " Delete Table" ),
580
- QObject::tr ( " Are you sure you want to delete [%1].[%2]?" ).arg ( mLayerProperty .schemaName , mLayerProperty .tableName ),
581
- QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
582
- return ;
583
-
584
- QString errCause;
585
- bool res = QgsMssqlConnection::dropTable ( mUri , &errCause );
586
- if ( !res )
579
+ QList<QgsDataItem *> items = selectedItems ();
580
+ for ( QgsDataItem *item : items )
587
581
{
588
- QMessageBox::warning ( nullptr , tr ( " Delete Table" ), errCause );
589
- }
590
- else
591
- {
592
- QMessageBox::information ( nullptr , tr ( " Delete Table" ), tr ( " Table deleted successfully." ) );
593
- if ( connItem )
594
- connItem->refresh ();
582
+ if ( QgsMssqlLayerItem *mssqlLayerItem = qobject_cast< QgsMssqlLayerItem *>( item ) )
583
+ mssqlLayerItem->deleteLayer ();
595
584
}
596
585
} );
597
586
lst.append ( actionDeleteLayer );
598
587
599
588
// truncate
600
- QAction *actionTruncateLayer = new QAction ( tr ( " Truncate Table" ), actionParent );
589
+ const QString truncateText = selectedItems ().count () == 1 ? tr ( " Truncate Table" )
590
+ : tr ( " Truncate Selected Tables" );
591
+ QAction *actionTruncateLayer = new QAction ( truncateText, actionParent );
601
592
connect ( actionTruncateLayer, &QAction::triggered, this , [ = ]
602
593
{
603
- if ( QMessageBox::question ( nullptr , QObject::tr ( " Truncate Table" ),
604
- QObject::tr ( " Are you sure you want to truncate [%1].[%2]?\n\n This will delete all data within the table." ).arg ( mLayerProperty .schemaName , mLayerProperty .tableName ),
605
- QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
606
- return ;
607
-
608
- QString errCause;
609
- bool res = QgsMssqlConnection::truncateTable ( mUri , &errCause );
610
- if ( !res )
594
+ QList<QgsDataItem *> items = selectedItems ();
595
+ for ( QgsDataItem *item : items )
611
596
{
612
- QMessageBox::warning ( nullptr , tr ( " Truncate Table" ), errCause );
613
- }
614
- else
615
- {
616
- QMessageBox::information ( nullptr , tr ( " Truncate Table" ), tr ( " Table truncated successfully." ) );
597
+ if ( QgsMssqlLayerItem *mssqlLayerItem = qobject_cast< QgsMssqlLayerItem *>( item ) )
598
+ mssqlLayerItem->truncateTable ();
617
599
}
618
600
} );
619
601
lst.append ( actionTruncateLayer );
620
602
return lst;
621
603
}
604
+
605
+ void QgsMssqlLayerItem::deleteLayer ()
606
+ {
607
+ QgsMssqlConnectionItem *connItem = qobject_cast<QgsMssqlConnectionItem *>( parent () ? parent ()->parent () : nullptr );
608
+
609
+ if ( QMessageBox::question ( nullptr , QObject::tr ( " Delete Table" ),
610
+ QObject::tr ( " Are you sure you want to delete [%1].[%2]?" ).arg ( mLayerProperty .schemaName , mLayerProperty .tableName ),
611
+ QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
612
+ return ;
613
+
614
+ QString errCause;
615
+ bool res = QgsMssqlConnection::dropTable ( mUri , &errCause );
616
+ if ( !res )
617
+ {
618
+ QMessageBox::warning ( nullptr , tr ( " Delete Table" ), errCause );
619
+ }
620
+ else
621
+ {
622
+ QMessageBox::information ( nullptr , tr ( " Delete Table" ), tr ( " Table deleted successfully." ) );
623
+ if ( connItem )
624
+ connItem->refresh ();
625
+ }
626
+ }
627
+
628
+ void QgsMssqlLayerItem::truncateTable ()
629
+ {
630
+ if ( QMessageBox::question ( nullptr , QObject::tr ( " Truncate Table" ),
631
+ QObject::tr ( " Are you sure you want to truncate [%1].[%2]?\n\n This will delete all data within the table." ).arg ( mLayerProperty .schemaName , mLayerProperty .tableName ),
632
+ QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
633
+ return ;
634
+
635
+ QString errCause;
636
+ bool res = QgsMssqlConnection::truncateTable ( mUri , &errCause );
637
+ if ( !res )
638
+ {
639
+ QMessageBox::warning ( nullptr , tr ( " Truncate Table" ), errCause );
640
+ }
641
+ else
642
+ {
643
+ QMessageBox::information ( nullptr , tr ( " Truncate Table" ), tr ( " Table truncated successfully." ) );
644
+ }
645
+ }
622
646
#endif
623
647
624
648
QgsMssqlLayerItem *QgsMssqlLayerItem::createClone ()
0 commit comments