示例#1
0
bool DatabaseTabWidget::closeDatabase(Database* db)
{
    Q_ASSERT(db);

    const DatabaseManagerStruct& dbStruct = m_dbList.value(db);
    int index = databaseIndex(db);
    Q_ASSERT(index != -1);

    QString dbName = tabText(index);
    if (dbName.right(1) == "*") {
        dbName.chop(1);
    }
    if (dbStruct.dbWidget->isInEditMode() && db->hasKey() && dbStruct.dbWidget->isEditWidgetModified()) {
        QMessageBox::StandardButton result =
            MessageBox::question(
            this, tr("Close?"),
            tr("\"%1\" is in edit mode.\nDiscard changes and close anyway?").arg(dbName),
            QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
        if (result == QMessageBox::Cancel) {
            return false;
        }
    }
    if (dbStruct.modified) {
        if (config()->get("AutoSaveOnExit").toBool()) {
            if (!saveDatabase(db)) {
                return false;
            }
        }
        else {
            QMessageBox::StandardButton result =
                MessageBox::question(
                this, tr("Save changes?"),
                tr("\"%1\" was modified.\nSave changes?").arg(dbName),
                QMessageBox::Yes | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Yes);
            if (result == QMessageBox::Yes) {
                if (!saveDatabase(db)) {
                        return false;
                }
            }
            else if (result == QMessageBox::Cancel) {
                return false;
            }
        }
    }

    deleteDatabase(db);

    return true;
}
示例#2
0
void DbModel::insert(QString key, QJSValue callbackFunction)
{
    if(m_name.isEmpty() || key.isEmpty() ||  m_jsonDocument.isNull())
    {
        DEBUG << "cannot insert. name is empty or json document is null";
        if(callbackFunction.isCallable())
        {
            callbackFunction.call(QJSValueList() << 1);
        }
        return;
    }
    QJsonObject root = m_jsonDocument.object();
    QJsonValueRef _arrayRef = root.find(m_name).value();
    QJsonArray _arrayMain = _arrayRef.toArray();
    QVariantMap _obj;
    _obj.insert("name", key);
    _arrayMain.append(QJsonValue::fromVariant(_obj));
    root.insert(m_name, _arrayMain);
    m_jsonDocument.setObject(root);
    qDebug() << m_jsonDocument.toJson();
    saveDatabase();
    if(callbackFunction.isCallable())
    {
        callbackFunction.call(QJSValueList() << 0);
    }
    beginInsertRows(QModelIndex(), _arrayMain.count() - 1, _arrayMain.count() - 1);
    endInsertRows();
}
示例#3
0
bool DatabaseTabWidget::saveDatabase(int index)
{
    if (index == -1) {
        index = currentIndex();
    }

    return saveDatabase(indexDatabase(index));
}
void DatabaseTabWidget::saveDatabase(int index)
{
    if (index == -1) {
        index = currentIndex();
    }

    saveDatabase(indexDatabase(index));
}
示例#5
0
void MainWindow::createActions()
{
	openAction = new QAction(tr("&Otevřít seznam..."), this);
	openAction->setIcon(QIcon(":/images/fileopen.svg"));
	openAction->setShortcut(QKeySequence::Open);
	openAction->setStatusTip(tr("Otevřít existující soubor se seznamem"));
	QObject::connect(openAction, SIGNAL(triggered()),
					 mainWidget, SLOT(openDatabase()));

	saveAction = new QAction(QIcon(":/images/filesave.svg"),
							 tr("&Uložit seznam"), this);
	saveAction->setShortcut(QKeySequence::Save);
	QObject::connect(saveAction, SIGNAL(triggered()),
					 mainWidget, SLOT(saveDatabase()));

	saveAsAction = new QAction(QIcon(":/images/filesaveas.svg"),
							   tr("&Uložit seznam jako..."), this);
	saveAsAction->setShortcut(QKeySequence::SaveAs);
	QObject::connect(saveAsAction, SIGNAL(triggered()),
					 mainWidget, SLOT(saveDatabaseAs()));

	findAction = new QAction(tr("&Vyhledat položku..."), this);
	findAction->setIcon(QIcon(":/images/search.svg"));
	findAction->setShortcut(QKeySequence::Find);
	findAction->setStatusTip(tr("Vyhledat položku v otevřeném seznamu"));
	QObject::connect(findAction, SIGNAL(triggered()),
					 mainWidget, SLOT(findFile()));

	exportAction = new QAction(tr("&Exportovat seznam..."), this);
	exportAction->setIcon(QIcon(":/images/export.svg"));
	exportAction->setShortcut(QKeySequence("Ctrl+E"));
	exportAction->setStatusTip(tr("Exportovat seznam do HTML"));
	QObject::connect(exportAction, SIGNAL(triggered()),
					 mainWidget, SLOT(exportDatabase()));

	settingsAction = new QAction(tr("&Nastavení..."), this);
	settingsAction->setIcon(QIcon(":/images/settings.svg"));
	settingsAction->setStatusTip(tr("Upravit nastavení programu"));
	QObject::connect(settingsAction, SIGNAL(triggered()),
					 mainWidget, SLOT(editSettings()));

	viewPhoneListAction = new QAction(tr("&Zobrazit seznam linek..."), this);
	viewPhoneListAction->setIcon(QIcon(":/images/spreadsheet.svg"));
	QObject::connect(viewPhoneListAction, SIGNAL(triggered()),
					 mainWidget, SLOT(viewPhoneList()));

	aboutQtAction = new QAction(tr("O toolkitu &Qt"), this);
	aboutQtAction->setIcon(QIcon(":/images/qt.png"));
	aboutQtAction->setShortcut(QKeySequence(tr("Ctrl+Q")));
	QObject::connect(aboutQtAction, SIGNAL(triggered()),
					 qApp, SLOT(aboutQt()));
}
示例#6
0
void DatabaseTabWidget::modified()
{
    Q_ASSERT(qobject_cast<Database*>(sender()));

    Database* db = static_cast<Database*>(sender());
    DatabaseManagerStruct& dbStruct = m_dbList[db];

    if (config()->get("AutoSaveAfterEveryChange").toBool() && dbStruct.saveToFilename) {
        saveDatabase(db);
        return;
    }

    if (!dbStruct.modified) {
        dbStruct.modified = true;
        updateTabName(db);
    }
}
DatabaseEditorActions::DatabaseEditorActions(DatabaseEditorController *controller) :
    QObject(controller),
    m_controller(controller)
{
    connect(controller, SIGNAL(currentDatabaseChanged(::LBDatabase::Database*)), this, SLOT(updateActions()));
    connect(controller, SIGNAL(currentTableChanged(::LBDatabase::Table*)), this, SLOT(updateActions()));
    connect(controller, SIGNAL(currentContextChanged(::LBDatabase::Context*)), this, SLOT(updateActions()));

    m_openDatabaseAction = new Action(this);
    m_openDatabaseAction->setText(tr("&Open..."));
    m_openDatabaseAction->setShortcut(QKeySequence::Open);
    connect(m_openDatabaseAction, SIGNAL(triggered()), m_controller, SLOT(openFile()));

    m_importDatabaseAction = new Action(this);
    m_importDatabaseAction->setText(tr("&Import database..."));
    connect(m_importDatabaseAction, SIGNAL(triggered()), m_controller, SLOT(importDatabase()));

    m_closeDatabaseAction = new Action(this);
    m_closeDatabaseAction->setText(tr("C&lose database"));
    m_closeDatabaseAction->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_W);
    m_closeDatabaseAction->setEnabled(false);
    connect(m_closeDatabaseAction, SIGNAL(triggered()), m_controller, SLOT(closeDatabase()));

    m_saveDatabaseAction = new Action(this);
    m_saveDatabaseAction->setText(tr("&Save"));
    m_saveDatabaseAction->setShortcut(QKeySequence::Save);
    m_saveDatabaseAction->setEnabled(false);
    connect(m_saveDatabaseAction, SIGNAL(triggered()), m_controller, SLOT(saveDatabase()));

    m_insertRowAction = new Action(this);
    m_insertRowAction->setText(tr("&Insert Row..."));
    m_insertRowAction->setEnabled(false);
    connect(m_insertRowAction, SIGNAL(triggered()), m_controller, SLOT(appendRow()));

    m_deleteRowAction = new Action(this);
    m_deleteRowAction->setText(tr("&Delete Row..."));
    m_deleteRowAction->setEnabled(false);
    connect(m_deleteRowAction, SIGNAL(triggered()), m_controller, SLOT(deleteRow()));

    m_createTableAction = new Action(this);
    m_createTableAction->setText(tr("&Create Table..."));
    m_createTableAction->setEnabled(false);
    connect(m_createTableAction, SIGNAL(triggered()), m_controller, SLOT(createTable()));

    m_editTableAction = new Action(this);
    m_editTableAction->setText(tr("&Edit Table..."));
    m_editTableAction->setEnabled(false);
    connect(m_editTableAction, SIGNAL(triggered()), m_controller, SLOT(editTable()));

    m_createContextAction = new Action(this);
    m_createContextAction->setText(tr("&Create Context..."));
    m_createContextAction->setEnabled(false);
    connect(m_createContextAction, SIGNAL(triggered()), m_controller, SLOT(createContext()));

    m_addEntityTypeAction = new Action(this);
    m_addEntityTypeAction->setText(tr("&Add EntityType..."));
    m_addEntityTypeAction->setEnabled(false);
    connect(m_addEntityTypeAction, SIGNAL(triggered()), m_controller, SLOT(addEntityType()));

    m_editEntityTypesAction = new Action(this);
    m_editEntityTypesAction->setText(tr("&Edit EntityTypes..."));
    m_editEntityTypesAction->setEnabled(false);
    connect(m_editEntityTypesAction, SIGNAL(triggered()), m_controller, SLOT(editEntityTypes()));

    m_exportUmlGraphvizAction = new Action(this);
    m_exportUmlGraphvizAction->setText(tr("&UML Graphviz *.dot document..."));
    m_exportUmlGraphvizAction->setEnabled(true);
    connect(m_exportUmlGraphvizAction, SIGNAL(triggered()), m_controller, SLOT(exportGraphviz()));

    m_exportCppAction = new Action(this);
    m_exportCppAction->setText(tr("&C++ Entity Storage..."));
    m_exportCppAction->setEnabled(true);
    connect(m_exportCppAction, SIGNAL(triggered()), m_controller, SLOT(exportCpp()));
}
示例#8
0
void DatabaseTabWidget::lockDatabases()
{
    clipboard()->clearCopiedText();

    for (int i = 0; i < count(); i++) {
        DatabaseWidget* dbWidget = static_cast<DatabaseWidget*>(widget(i));
        Database* db = databaseFromDatabaseWidget(dbWidget);

        DatabaseWidget::Mode mode = dbWidget->currentMode();

        if ((mode != DatabaseWidget::ViewMode && mode != DatabaseWidget::EditMode)
                || !dbWidget->dbHasKey()) {
            continue;
        }

        // show the correct tab widget before we are asking questions about it
        setCurrentWidget(dbWidget);

        if (mode == DatabaseWidget::EditMode && dbWidget->isEditWidgetModified()) {
            QMessageBox::StandardButton result =
                MessageBox::question(
                    this, tr("Lock database"),
                    tr("Can't lock the database as you are currently editing it.\nPlease press cancel to finish your changes or discard them."),
                    QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
            if (result == QMessageBox::Cancel) {
                continue;
            }
        }


        if (m_dbList[db].modified && !m_dbList[db].saveToFilename) {
            QMessageBox::StandardButton result =
                MessageBox::question(
                    this, tr("Lock database"),
                    tr("This database has never been saved.\nYou can save the database or stop locking it."),
                    QMessageBox::Save | QMessageBox::Cancel, QMessageBox::Cancel);
            if (result == QMessageBox::Save) {
                if (!saveDatabase(db)) {
                    continue;
                }
            }
            else if (result == QMessageBox::Cancel) {
                continue;
            }
        }
        else if (m_dbList[db].modified) {
            QMessageBox::StandardButton result =
                MessageBox::question(
                    this, tr("Lock database"),
                    tr("This database has been modified.\nDo you want to save the database before locking it?\nOtherwise your changes are lost."),
                    QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
            if (result == QMessageBox::Save) {
                if (!saveDatabase(db)) {
                    continue;
                }
            }
            else if (result == QMessageBox::Discard) {
                m_dbList[db].modified = false;
            }
            else if (result == QMessageBox::Cancel) {
                continue;
            }
        }

        dbWidget->lock();
        // database has changed so we can't use the db variable anymore
        updateTabName(dbWidget->database());
    }
}
示例#9
0
MainWindow::MainWindow(ActualDataStore* inDS)
{
  ds = inDS;
  userNames = ds->getUsersNames();




  // Title
  setWindowTitle("Amazon");




  // Overall layout
  overallLayout = new QVBoxLayout();




  // // Search group for searching functionality
  sGroup = new SearchGroup(ds);
  overallLayout->addWidget(sGroup);




  // // Section for interacting with users
  // Layout
  userGroupLayout = new QHBoxLayout();
  overallLayout->addLayout(userGroupLayout);
  // Button for selecting current user
  userButtonIdentifier = new QLabel("Current User:"******"Add to Cart");
  userGroupLayout->addWidget(addCartButton);
  // Viewcart button
  viewCartButton = new QPushButton("View Cart");
  connect(viewCartButton, SIGNAL(clicked()), this, SLOT(openViewCartWindow()));
  userGroupLayout->addWidget(viewCartButton);




  // // Section for dealing with database
  // Layout
  dbGroupLayout = new QHBoxLayout();
  overallLayout->addLayout(dbGroupLayout);
  // Save functionality
  newDBField = new QLineEdit();
  newDBField->setPlaceholderText("Enter new database filename");
  saveButton = new QPushButton("Save");
  connect(saveButton, SIGNAL(clicked()), this, SLOT(saveDatabase()));
  dbGroupLayout->addWidget(newDBField);
  dbGroupLayout->addWidget(saveButton);
  // Quit
  quitButton = new QPushButton("Quit");
  connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
  dbGroupLayout->addWidget(quitButton);

  // Allow enter/return key to act as go button
  connect(newDBField, SIGNAL(returnPressed()), this, SLOT(saveDatabase()));




  // Mapper to reroute addCartButton to sGroup
  signalMapper = new QSignalMapper(this);
  connect(addCartButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
  signalMapper->setMapping(addCartButton, userSelButton->currentText());
  connect(signalMapper, SIGNAL(mapped(QString)), sGroup, SLOT(addItemToCart(QString)));




  // Set overall layout
  setLayout(overallLayout);
}