summaryrefslogtreecommitdiffstats
path: root/src/gui/microselectwidget.cpp
blob: 1c4150bbb0e19dcce7b3eb30879d820eadf50617 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/***************************************************************************
 *   Copyright (C) 2005 by David Saxton                                    *
 *   [email protected]                                                    *
 *                                                                         *
 *   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; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#include "asminfo.h"
#include "microinfo.h"
#include "microlibrary.h"
#include "microselectwidget.h"

#include <kcombobox.h>
#include <klocale.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qvariant.h>
#include <qwhatsthis.h>

MicroSelectWidget::MicroSelectWidget( QWidget* parent, const char* name, WFlags )
	: QGroupBox( 4, Qt::Horizontal, i18n("Microprocessor"), parent, name )
{
	m_allowedAsmSet = AsmInfo::AsmSetAll;
	m_allowedGpsimSupport = m_allowedFlowCodeSupport = m_allowedMicrobeSupport = MicroInfo::AllSupport;
	
	if ( !name )
		setName( "MicroSelectWidget" );

	m_pMicroFamilyLabel = new QLabel( this, "m_pMicroFamilyLabel" );
	m_pMicroFamilyLabel->setText( i18n("Family") );

	m_pMicroFamily = new KComboBox( FALSE, this, "m_pMicroFamily" );
	m_pMicroFamily->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );

	m_pMicroLabel = new QLabel( this, "m_pMicroLabel" );
	m_pMicroLabel->setText( i18n("Micro") );

	m_pMicro = new KComboBox( FALSE, this, "m_pMicro" );
	m_pMicro->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
	m_pMicro->setEditable( TRUE );
	m_pMicro->setAutoCompletion(true);
	updateFromAllowed();
	setMicro("P16F84");
	connect( m_pMicroFamily, SIGNAL(activated(const QString & )), this, SLOT(microFamilyChanged(const QString& )) );
}


MicroSelectWidget::~MicroSelectWidget()
{
}

void MicroSelectWidget::setAllowedAsmSet( unsigned allowed )
{
	m_allowedAsmSet = allowed;
	updateFromAllowed();
}
void MicroSelectWidget::setAllowedGpsimSupport( unsigned allowed )
{
	m_allowedGpsimSupport = allowed;
	updateFromAllowed();
}
void MicroSelectWidget::setAllowedFlowCodeSupport( unsigned allowed )
{
	m_allowedFlowCodeSupport = allowed;
	updateFromAllowed();
}	
void MicroSelectWidget::setAllowedMicrobeSupport( unsigned allowed )
{
	m_allowedMicrobeSupport = allowed;
	updateFromAllowed();
}


void MicroSelectWidget::updateFromAllowed()
{
	QString oldFamily = m_pMicroFamily->currentText();
	
	m_pMicroFamily->clear();
	
#define CHECK_ADD(family) if ( (m_allowedAsmSet & AsmInfo::family) && !MicroLibrary::self()->microIDs( AsmInfo::family, m_allowedGpsimSupport, m_allowedFlowCodeSupport, m_allowedMicrobeSupport ).isEmpty() ) m_pMicroFamily->insertItem( AsmInfo::setToString(AsmInfo::family) );
	CHECK_ADD(PIC12)
	CHECK_ADD(PIC14)
	CHECK_ADD(PIC16);
#undef CHECK_ADD

	if ( m_pMicroFamily->contains(oldFamily) )
		m_pMicroFamily->setCurrentText(oldFamily);
	
	microFamilyChanged(oldFamily);
}


void MicroSelectWidget::setMicro( const QString & id )
{
	MicroInfo * info = MicroLibrary::self()->microInfoWithID(id);
	if (!info)
		return;
	
	m_pMicro->clear();
	m_pMicro->insertStringList( MicroLibrary::self()->microIDs( info->instructionSet()->set() ) );
	m_pMicro->setCurrentText(id);
	
	m_pMicroFamily->setCurrentText( AsmInfo::setToString( info->instructionSet()->set() ) );
}


QString MicroSelectWidget::micro() const
{
	return m_pMicro->currentText();
}


void MicroSelectWidget::microFamilyChanged( const QString & family )
{
	QString oldID = m_pMicro->currentText();
	
	m_pMicro->clear();
	m_pMicro->insertStringList( MicroLibrary::self()->microIDs( AsmInfo::stringToSet(family), m_allowedGpsimSupport, m_allowedFlowCodeSupport, m_allowedMicrobeSupport ) );
	
	if ( m_pMicro->contains(oldID) )
		m_pMicro->setCurrentText(oldID);
}

#include "microselectwidget.moc"