这是源代码,是黑白的。
void TinyGIS::on_actionAdd_Raster_Layer_triggered()
{
const QStringList& fileNames = QFileDialog::getOpenFileNames(this, tr("Add raster layer"), QString(), QString("GTiff(*.tif;*.tiff)"));
if (fileNames.isEmpty())
{
return;
}
//QSignalBlocker signalBlocker(Project::instance()->layerTree());
for (const QString& fileName : fileNames)
{
QFileInfo fileInfo(fileName);
QgsRasterLayer* layer = new QgsRasterLayer(fileName, fileInfo.baseName());
Project::instance()->addLayer(layer);// 加载栅格图层
}
refreshMapCanvas();
addLog(tr("Open Raster layer successfully."));
}
void TinyGIS::refreshMapCanvas()
{
m_mapCanvas->setLayers(Project::instance()->layerTree()->checkedLayers());
m_mapCanvas->refresh();
}
void TinyGIS::refreshMapCanvas()
{
m_mapCanvas->setLayers(Project::instance()->layerTree()->checkedLayers());
m_mapCanvas->refresh();
}
这个是黑白效果