Allow non-host-platform libraries in Add Library wizard

Since much of the available UI and behavior depends on which platform's
library we start with, let the user choose a platform filter.
Default is the host OS.

Task-number: QTCREATORBUG-17995
Change-Id: Ic8bec7ac30eecf08c1684da4f2823a8add8f6d20
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Eike Ziller
2018-09-24 12:26:46 +02:00
parent 1785b0f561
commit f5647cc2c4
4 changed files with 94 additions and 56 deletions

View File

@@ -655,6 +655,7 @@ QString PathChooser::promptDialogTitle() const
void PathChooser::setPromptDialogFilter(const QString &filter)
{
d->m_dialogFilter = filter;
d->m_lineEdit->validate();
}
QString PathChooser::promptDialogFilter() const

View File

@@ -43,6 +43,16 @@ using namespace ProjectExplorer;
using namespace QmakeProjectManager;
using namespace QmakeProjectManager::Internal;
static void fillLibraryPlatformTypes(QComboBox *comboBox)
{
comboBox->clear();
comboBox->addItem("Windows (*.lib lib*.a)", int(Utils::OsTypeWindows));
comboBox->addItem("Linux (lib*.so lib*.a)", int(Utils::OsTypeLinux));
comboBox->addItem("macOS (*.dylib *.a *.framework)", int(Utils::OsTypeMac));
const int currentIndex = comboBox->findData(int(Utils::HostOsInfo::hostOs()));
comboBox->setCurrentIndex(std::max(0, currentIndex));
}
LibraryDetailsController::LibraryDetailsController(
Ui::LibraryDetailsWidget *libraryDetails,
const QString &proFile, QObject *parent) :
@@ -73,6 +83,8 @@ LibraryDetailsController::LibraryDetailsController(
this, &LibraryDetailsController::slotPlatformChanged);
connect(m_libraryDetailsWidget->winCheckBox, &QAbstractButton::clicked,
this, &LibraryDetailsController::slotPlatformChanged);
fillLibraryPlatformTypes(m_libraryDetailsWidget->libraryTypeComboBox);
}
Ui::LibraryDetailsWidget *LibraryDetailsController::libraryDetailsWidget() const
@@ -95,6 +107,16 @@ AddLibraryWizard::MacLibraryType LibraryDetailsController::macLibraryType() cons
return m_macLibraryType;
}
Utils::OsType LibraryDetailsController::libraryPlatformType() const
{
return Utils::OsType(m_libraryDetailsWidget->libraryTypeComboBox->currentData().value<int>());
}
QString LibraryDetailsController::libraryPlatformFilter() const
{
return m_libraryDetailsWidget->libraryTypeComboBox->currentText();
}
void LibraryDetailsController::updateGui()
{
// read values from gui
@@ -249,6 +271,8 @@ void LibraryDetailsController::setMacLibraryGroupVisible(bool ena)
void LibraryDetailsController::setLibraryPathChooserVisible(bool ena)
{
libraryDetailsWidget()->libraryTypeComboBox->setVisible(ena);
libraryDetailsWidget()->libraryTypeLabel->setVisible(ena);
libraryDetailsWidget()->libraryPathChooser->setVisible(ena);
libraryDetailsWidget()->libraryFileLabel->setVisible(ena);
}
@@ -578,29 +602,6 @@ NonInternalLibraryDetailsController::NonInternalLibraryDetailsController(
setLibraryComboBoxVisible(false);
setLibraryPathChooserVisible(true);
if (Utils::HostOsInfo::isWindowsHost()) {
libraryDetailsWidget()->libraryPathChooser->setPromptDialogFilter(
QLatin1String("Library file (*.lib lib*.a)"));
setLinkageRadiosVisible(true);
setRemoveSuffixVisible(true);
} else {
setLinkageRadiosVisible(false);
setRemoveSuffixVisible(false);
}
if (Utils::HostOsInfo::isLinuxHost())
libraryDetailsWidget()->libraryPathChooser->setPromptDialogFilter(
QLatin1String("Library file (lib*.so lib*.a)"));
if (Utils::HostOsInfo::isMacHost()) {
libraryDetailsWidget()->libraryPathChooser->setPromptDialogFilter(
QLatin1String("Library file (*.dylib *.a *.framework)"));
// QLatin1String("Library file (lib*.dylib lib*.a *.framework)"));
libraryDetailsWidget()->libraryPathChooser->setExpectedKind(Utils::PathChooser::Any);
} else {
libraryDetailsWidget()->libraryPathChooser->setExpectedKind(Utils::PathChooser::File);
}
connect(libraryDetailsWidget()->libraryPathChooser, &Utils::PathChooser::validChanged,
this, &LibraryDetailsController::completeChanged);
connect(libraryDetailsWidget()->libraryPathChooser, &Utils::PathChooser::rawPathChanged,
@@ -611,12 +612,15 @@ NonInternalLibraryDetailsController::NonInternalLibraryDetailsController(
this, &NonInternalLibraryDetailsController::slotLinkageTypeChanged);
connect(libraryDetailsWidget()->staticRadio, &QAbstractButton::clicked,
this, &NonInternalLibraryDetailsController::slotLinkageTypeChanged);
connect(libraryDetailsWidget()->libraryTypeComboBox, &QComboBox::currentTextChanged,
this, &NonInternalLibraryDetailsController::slotLibraryTypeChanged);
slotLibraryTypeChanged();
}
AddLibraryWizard::LinkageType NonInternalLibraryDetailsController::suggestedLinkageType() const
{
AddLibraryWizard::LinkageType type = AddLibraryWizard::NoLinkage;
if (!Utils::HostOsInfo::isWindowsHost()) {
if (libraryPlatformType() != Utils::OsTypeWindows) {
if (libraryDetailsWidget()->libraryPathChooser->isValid()) {
QFileInfo fi(libraryDetailsWidget()->libraryPathChooser->path());
if (fi.suffix() == QLatin1String("a"))
@@ -631,7 +635,7 @@ AddLibraryWizard::LinkageType NonInternalLibraryDetailsController::suggestedLink
AddLibraryWizard::MacLibraryType NonInternalLibraryDetailsController::suggestedMacLibraryType() const
{
AddLibraryWizard::MacLibraryType type = AddLibraryWizard::NoLibraryType;
if (Utils::HostOsInfo::isMacHost()) {
if (libraryPlatformType() == Utils::OsTypeMac) {
if (libraryDetailsWidget()->libraryPathChooser->isValid()) {
QFileInfo fi(libraryDetailsWidget()->libraryPathChooser->path());
if (fi.suffix() == QLatin1String("framework"))
@@ -665,7 +669,7 @@ QString NonInternalLibraryDetailsController::suggestedIncludePath() const
void NonInternalLibraryDetailsController::updateWindowsOptionsEnablement()
{
bool ena = platforms() & (AddLibraryWizard::WindowsMinGWPlatform | AddLibraryWizard::WindowsMSVCPlatform);
if (Utils::HostOsInfo::isWindowsHost()) {
if (libraryPlatformType() == Utils::OsTypeWindows) {
libraryDetailsWidget()->addSuffixCheckBox->setEnabled(ena);
ena = true;
}
@@ -695,9 +699,26 @@ void NonInternalLibraryDetailsController::slotRemoveSuffixChanged(bool ena)
}
}
void NonInternalLibraryDetailsController::slotLibraryTypeChanged()
{
libraryDetailsWidget()->libraryPathChooser->setPromptDialogFilter(libraryPlatformFilter());
const bool isMacOs = libraryPlatformType() == Utils::OsTypeMac;
const bool isWindows = libraryPlatformType() == Utils::OsTypeWindows;
libraryDetailsWidget()->libraryPathChooser->setExpectedKind(isMacOs ? Utils::PathChooser::Any
: Utils::PathChooser::File);
setMacLibraryRadiosVisible(!isMacOs);
setLinkageRadiosVisible(isWindows);
setRemoveSuffixVisible(isWindows);
updateWindowsOptionsEnablement();
slotLibraryPathChanged();
slotLinkageTypeChanged();
libraryDetailsWidget()->detailsLayout->parentWidget()->window()->adjustSize();
}
void NonInternalLibraryDetailsController::slotLibraryPathChanged()
{
if (Utils::HostOsInfo::isWindowsHost()) {
if (libraryPlatformType() == Utils::OsTypeWindows) {
bool subfoldersEnabled = true;
bool removeSuffixEnabled = true;
if (libraryDetailsWidget()->libraryPathChooser->isValid()) {
@@ -739,13 +760,13 @@ QString NonInternalLibraryDetailsController::snippet() const
QString libName;
const bool removeSuffix = isWindowsGroupVisible()
&& libraryDetailsWidget()->removeSuffixCheckBox->isChecked();
if (Utils::HostOsInfo::isWindowsHost()) {
if (libraryPlatformType() == Utils::OsTypeWindows) {
libName = fi.completeBaseName();
if (removeSuffix && !libName.isEmpty()) // remove last letter which needs to be "d"
libName = libName.left(libName.size() - 1);
if (fi.completeSuffix() == QLatin1String("a")) // the mingw lib case
libName = libName.mid(3); // cut the "lib" prefix
} else if (Utils::HostOsInfo::isMacHost()) {
} else if (libraryPlatformType() == Utils::OsTypeMac) {
if (macLibraryType() == AddLibraryWizard::FrameworkType)
libName = fi.completeBaseName();
else
@@ -759,7 +780,7 @@ QString NonInternalLibraryDetailsController::snippet() const
if (isWindowsGroupVisible()) {
// when we are on Win but we don't generate the code for Win
// we still need to remove "debug" or "release" subfolder
const bool useSubfoldersCondition = (Utils::HostOsInfo::isWindowsHost())
const bool useSubfoldersCondition = (libraryPlatformType() == Utils::OsTypeWindows)
? true : platforms() & (AddLibraryWizard::WindowsMinGWPlatform
| AddLibraryWizard::WindowsMSVCPlatform);
if (useSubfoldersCondition)
@@ -774,7 +795,7 @@ QString NonInternalLibraryDetailsController::snippet() const
QFileInfo pfi(proFile());
QDir pdir = pfi.absoluteDir();
QString absoluteLibraryPath = fi.absolutePath();
if (Utils::HostOsInfo::isWindowsHost() && useSubfolders) { // drop last subfolder which needs to be "debug" or "release"
if (libraryPlatformType() == Utils::OsTypeWindows && useSubfolders) { // drop last subfolder which needs to be "debug" or "release"
QFileInfo libfi(absoluteLibraryPath);
absoluteLibraryPath = libfi.absolutePath();
}
@@ -889,12 +910,10 @@ void ExternalLibraryDetailsController::updateWindowsOptionsEnablement()
{
NonInternalLibraryDetailsController::updateWindowsOptionsEnablement();
if (!Utils::HostOsInfo::isWindowsHost())
return;
bool subfoldersEnabled = true;
bool removeSuffixEnabled = true;
if (libraryDetailsWidget()->libraryPathChooser->isValid()) {
if (libraryPlatformType() == Utils::OsTypeWindows
&& libraryDetailsWidget()->libraryPathChooser->isValid()) {
QFileInfo fi(libraryDetailsWidget()->libraryPathChooser->path());
QFileInfo dfi(fi.absolutePath());
const QString parentFolderName = dfi.fileName().toLower();
@@ -905,7 +924,6 @@ void ExternalLibraryDetailsController::updateWindowsOptionsEnablement()
if (baseName.isEmpty() || baseName.at(baseName.size() - 1).toLower() != QLatin1Char('d'))
removeSuffixEnabled = false;
}
libraryDetailsWidget()->useSubfoldersCheckBox->setEnabled(subfoldersEnabled);
libraryDetailsWidget()->removeSuffixCheckBox->setEnabled(removeSuffixEnabled);

View File

@@ -52,6 +52,8 @@ protected:
AddLibraryWizard::Platforms platforms() const;
AddLibraryWizard::LinkageType linkageType() const;
AddLibraryWizard::MacLibraryType macLibraryType() const;
Utils::OsType libraryPlatformType() const;
QString libraryPlatformFilter() const;
QString proFile() const;
bool isIncludePathChanged() const;
bool guiSignalsIgnored() const;
@@ -127,6 +129,7 @@ protected:
private:
void slotLinkageTypeChanged();
void slotRemoveSuffixChanged(bool ena);
void slotLibraryTypeChanged();
void slotLibraryPathChanged();
};

View File

@@ -6,13 +6,23 @@
<rect>
<x>0</x>
<y>0</y>
<width>455</width>
<height>370</height>
<width>456</width>
<height>438</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item row="0" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="QLabel" name="libraryFileLabel">
<property name="text">
<string>Library file:</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="libraryLabel">
<property name="text">
@@ -20,30 +30,20 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="libraryComboBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="libraryFileLabel">
<property name="text">
<string>Library file:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Utils::PathChooser" name="libraryPathChooser" native="true"/>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="includeLabel">
<property name="text">
<string>Include path:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="Utils::PathChooser" name="includePathChooser" native="true"/>
</item>
<item row="2" column="0">
<item row="3" column="1">
<widget class="QLineEdit" name="packageLineEdit"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="packageLabel">
<property name="text">
<string>Package:</string>
@@ -51,7 +51,20 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="packageLineEdit"/>
<widget class="Utils::PathChooser" name="libraryPathChooser" native="true"/>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="libraryComboBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="libraryTypeLabel">
<property name="text">
<string>Library type:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="libraryTypeComboBox"/>
</item>
</layout>
</item>
@@ -115,7 +128,10 @@
</layout>
</item>
<item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout_4">
<layout class="QVBoxLayout" name="detailsLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item>
<widget class="QGroupBox" name="linkageGroupBox">
<property name="title">