Code: Alles auswählen
main(){
pwWidget pww; //Übergibt "irgendwie" ein Flag ob das pw richtig war an main
myMainWidget mainw; // Main startet nur wenn Flag true ist, ansonsten quit
return ...;
}
Code: Alles auswählen
main(){
pwWidget pww; //Übergibt "irgendwie" ein Flag ob das pw richtig war an main
myMainWidget mainw; // Main startet nur wenn Flag true ist, ansonsten quit
return ...;
}
Code: Alles auswählen
Dialog::Dialog(){
setupUi(this);
connect( lineEdit, SIGNAL(returnPressed()),
this, SLOT(checkPW()) );
connect( buttonBox, SIGNAL(accepted()),
this, SLOT(checkPW()) );
connect( buttonBox, SIGNAL(rejected()),
this, SLOT(reject()) );
}
void Dialog::checkPW(){
QString pw="ccw";
if(lineEdit->text()==pw){
SLOT(accepted());
}
else{
SLOT(rejected());
}
}Code: Alles auswählen
#ifndef MAINFORM_H
#define MAINFORM_H
#include <QtGui>
#include <QString>
#include <QFile>
#include "data.h"
#include "dialog.h"
#include "ui_mainwindow.h"
#define LENGTH 100000
class MForm : public QMainWindow, private Ui::MainWindow {
Q_OBJECT
public:
int val;
Data* myd[LENGTH];
Dialog* myDialog;
MForm();
~MForm(){}
protected slots:
void search();
void save();
void pw();
private:
void getDatabase(Data* myd[]);
};
#endif // MAINFORM_H
Code: Alles auswählen
#include "mainForm.h"
#include "dialog.h"
#include "db.h"
MForm::MForm(){
myDialog = new Dialog;
myDialog->exec();
if(myDialog->getFlag()){
//Gui Initialisieren
setupUi(this);
//Daten
for(int n=0; n<LENGTH; n++){
myd[n] = NULL;
}
getDatabase(myd);
//connects
connect( pushButton , SIGNAL(clicked()),
this , SLOT(search()) );
connect( lineEdit, SIGNAL(returnPressed()),
this , SLOT(search()) );
connect( pushButton_2 , SIGNAL(clicked()),
this , SLOT(save()) );
}
else {
this->close();
}
}
void MForm::search(){
QString str = lineEdit->text();
QString buf,temp;
str=str.toLower();
textEdit->clear();
for(int i=0 ; i<LENGTH-1 ; i++){
if(myd[i]!=NULL){
if((myd[i]->owner.toLower()).indexOf(str)!= -1){
buf.clear();
buf=buf.setNum(myd[i]->gala)+":";
buf+=QString::number(myd[i]->system)+":";
buf+=QString::number(myd[i]->plani)+" / ";
buf+="von "+myd[i]->owner+"(Punkte: "+ QString::number(myd[i]->points) +" / AZ: "+QString::number(myd[i]->az)+")";
buf+=" Planetenname: "+myd[i]->name;
buf+=" / Allianz: "+myd[i]->alli+"\n";
temp=textEdit->toPlainText();
temp.append(buf);
textEdit->setPlainText(temp);
}
}
}
}
void MForm::save(){
QString fileName = QFileDialog::getSaveFileName(this, "Bitte eine Datei auswählen",
QDir::homePath(), "Dokumente (*.txt)");
QFile file(fileName);
if (file.open(QIODevice::WriteOnly | QIODevice::Text)){
file.write(textEdit->toPlainText().toUtf8());
statusBar()->showMessage(tr("Daten wurden gespeichert!"),5000);
}
file.close();
}
void MForm::getDatabase(Data *myd[]){
QString fileName = "DB.csv";
QFile file(fileName);
int n=0;
if(file.open(QIODevice::ReadOnly | QIODevice::Text)){
QString buf = QString::fromUtf8(file.readLine());
while(!file.atEnd()&&n<LENGTH) {
//Objekt erzeugen und Datensatz lesen
myd[n]=new Data();
buf = QString::fromUtf8(file.readLine());
// Objekt zusammenbauen
myd[n]->gala=( (buf.mid(0,( buf.indexOf(";")) ) ).toInt() );
buf=buf.mid(buf.indexOf(";")+1);
myd[n]->system=( (buf.mid(0,( buf.indexOf(";")) ) ).toInt() );
buf=buf.mid(buf.indexOf(";")+1);
myd[n]->plani=( (buf.mid(0,( buf.indexOf(";")) ) ).toInt() );
buf=buf.mid(buf.indexOf(";")+1);
myd[n]->owner=buf.mid(0,( buf.indexOf(";")) ) ;
buf=buf.mid(buf.indexOf(";")+1);
myd[n]->name=buf.mid(0,( buf.indexOf(";")) ) ;
buf=buf.mid(buf.indexOf(";")+1);
myd[n]->points=buf.mid(0,( buf.indexOf(";")) ).toInt() ;
buf=buf.mid(buf.indexOf(";")+1);
myd[n]->alli=buf;
myd[n]->setAZ();
n++;
}
}
if(file.error()) {
QMessageBox::information(0,tr("Error Beim Filelesen!"),tr("blaaaaaaa"));
}
}
void MForm::pw(){
val = myDialog->result();
}
Code: Alles auswählen
#ifndef DIALOG_H
#define DIALOG_H
#include <QtGui>
#include "ui_dialog.h"
class Dialog : public QDialog , private Ui::Dialog {
Q_OBJECT
private:
bool flag;
QString pw;
public:
bool getFlag();
Dialog();
~Dialog(){}
public slots:
void checkPW();
};
#endif // DIALOG_H
Code: Alles auswählen
#include "dialog.h"
#include "mainForm.h"
Dialog::Dialog(){
flag=false;
pw="ccw";
setupUi(this);
connect( lineEdit, SIGNAL(returnPressed()),
this, SLOT(checkPW()) );
connect( buttonBox, SIGNAL(accepted()),
this, SLOT(checkPW()) );
connect( buttonBox, SIGNAL(rejected()),
this, SLOT(reject()) );
}
void Dialog::checkPW(){
if(lineEdit->text()==pw){
flag=true;
}
else{
flag=false;
}
}
bool Dialog::getFlag(){
return flag;
}
Code: Alles auswählen
connect( lineEdit, SIGNAL(returnPressed()),
this, SLOT(checkPW()) );
connect( lineEdit, SIGNAL(returnPressed()),
this, SLOT(accept()));
connect( buttonBox, SIGNAL(accepted()),
this, SLOT(checkPW()) );
connect( buttonBox, SIGNAL(accepted()),
this, SLOT(accept()));
connect( buttonBox, SIGNAL(rejected()),
this, SLOT(reject()) );