Pārlūkot izejas kodu

better solution for new from template: QSignalMapper

tags/1.3
Sven Oliver Moll pirms 2 gadiem
vecāks
revīzija
f4a7d0cfa5

+ 13
- 11
src/fridgegrid/DragWidget.cpp Parādīt failu

@@ -358,18 +358,13 @@ void DragWidget::save()
}


void DragWidget::load()
void DragWidget::load( const QString &templateFileName )
{
QSettings settings;
QString fileName( templateFileName );
QFileInfo lastFilename( settings.value("Filename").toString() );
QString fileName;
QAction *action = qobject_cast<QAction*>( sender() );
if( action && !action->data().isNull() )
{
fileName = action->data().toString();
settings.remove( "Filename" );
}
else

if( fileName.isEmpty() )
{
fileName = QFileDialog::getOpenFileName( this, QCoreApplication::applicationName(),
lastFilename.absolutePath(), "*.xml" );
@@ -377,6 +372,15 @@ void DragWidget::load()
{
return;
}
}

// an internal filename should not be saved to registry
if( fileName.startsWith( ':' ) )
{
settings.remove( "Filename" );
}
else
{
settings.setValue( "Filename", fileName );
}

@@ -445,8 +449,6 @@ void DragWidget::load()
newLabel->setAttribute(Qt::WA_DeleteOnClose);
}
}

//return true;
}



+ 1
- 1
src/fridgegrid/DragWidget.hpp Parādīt failu

@@ -96,7 +96,7 @@ public slots:
\brief \todo

*/
void load();
void load( const QString &templateFileName = QString() );
/*!
\brief \todo


+ 6
- 1
src/fridgegrid/MainWindow.cpp Parādīt failu

@@ -20,6 +20,7 @@
#include <QDockWidget>
#include <QMenu>
#include <QSettings>
#include <QSignalMapper>
#include <QSplitter>
#include <QTextEdit>
#include <QTimer>
@@ -88,13 +89,17 @@ MainWindow::MainWindow( QWidget *parent, Qt::WindowFlags flags )
}
}

QSignalMapper *signalMapper = new QSignalMapper( this );
connect( signalMapper, SIGNAL(mapped(QString)),
mpDragWidget, SLOT(load(QString)) );
QFileInfoList fil( QDir(":/templates/").entryInfoList() );
foreach( const QFileInfo &fi, fil )
{
action = templateMenu->addAction( fi.baseName().replace('_',' ') );
action->setData( fi.filePath() );
connect( action, SIGNAL(triggered()),
mpDragWidget, SLOT(load()) );
signalMapper, SLOT(map()));
signalMapper->setMapping( action, fi.filePath() );
}

action = new QAction( style.standardIcon( QStyle::SP_DialogOpenButton ), "Open File", this );

Notiek ielāde…
Atcelt
Saglabāt