diff --git a/language/codegen/tests/test_templatesmodel.cpp b/language/codegen/tests/test_templatesmodel.cpp index 1911e5d4a..04b155ed4 100644 --- a/language/codegen/tests/test_templatesmodel.cpp +++ b/language/codegen/tests/test_templatesmodel.cpp @@ -1,87 +1,89 @@ /* * This file is part of KDevelop * Copyright 2012 Miha Čančula * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "test_templatesmodel.h" #include "codegen_tests_config.h" #include #include #include using namespace KDevelop; void TestTemplatesModel::initTestCase() { + // avoid translated desktop entries, tests use untranslated strings + QLocale::setDefault(QLocale::c()); AutoTestShell::init(); TestCore::initialize(Core::NoUi); model = new TemplatesModel(QStringLiteral("kdevcodegentest"), this); model->addDataPath(QStringLiteral(CODEGEN_TESTS_DATA_DIR) + "/"); model->refresh(); } void TestTemplatesModel::cleanupTestCase() { delete model; TestCore::shutdown(); } void TestTemplatesModel::descriptionExtraction() { QCOMPARE(model->rowCount(), 1); QModelIndex testingCategoryIndex = model->index(0, 0); QCOMPARE(model->rowCount(testingCategoryIndex), 2); for (int i = 0; i < 2; ++i) { QModelIndex languageCategoryIndex = model->index(i, 0, testingCategoryIndex); QCOMPARE(model->rowCount(languageCategoryIndex), 1); QModelIndex templateIndex = model->index(0, 0, languageCategoryIndex); QCOMPARE(model->rowCount(templateIndex), 0); } } void TestTemplatesModel::descriptionParsing() { QList items = model->findItems(QStringLiteral("Testing YAML template"), Qt::MatchRecursive); QCOMPARE(items.size(), 1); QStandardItem* item = items.first(); QCOMPARE(item->data(TemplatesModel::CommentRole).toString(), QStringLiteral("Describes a class using YAML syntax")); QVERIFY(item->data(TemplatesModel::IconNameRole).toString().isEmpty()); QString descriptionFile = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/kdevcodegentest/template_descriptions/test_yaml.desktop"; QVERIFY(QFile::exists(descriptionFile)); QCOMPARE(item->data(TemplatesModel::DescriptionFileRole).toString(), descriptionFile); } void TestTemplatesModel::templateIndexes() { QModelIndexList indexes = model->templateIndexes(QStringLiteral("test_yaml.tar.bz2")); QCOMPARE(indexes.size(), 3); QCOMPARE(model->data(indexes[0]).toString(), QStringLiteral("Testing")); QCOMPARE(model->data(indexes[1]).toString(), QStringLiteral("YAML")); QCOMPARE(model->data(indexes[2]).toString(), QStringLiteral("Testing YAML template")); } QTEST_GUILESS_MAIN(TestTemplatesModel) diff --git a/plugins/filetemplates/tests/test_generationtest.cpp b/plugins/filetemplates/tests/test_generationtest.cpp index 2c9b8fb52..666ef2f7d 100644 --- a/plugins/filetemplates/tests/test_generationtest.cpp +++ b/plugins/filetemplates/tests/test_generationtest.cpp @@ -1,126 +1,128 @@ /* * This file is part of KDevelop * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "test_generationtest.h" #include "tests_config.h" #include #include #include #include #include #include #include using namespace KDevelop; #define COMPARE_FILES(name) \ do { \ QFile actualFile(Path(Path(baseUrl), QStringLiteral(name)).toLocalFile()); \ QVERIFY(actualFile.open(QIODevice::ReadOnly)); \ QFile expectedFile(QStringLiteral(TESTS_EXPECTED_DIR "/" name)); \ QVERIFY(expectedFile.open(QIODevice::ReadOnly)); \ QCOMPARE(actualFile.size(), expectedFile.size()); \ QCOMPARE(QString(actualFile.readAll()), QString(expectedFile.readAll())); \ } while(0) void TestGenerationTest::initTestCase() { QByteArray xdgData = qgetenv("XDG_DATA_DIRS"); xdgData.prepend(TESTS_DATA_DIR ":"); bool addedDir = qputenv("XDG_DATA_DIRS", xdgData); QVERIFY(addedDir); + // avoid translated desktop entries, tests use untranslated strings + QLocale::setDefault(QLocale::c()); AutoTestShell::init(); TestCore::initialize (Core::NoUi); TemplatesModel model(QStringLiteral("testgenerationtest")); model.refresh(); renderer = new TemplateRenderer; renderer->setEmptyLinesPolicy(TemplateRenderer::TrimEmptyLines); renderer->addVariable(QStringLiteral("name"), "TestName"); renderer->addVariable(QStringLiteral("license"), "Test license header\nIn two lines"); QStringList testCases; testCases << QStringLiteral("firstTestCase"); testCases << QStringLiteral("secondTestCase"); testCases << QStringLiteral("thirdTestCase"); renderer->addVariable(QStringLiteral("testCases"), testCases); } void TestGenerationTest::cleanupTestCase() { delete renderer; TestCore::shutdown(); } void TestGenerationTest::init() { dir.reset(new QTemporaryDir); baseUrl = QUrl::fromLocalFile(dir->path()); } void TestGenerationTest::yamlTemplate() { QString description = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("testgenerationtest/template_descriptions/test_yaml2.desktop")); QVERIFY(!description.isEmpty()); SourceFileTemplate file; file.addAdditionalSearchLocation(QStringLiteral(TESTS_DATA_DIR "/testgenerationtest/templates")); file.setTemplateDescription(description); QCOMPARE(file.name(), QStringLiteral("Testing YAML Template")); DocumentChangeSet changes = renderer->renderFileTemplate(file, baseUrl, urls(file)); changes.applyAllChanges(); COMPARE_FILES("testname.yaml"); } void TestGenerationTest::cppTemplate() { QString description = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("testgenerationtest/template_descriptions/test_qtestlib.desktop")); QVERIFY(!description.isEmpty()); SourceFileTemplate file; file.addAdditionalSearchLocation(QStringLiteral(TESTS_DATA_DIR "/testgenerationtest/templates")); file.setTemplateDescription(description); QCOMPARE(file.name(), QStringLiteral("Testing C++ Template")); DocumentChangeSet changes = renderer->renderFileTemplate(file, baseUrl, urls(file)); changes.applyAllChanges(); COMPARE_FILES("testname.h"); COMPARE_FILES("testname.cpp"); } QHash< QString, QUrl > TestGenerationTest::urls (const SourceFileTemplate& file) { QHash ret; foreach (const SourceFileTemplate::OutputFile& output, file.outputFiles()) { QUrl url = Path(Path(baseUrl), renderer->render(output.outputName).toLower()).toUrl(); ret.insert(output.identifier, url); } return ret; } QTEST_GUILESS_MAIN(TestGenerationTest); diff --git a/shell/progresswidget/overlaywidget.cpp b/shell/progresswidget/overlaywidget.cpp index 22dd5e9f7..c7da99181 100644 --- a/shell/progresswidget/overlaywidget.cpp +++ b/shell/progresswidget/overlaywidget.cpp @@ -1,99 +1,99 @@ /** -*- c++ -*- * overlaywidget.h * * Copyright (c) 2004 David Faure * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * In addition, as a special exception, the copyright holders give * permission to link the code of this program with any edition of * the Qt library by Trolltech AS, Norway (or with modified versions * of Qt that use the same license as Qt), and distribute linked * combinations including the two. You must obey the GNU General * Public License in all respects for all of the code used other than * Qt. If you modify this file, you may extend this exception to * your version of the file, but you are not obligated to do so. If * you do not wish to do so, delete this exception statement from * your version. */ #include "overlaywidget.h" #include #include #include #include using namespace KDevelop; OverlayWidget::OverlayWidget( QWidget* alignWidget, QWidget* parent, const char* name ) - : QWidget( parent, Qt::Window | Qt::FramelessWindowHint ), mAlignWidget( nullptr ) + : QWidget( parent, Qt::Window | Qt::FramelessWindowHint | Qt::ToolTip ), mAlignWidget( nullptr ) { auto hboxHBoxLayout = new QHBoxLayout(this); hboxHBoxLayout->setMargin(0); setObjectName(name); setAlignWidget( alignWidget ); setWindowFlags(Qt::WindowDoesNotAcceptFocus | windowFlags()); qApp->installEventFilter(this); } OverlayWidget::~OverlayWidget() { } void OverlayWidget::reposition() { if ( !mAlignWidget ) return; // p is in the alignWidget's coordinates QPoint p; // We are always above the alignWidget, right-aligned with it. p.setX( mAlignWidget->width() - width() ); p.setY( -height() ); // Position in the global coordinates QPoint global = mAlignWidget->mapToGlobal( p ); // Move 'this' to that position. move( global ); } void OverlayWidget::setAlignWidget( QWidget * w ) { if (w == mAlignWidget) return; mAlignWidget = w; reposition(); } bool OverlayWidget::eventFilter( QObject* o, QEvent* e) { if (e->type() == QEvent::Move || e->type() == QEvent::Resize) { reposition(); } else if (e->type() == QEvent::Close) { close(); } return QWidget::eventFilter(o,e); } void OverlayWidget::resizeEvent( QResizeEvent* ev ) { reposition(); QWidget::resizeEvent( ev ); } diff --git a/shell/settings/environmentwidget.cpp b/shell/settings/environmentwidget.cpp index 078257387..bb46fbe8a 100644 --- a/shell/settings/environmentwidget.cpp +++ b/shell/settings/environmentwidget.cpp @@ -1,242 +1,244 @@ /* This file is part of KDevelop Copyright 2006 Adam Treat Copyright 2007 Dukju Ahn Copyright 2008 Andreas Pakuat This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "environmentwidget.h" #include #include #include #include #include #include #include #include #include "environmentgroupmodel.h" #include "placeholderitemproxymodel.h" #include "../debug.h" namespace KDevelop { EnvironmentWidget::EnvironmentWidget( QWidget *parent ) : QWidget( parent ), groupModel( new EnvironmentGroupModel() ), proxyModel( new QSortFilterProxyModel() ) { // setup ui ui.setupUi( this ); ui.variableTable->verticalHeader()->hide(); proxyModel->setSourceModel( groupModel ); PlaceholderItemProxyModel* topProxyModel = new PlaceholderItemProxyModel(this); topProxyModel->setSourceModel(proxyModel); topProxyModel->setColumnHint(0, i18n("Enter variable ...")); connect(topProxyModel, &PlaceholderItemProxyModel::dataInserted, this, &EnvironmentWidget::handleVariableInserted); ui.variableTable->setModel( topProxyModel ); ui.variableTable->horizontalHeader()->setSectionResizeMode( 0, QHeaderView::ResizeToContents ); ui.variableTable->horizontalHeader()->setSectionResizeMode( 1, QHeaderView::Stretch ); ui.addgrpBtn->setIcon(QIcon::fromTheme(QStringLiteral("list-add"))); ui.clonegrpBtn->setIcon(QIcon::fromTheme(QStringLiteral("edit-clone"))); ui.removegrpBtn->setIcon(QIcon::fromTheme(QStringLiteral("list-remove"))); ui.deleteButton->setIcon(QIcon::fromTheme(QStringLiteral("list-remove"))); ui.deleteButton->setShortcut(Qt::Key_Delete); ui.batchModeEditButton->setIcon(QIcon::fromTheme(QStringLiteral("format-list-unordered"))); connect( ui.deleteButton, &QPushButton::clicked, this, &EnvironmentWidget::deleteButtonClicked ); connect( ui.batchModeEditButton, &QPushButton::clicked, this, &EnvironmentWidget::batchModeEditButtonClicked ); connect( ui.clonegrpBtn, &QPushButton::clicked, this, &EnvironmentWidget::cloneGroupClicked ); connect( ui.addgrpBtn, &QPushButton::clicked, this, &EnvironmentWidget::addGroupClicked ); connect( ui.addgrpBtn, &QPushButton::clicked, this, &EnvironmentWidget::changed ); connect( ui.removegrpBtn, &QPushButton::clicked, this, &EnvironmentWidget::removeGroupClicked ); connect( ui.removegrpBtn, &QPushButton::clicked, this, &EnvironmentWidget::changed ); connect( ui.setAsDefaultBtn, &QPushButton::clicked, this, &EnvironmentWidget::setAsDefault ); connect( ui.setAsDefaultBtn, &QPushButton::clicked, this, &EnvironmentWidget::changed ); connect( ui.activeCombo, static_cast(&KComboBox::currentIndexChanged), this, &EnvironmentWidget::activeGroupChanged ); connect( ui.activeCombo, &KComboBox::editTextChanged, this, &EnvironmentWidget::enableButtons); connect( groupModel, &EnvironmentGroupModel::dataChanged, this, &EnvironmentWidget::changed ); connect( groupModel, &EnvironmentGroupModel::rowsRemoved, this, &EnvironmentWidget::changed ); connect( groupModel, &EnvironmentGroupModel::rowsInserted, this, &EnvironmentWidget::changed ); connect( groupModel, &EnvironmentGroupModel::rowsRemoved, this, &EnvironmentWidget::enableDeleteButton ); connect( groupModel, &EnvironmentGroupModel::rowsInserted, this, &EnvironmentWidget::enableDeleteButton ); connect( groupModel, &EnvironmentGroupModel::modelReset, this, &EnvironmentWidget::enableDeleteButton ); } void EnvironmentWidget::setActiveGroup( const QString& group ) { ui.activeCombo->setCurrentItem(group); } void EnvironmentWidget::enableDeleteButton() { ui.deleteButton->setEnabled( groupModel->rowCount() > 0 ); } void EnvironmentWidget::setAsDefault() { groupModel->changeDefaultGroup( ui.activeCombo->currentText() ); enableButtons( ui.activeCombo->currentText() ); emit changed(); } void EnvironmentWidget::loadSettings( KConfig* config ) { qCDebug(SHELL) << "Loading groups from config"; groupModel->loadFromConfig( config ); ui.activeCombo->clear(); QStringList groupList = groupModel->groups(); qCDebug(SHELL) << "Grouplist:" << groupList << "default group:" << groupModel->defaultGroup(); ui.activeCombo->addItems( groupList ); int idx = ui.activeCombo->findText( groupModel->defaultGroup() ); ui.activeCombo->setCurrentIndex( idx ); } void EnvironmentWidget::saveSettings( KConfig* config ) { groupModel->saveToConfig( config ); } void EnvironmentWidget::defaults( KConfig* config ) { loadSettings( config ); } void EnvironmentWidget::deleteButtonClicked() { QModelIndexList selected = ui.variableTable->selectionModel()->selectedRows(); if( selected.isEmpty() ) return; QStringList variables; foreach( const QModelIndex &idx, selected ) { const QString variable = idx.data(EnvironmentGroupModel::VariableRole).toString(); variables << variable; } groupModel->removeVariables(variables); } void EnvironmentWidget::handleVariableInserted(int /*column*/, const QVariant& value) { groupModel->addVariable(value.toString(), QString()); } void EnvironmentWidget::batchModeEditButtonClicked() { QDialog dialog(this); dialog.setWindowTitle( i18n( "Batch Edit Mode" ) ); QVBoxLayout *layout = new QVBoxLayout(&dialog); QTextEdit *edit = new QTextEdit; edit->setPlaceholderText(QStringLiteral("VARIABLE1=VALUE1\nVARIABLE2=VALUE2")); QString text; for (int i = 0; i < proxyModel->rowCount(); ++i) { const auto variable = proxyModel->index(i, EnvironmentGroupModel::VariableColumn).data().toString(); const auto value = proxyModel->index(i, EnvironmentGroupModel::ValueColumn).data().toString(); text.append(QStringLiteral("%1=%2\n").arg(variable, value)); } edit->setText(text); layout->addWidget( edit ); auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); auto okButton = buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); dialog.connect(buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept); dialog.connect(buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject); layout->addWidget(buttonBox); dialog.resize(600, 400); if ( dialog.exec() != QDialog::Accepted ) { return; } groupModel->loadEnvironmentFromString(edit->toPlainText()); } void EnvironmentWidget::addGroupClicked() { QString curText = ui.activeCombo->currentText(); if( groupModel->groups().contains( curText ) ) { return; // same group name cannot be added twice. } ui.activeCombo->addItem( curText ); ui.activeCombo->setCurrentItem( curText ); } void EnvironmentWidget::cloneGroupClicked() { QString newGroup = ui.activeCombo->currentText(); if( !groupModel->cloneCurrentGroup( newGroup ) ) { - int id = 1; - newGroup = i18nc("a copy of the existing environment was created", "%1 (Cloned %2)", newGroup, id); - while( !groupModel->cloneCurrentGroup( newGroup.arg( id ) ) ) { - ++id; + const KLocalizedString newGroupTemplate = + ki18nc("a copy of the existing environment was created", "%1 (Cloned %2)").subs(newGroup); + for (int id = 1; ; ++id) { + newGroup = newGroupTemplate.subs(id).toString(); + if (groupModel->cloneCurrentGroup(newGroup)) { + break; + } } - newGroup = newGroup.arg( id ); } ui.activeCombo->addItem( newGroup ); ui.activeCombo->setCurrentItem( newGroup ); } void EnvironmentWidget::removeGroupClicked() { int idx = ui.activeCombo->currentIndex(); if( idx < 0 || ui.activeCombo->count() == 1 ) { return; } QString curText = ui.activeCombo->currentText(); groupModel->removeGroup( curText ); ui.activeCombo->removeItem( idx ); ui.activeCombo->setCurrentItem( groupModel->defaultGroup() ); } void EnvironmentWidget::activeGroupChanged( int /*idx*/ ) { groupModel->setCurrentGroup( ui.activeCombo->currentText() ); enableButtons( ui.activeCombo->currentText() ); } void EnvironmentWidget::enableButtons( const QString& txt ) { ui.addgrpBtn->setEnabled( !groupModel->groups().contains( txt ) ); ui.removegrpBtn->setEnabled( ( groupModel->groups().contains( txt ) && groupModel->defaultGroup() != txt ) ); ui.setAsDefaultBtn->setEnabled( ( groupModel->groups().contains( txt ) && groupModel->defaultGroup() != txt ) ); } } #include "moc_environmentwidget.cpp"