• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

E:/sqlmaster/src/manageindexes.cpp

Go to the documentation of this file.
00001 #include "manageindexes.h"
00002 #include "ui_manageindexes.h"
00003 #include <QMessageBox>
00004 ManageIndexes::ManageIndexes(QWidget *parent) :
00005         QDialog(parent),
00006         ui(new Ui::ManageIndexes)
00007 {
00008     ui->setupUi(this);
00009 }
00010 
00011 ManageIndexes::~ManageIndexes()
00012 {
00013     delete ui;
00014 }
00015 
00016 void ManageIndexes::refreshIndexes() {
00017     db.open();
00018     if (db.isOpen()) {
00019         QSqlQuery qu(db);
00020         ui->lineEdit->setText(dbName);
00021         ui->lineEdit_2->setText(tableName);
00022         ui->treeWidget->clear();
00023         if (qu.exec(tr("show keys from `%1`.`%2`").arg(dbName, tableName))) {
00024             while (qu.next()) {
00025                 QSqlRecord rec = qu.record();
00026                 QString indName = rec.value("Key_name").toString();
00027                 QString cols = rec.value("Column_name").toString();
00028                 QTreeWidgetItem *it = new QTreeWidgetItem(ui->treeWidget);
00029                 it->setText(0, indName);
00030                 it->setText(1, cols);
00031                 it->setIcon(0, QIcon("://icons/Icon_43.ico"));
00032             }
00033         }
00034     }
00035 }
00036 
00037 void ManageIndexes::on_cmdNewIndex_clicked()
00038 {
00039     IndexEditor ind(this);
00040     ind.db = db;
00041     ind.dbName = dbName;
00042     ind.tableName = tableName;
00043     ind.newIndex();
00044     if (ind.exec()) {
00045         refreshIndexes();
00046     }
00047 }
00048 
00049 void ManageIndexes::on_cmdEditIndex_clicked()
00050 {
00051     IndexEditor ind(this);
00052     ind.db = db;
00053     ind.dbName = dbName;
00054     ind.tableName = tableName;
00055     QString currIndex;
00056     if (ui->treeWidget->selectedItems().count() >0)
00057     {
00058         currIndex = ui->treeWidget->currentItem()->text(0);
00059         if (currIndex != "") {
00060             ind.indexName = currIndex;
00061             ind.editIndex();
00062             if (ind.exec()) {
00063                 refreshIndexes();
00064             }
00065         }
00066     }else {
00067         QMessageBox::warning(this, "Warning", "Select an index to edit.");
00068     }
00069 
00070 }
00071 
00072 void ManageIndexes::on_cmdDeleteIndex_clicked()
00073 {
00074     QString currIndex;
00075     if (ui->treeWidget->selectedItems().count() >0)
00076     {
00077         currIndex = ui->treeWidget->currentItem()->text(0);
00078         if (currIndex != "") {
00079             QSqlQuery qu(db);
00080             if (QMessageBox::question(this, "Confirm Delete", tr("Are you sure you want to delete the index '%1'?").arg(currIndex), QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) {
00081                 if (qu.exec(tr("alter table `%1`.`%2` drop key `%3`").arg(dbName, tableName, currIndex))) {
00082                     refreshIndexes();
00083                 } else {
00084                     QMessageBox::critical(this, "Error", tr("An error occurred while deleting the index '%1'.\n\n").arg(currIndex, qu.lastError().text()));
00085                 }
00086             }
00087         }
00088     }else {
00089         QMessageBox::warning(this, "Warning", "Select an index to delete.");
00090     }
00091 }
00092 
00093 

Generated on Wed Dec 1 2010 08:43:39 for SQL Master by  doxygen 1.7.2