void PathDataViewActions::addActionsToMenu(QMenu *menu)
{
    Q_CHECK_PTR(menu);

    if (!shortcutCopyname.isEnabled())
        return;

    if (view->selectionModel()->selectedRows().size() == 1)
        menu->addAction(QIcon(":/icon/file-doc.png"), tr("Copy the filename to clipboard."), this, SLOT(copyFilename()), shortcutCopyname.key());

    QIcon iconRemove(QApplication::style()->standardIcon(QStyle::SP_DialogCloseButton));
    menu->addAction(iconRemove, tr("Remove"), this, SLOT(removeSelectedRows()), shortcutRemove.key());
}
Ejemplo n.º 2
0
/**
 * @brief MenuActions::createActions
 * Creates all the action objects.
 */
void MenuActions::createActions()
{
   newAct = new QAction(QIcon(":/newicon.png"), tr("&New..."), parent());
   newAct->setShortcuts(QKeySequence::New);
   connect(newAct, SIGNAL(triggered()), parent()->parent(), SLOT(addWindow()));

   openAct = new QAction(QIcon(":/openicon.png"), tr("&Open..."), parent());
   openAct->setShortcuts(QKeySequence::Open);
   openAct->setStatusTip(tr("Open an existing file"));
   connect(openAct, SIGNAL(triggered()), this, SLOT(openFile()));

   saveAct = new QAction(QIcon(":/saveicon.png"), tr("&Save"), parent());
   saveAct->setShortcuts(QKeySequence::Save);
   saveAct->setStatusTip(tr("Save the document to disk"));
   connect(saveAct, SIGNAL(triggered()), this, SLOT(saveFile()));

   saveAsAct = new QAction(tr("Save &As..."), parent());
   saveAsAct->setShortcuts(QKeySequence::SaveAs);
   saveAsAct->setStatusTip(tr("Save the document under a new name"));

   copyRowsAct = new QAction(tr("Copy selected rows"), parent());
   copyRowsAct->setShortcuts(QKeySequence::Copy);
   connect(copyRowsAct, SIGNAL(triggered()), parent(), SLOT(copySelectedRows()));
   copyRowsAct->setEnabled(false);

   removeRowsAct = new QAction(tr("Remove the selected rows"), parent());
   removeRowsAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D));
   connect(removeRowsAct, SIGNAL(triggered()), parent(), SLOT(removeSelectedRows()));
   removeRowsAct->setEnabled(false);

   closeWindowAct = new QAction(tr("Close &window"), parent());
   closeWindowAct->setShortcuts(QKeySequence::Close);
   connect(closeWindowAct, SIGNAL(triggered()), parent(), SLOT(close()));

   exitAct = new QAction(tr("&Quit program"), parent());
   exitAct->setShortcuts(QKeySequence::Quit);
   exitAct->setStatusTip(tr("Exit the application"));
   connect(exitAct, SIGNAL(triggered()), parent()->parent(), SLOT(quit()));

   displaySidebarAct = new QAction(tr("Display sidebar"), parent());
   displaySidebarAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_B));
   displaySidebarAct->setCheckable(true);
   displaySidebarAct->setChecked(true);
   connect(displaySidebarAct, SIGNAL(triggered(bool)), this, SLOT(setSidebarVisible(bool)));

   displayFileToolbarAct = new QAction(tr("Display shortcut menu"), parent());
   displayFileToolbarAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M));
   displayFileToolbarAct->setCheckable(true);
   displayFileToolbarAct->setChecked(true);
   connect(displayFileToolbarAct, SIGNAL(triggered(bool)), this, SLOT(setMenubarVisible(bool)));

   displayFileSizeAct = new QAction(tr("Display file size"), parent());
   displayFileSizeAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_F));
   displayFileSizeAct->setCheckable(true);
   displayFileSizeAct->setChecked(true);
   connect(displayFileSizeAct, SIGNAL(triggered(bool)), this, SLOT(setFileSizeVisible(bool)));

   aboutAct = new QAction(tr("&About"), parent());
   aboutAct->setStatusTip(tr("Show the application's About box"));
   connect(aboutAct, SIGNAL(triggered()), this, SLOT(showAboutDialog()));
}
void TableEditor::setupLayout()
{
    // set up agents tab
    agentsModel = new QSqlTableModel(this);
    agentsModel->setTable("agents");
    if (!tableFilter.isEmpty())
        agentsModel->setFilter(tableFilter);
    agentsModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    agentsModel->select();

    agentsTable = new QTableView(this);
    agentsTable->setModel(agentsModel);
    agentsTable->resizeColumnsToContents();
    agentsTable->sortByColumn(0,Qt::AscendingOrder);
    agentsTable->setSortingEnabled(true);

    // set up determinations tab
    determinationsModel = new QSqlTableModel(this);
    determinationsModel->setTable("determinations");
    if (!tableFilter.isEmpty())
        determinationsModel->setFilter(tableFilter);
    determinationsModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    determinationsModel->select();

    determinationsTable = new QTableView(this);
    determinationsTable->setModel(determinationsModel);
    determinationsTable->resizeColumnsToContents();
    determinationsTable->sortByColumn(0,Qt::AscendingOrder);
    determinationsTable->setSortingEnabled(true);

    // set up images tab
    imagesModel = new QSqlTableModel(this);
    imagesModel->setTable("images");
    if (!tableFilter.isEmpty())
        imagesModel->setFilter(tableFilter);
    imagesModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    imagesModel->select();

    imagesTable = new QTableView(this);
    imagesTable->setModel(imagesModel);
    imagesTable->resizeColumnsToContents();
    imagesTable->sortByColumn(19,Qt::AscendingOrder);
    imagesTable->setSortingEnabled(true);

    // set up taxa tab
    taxaModel = new QSqlTableModel(this);
    taxaModel->setTable("taxa");
    if (!tableFilter.isEmpty())
        taxaModel->setFilter(tableFilter);
    taxaModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    taxaModel->select();

    taxaTable = new QTableView(this);
    taxaTable->setModel(taxaModel);
    taxaTable->resizeColumnsToContents();
    taxaTable->sortByColumn(1,Qt::AscendingOrder);
    taxaTable->setSortingEnabled(true);

    // set up organisms tab
    organismsModel = new QSqlTableModel(this);
    organismsModel->setTable("organisms");
    if (!tableFilter.isEmpty())
        organismsModel->setFilter(tableFilter);
    organismsModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    organismsModel->select();

    organismsTable = new QTableView(this);
    organismsTable->setModel(organismsModel);
    organismsTable->resizeColumnsToContents();
    organismsTable->sortByColumn(0,Qt::AscendingOrder);
    organismsTable->setSortingEnabled(true);

    // set up sensu tab
    sensuModel = new QSqlTableModel(this);
    sensuModel->setTable("sensu");
    if (!tableFilter.isEmpty())
        sensuModel->setFilter(tableFilter);
    sensuModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    sensuModel->select();

    sensuTable = new QTableView(this);
    sensuTable->setModel(sensuModel);
    sensuTable->resizeColumnsToContents();
    sensuTable->sortByColumn(0,Qt::AscendingOrder);
    sensuTable->setSortingEnabled(true);

    tabWidget = new QTabWidget(this);
    tabWidget->addTab(agentsTable,"Agents");
    tabWidget->addTab(determinationsTable,"Determinations");
    tabWidget->addTab(imagesTable,"Images");
    tabWidget->addTab(taxaTable,"Names");
    tabWidget->addTab(organismsTable,"Organisms");
    tabWidget->addTab(sensuTable,"Sensu");

    submitButton = new QPushButton(tr("&Save changes"));
    submitButton->setDefault(true);
    refreshButton = new QPushButton(tr("&Revert unsaved changes\nand refresh database"));
    deleteButton = new QPushButton(tr("&Delete selected rows"));
    quitButton = new QPushButton(tr("&Close"));

    buttonBox = new QDialogButtonBox(Qt::Vertical);
    buttonBox->addButton(submitButton, QDialogButtonBox::ActionRole);
    buttonBox->addButton(deleteButton, QDialogButtonBox::ActionRole);
    buttonBox->addButton(refreshButton, QDialogButtonBox::ActionRole);
    buttonBox->addButton(quitButton, QDialogButtonBox::ActionRole);

    connect(submitButton, SIGNAL(clicked()), this, SLOT(submit())); // this needs to save (submit) all changes from all tables
    connect(refreshButton, SIGNAL(clicked()), this, SLOT(refreshAll())); // this needs to refresh all tables to their current database values
    connect(deleteButton, SIGNAL(clicked()), this, SLOT(removeSelectedRows())); // this needs to remove selected rows ONLY from current tab
    connect(quitButton, SIGNAL(clicked()), this, SLOT(confirmClose()));

    QHBoxLayout *mainLayout = new QHBoxLayout;
    mainLayout->addWidget(tabWidget);
    mainLayout->addWidget(buttonBox);
    setLayout(mainLayout);

    setWindowTitle("Table view");

    QSqlDatabase db = QSqlDatabase::database();
    db.transaction();

    QSqlQuery qry;
    qry.prepare("SELECT value FROM settings WHERE setting = (?)");
    qry.addBindValue("view.table.location");
    qry.exec();
    if (qry.next())
        restoreGeometry(qry.value(0).toByteArray());

    bool wasMaximized = false;
    qry.prepare("SELECT value FROM settings WHERE setting = (?)");
    qry.addBindValue("view.table.fullscreen");
    qry.exec();
    if (qry.next())
        wasMaximized = qry.value(0).toBool();

    if (!db.commit())
    {
        qDebug() << "Problem committing changes to database in TableEditor::setupLayout()";
        db.rollback();
    }

    if (wasMaximized)
        this->showMaximized();
}